QtLocation.PlaceSearchModel

Provides access to place search results. More...

Import Statement: import QtLocation 5.3
Since: Qt Location 5.0

Properties

Methods

Detailed Description

searchTerm and categories properties can be set to restrict the search results to places matching those criteria.

The PlaceSearchModel returns both sponsored and href="http://en.wikipedia.org/wiki/Organic_search">organic search results. Sponsored search results will have the sponsored role set to true.

The model returns data for the following roles:

RoleTypeDescription
typeenumThe type of search result.
titlestringA string describing the search result.
iconPlaceIconIcon representing the search result.
distancerealValid only when the type role is PlaceResult, the distance to the place from the center of the searchArea has been specified, the distance is NaN.
placePlaceValid only when the type role is PlaceResult, an object representing the place.
sponsoredboolValid only when the type role is PlaceResult, true if the search result is a sponsored result.

Search Result Types

The type role can take on the following values:

PlaceSearchModel.UnknownSearchResultThe contents of the search result are unknown.
PlaceSearchModel.PlaceResultThe search result contains a place.
PlaceSearchModel.ProposedSearchResultThe search result contains a proposed search which may be relevant.

It can often be helpful to use a Loader to create a delegate that will choose different Components based on the search result type.

Component {
id: resultDelegate
Loader {
Component {
id: placeResult
Column {
Text { text: title }
Text { text: place.location.address.text }
}
}
Component {
id: otherResult
Text { text: title }
}
sourceComponent: type == PlaceSearchModel.PlaceResult ? placeResult :
otherResult
}
}

Detection of Updated and Removed Places

The PlaceSearchModel listens for places that have been updated or removed from its plugin's backend. If it detects that a place has been updated and that place is currently present in the model, then it will call Place::getDetails to refresh the details. If it detects that a place has been removed, then correspondingly the place will be removed from the model if it is currently present.

Example

The following example shows how to use the count is set to the number of search results returned during the fetch.

import QtQuick 2.0
import QtPositioning 5.2
import QtLocation 5.3
PlaceSearchModel {
id: searchModel
plugin: myPlugin
searchTerm: "pizza"
searchArea: QtPositioning.circle(startCoordinate);
Component.onCompleted: update()
}

Paging

The limit can vary according to the plugin.

See also CategoryModel and QPlaceManager.

Property Documentation

categories : list<Category>

This property holds a list of categories to be used when searching. Returned search results will be for places that match at least one of the categories.


count : int

This property holds the number of results the model has.

Note that it does not refer to the total number of search results available in the backend. The total number of search results is not currently supported by the API.


favoritesMatchParameters : VariantMap

This property holds a set of parameters used to specify how search result places are matched to favorites in the favoritesPlugin.

By default the parameter map is empty and implies that the favorites plugin matches by alternative identifiers. Generally, an application developer will not need to set this property.

In cases where the favorites plugin does not support matching by alternative identifiers, then the plugin documentation should be consulted to see precisely what key-value parameters to set.


favoritesPlugin : Plugin

This property holds the Plugin which will be used to search for favorites. Any places from the search which can be cross-referenced or matched in the favoritesPlugin will have their favorite property set to the corresponding Place from the favoritesPlugin.

If the favoritesPlugin is not set, the favorite property of the places in the results will always be null.

See also Favorites.


limit : int

This property holds the limit of the number of items that will be returned.


nextPagesAvailable : bool

This property holds whether there is one or more additional pages of search results available.

See also nextPage().


plugin : Plugin

This property holds the Plugin which will be used to perform the search.


previousPagesAvailable : bool

This property holds whether there is one or more previous pages of search results available.

See also previousPage().


recommendationId : string

This property holds the placeId to be used in order to find recommendations for similar places.


relevanceHint : enumeration

This property holds a relevance hint used in the search query. The hint is given to the provider to help but not dictate the ranking of results. For example, the distance hint may give closer places a higher ranking but it does not necessarily mean the results will be strictly ordered according to distance. A provider may ignore the hint altogether.

SearchResultModel.UnspecifiedHintNo relevance hint is given to the provider.
SearchResultModel.DistanceHintThe distance of the place from the user's current location is important to the user. This hint is only meaningful when a circular search area is used.
SearchResultModel.LexicalPlaceNameHintThe lexical ordering of place names (in ascending alphabetical order) is relevant to the user. This hint is useful for providers based on a local data store.

searchArea : variant

This property holds the search area. The search result returned by the model will be within the search area.

If this property is set to a geocircle its radius property may be left unset, in which case the Plugin will choose an appropriate radius for the search.

Support for specifying a search area can vary according to the plugin backend implementation. For example, some may support a search center only while others may only support geo rectangles.


searchTerm : string

This property holds search term used in query. The search term is a free-form text string.


status : enum

This property holds the status of the model. It can be one of:

PlaceSearchModel.NullNo search query has been executed. The model is empty.
PlaceSearchModel.ReadyThe search query has completed, and the results are available.
PlaceSearchModel.LoadingA search query is currently being executed.
PlaceSearchModel.ErrorAn error occurred when executing the previous search query.

visibilityScope : enum

This property holds the visibility scope of the places to search. Only places with the specified visibility will be returned in the search results.

The visibility scope can be one of:

Place.UnspecifiedVisibilityNo explicit visibility scope specified, places with any visibility may be part of search results.
Place.DeviceVisibilityOnly places stored on the local device will be part of the search results.
Place.PrivateVisibilityOnly places that are private to the current user will be part of the search results.
Place.PublicVisibilityOnly places that are public will be part of the search results.

Method Documentation

cancel()

Cancels an ongoing search operation immediately and sets the model status to PlaceSearchModel.Ready. The model retains any search results it had before the operation was started.

If an operation is not ongoing, invoking cancel() has no effect.

See also status.


data(int index, string role)

Returns the data for a given role at the specified row index.


string errorString() const

This read-only property holds the textual presentation of latest place search model error. If no error has occurred or if the model was cleared an empty string is returned.

An empty string may also be returned if an error occurred which has no associated textual representation.


nextPage()

Updates the model to display the next page of search results. If there is no next page then this method does nothing.


previousPage()

Updates the model to display the previous page of search results. If there is no previous page then this method does nothing.


reset()

Resets the model. All search results are cleared, any outstanding requests are aborted and possible errors are cleared. Model status will be set to PlaceSearchModel.Null.


update()

Updates the model based on the provided query parameters. The model will be populated with a list of places matching the search parameters specified by the type's properties. Search criteria is specified by setting properties such as the limit. Support for these properties may vary according to plugin. update() then submits the set of criteria to the plugin to process.

While the model is updating the status is set to PlaceSearchModel.Error and the model cleared.

PlaceSearchModel {
id: model
plugin: backendPlugin
searchArea: QtPositioning.circle(QtPositioning.coordinate(10, 10))
...
}
MouseArea {
...
onClicked: {
model.searchTerm = "pizza";
model.categories = null;  //not searching by any category
model.searchArea.center.latitude = -27.5;
model.searchArea.center.longitude = 153;
model.update();
}
}

See also status.


updateWith(int proposedSearchIndex)

Updates the model based on the ProposedSearchResult at index proposedSearchIndex. The model will be populated with a list of places matching the proposed search. Model status will be set to PlaceSearchModel.Error and the model cleared.

If proposedSearchIndex does not reference a ProposedSearchResult this method does nothing.