Search for one or more terms in the values of an app
Overview
Search for one or more terms in the values of an app by using the SearchAssociations method.
Examples
Example 1:
The first step of the example is to create a chart with one dimension City (set in qFieldDefs ) and one measure Count(Rainfall) (set in qDef).
1. Create the chart object BC01.
The client sends:
The engine returns:
The chart object is created and the handle is 2.
2. Search for the values associated to Oakmont in the app (qTerm is Oakmont).
All the values in the app are in optional state. The search context is LockedFieldsOnly (default value). Since there are no locked fields, the search is performed on all values.
The number of search results that contain search hits is limited to 4 (value of the parameter qCount ) and the number of matching values in each search result is limited to 2 (qMaxNbrFieldMatches).
The client sends:
The engine returns:
The list of search terms is returned. In this example, there is only one term that is searched (in qSearchTerms).
The list of fields containing some search hits (in qFieldNames) and the list of search results (in qSearchTermsMatched) are returned. For each search result, the matching values are returned.
qField in qFieldDictionaries returns the index of the field in the list of fields defined by qFieldNames. In this example, qField set to :
- 0 corresponds to the field GolfCourseKey
- 1 corresponds to the field Golf Course
- 2 corresponds to the field City
- 3 corresponds to the field Course Address1
- 4 corresponds to the field Description
qText in qFieldDictionaties returns the value of a search hit.
qCharPos sets to:
- 0 means that the search term is located at position 0 in the value of the search result
- 25 means that the search term is located at position 25 in the value of the search result
qCharCount sets to 7 means that the length of the search term is 7.
The number of values returned by qResult in qFieldDictionaries is limited by the value of the parameter qMaxNbrFieldMatches. In this example, the maximum number of values per field containing search results is 2.
The list of search results (qSearchTermsMatched) is returned . The number of search results per field is limited by the value of the parameter qCount. In this example, the maximum number of search results is 4.
The index of each search result is given in qId. For each search result is given:
- the position of the field in the list of fields containing the search hits
- the positions of the matching values in the search results. In this example since the number of values per field is limited to two, qValues can only be [0] or [0,1].
The number of search matches in a field (given in qNoOfMatches ) is returned. This value is not limited by the value of the parameter qMaxNbrFieldMatches.
See: SearchAssociations method.
The figure below shows the result of the global associative search in the Qlik Sense interface:
3. Select the values related to the search result with index 0 (qId is 0). This search result corresponds to the field in position 2 (qField is 2) which is City. The search string is Oakmont. There are no current selections.
In this example, qMatchIx is 0 (equals to qId) and qTerms is [Oakmont].
The client sends:
The engine returns:
The matching values in the field City are selected.
See: SelectAssociations method.
4. Get the layout of the chart object. The handle of the request is 2 because the handle of the chart is 2.
The client sends:
The engine returns:
The city Oakmont is selected.
Example 2:
The first step in this example is to create a list object with one dimension City (set in qFieldDefs ).
1. Create the list object LB01. The dimension is City.
The client sends:
The engine returns:
The list object is created and the handle is 2.
2. Search for the values containing Aachen in the field City.
The client sends:
The engine returns:
There is one matching value: the city Aachen. The identifier linked to the field City is 0 (in result/qResults/qSearchTermsMatched/0/0/qId).
See: SearchAssociations method.
3. Select the value associated to Aachen in the field City (qMatchIx is 0).
There are no current selections in the app and the search context is LockedFieldsOnly (default value). Therefore there is only one value to be selected: the city Aachen (as returned by the SearchAssociations method in the previous step).
The client sends:
The engine returns:
The value Aachen in the field City is selected.
See: SelectAssociations method.
4. Get the layout of the list object. The handle of the request is 2 because the handle of the list object is 2.
The client sends:
The engine returns:
The city Aachen is selected.
5. Search for the values associated to Aalborg in the field City. The search context is LockedFieldsOnly (default value). Since there are no locked fields, the search is performed on all values of the field City.
The client sends:
The engine returns:
There is one matching value: the city Aalborg. The identifier linked to the field City is 0 (in result/qResults/qSearchTermsMatched/0/0/qId).
See: SearchAssociations method.
6. Select the value associated to Aalborg in the field City (qMatchIx is 0).
There are some current selections in the app and the search context is LockedFieldsOnly (default value). Therefore the new selection (the city Aalborg) will replace the current selection.
The client sends:
The engine returns:
The value Aalborg in the field City is selected.
See: SelectAssociations method.
7. Get the layout of the list object. The handle of the request is 2 because the handle of the list object is 2.
The client sends:
The engine returns:
The city Aalborg is selected and the city Aachen is no longer selected.
8. Select the value associated to Aachen in the field City (qMatchIx is 0).
There are some current selections in the app and the search context is CurrentSelection. Therefore the new selection is added to the current selection.
The client sends:
The engine returns:
The value Aachen is selected.
9. Get the layout of the list object. The handle of the request is 2 because the handle of the list object is 2.
The client sends:
The engine returns:
The cities Aalborg and Aachen are selected.
Example 3:
The first step in this example is to create a list object with one dimension City (set in qFieldDefs ).
1. Create the list object LB01. The dimension is City.
The client sends:
The engine returns:
The list object is created and the handle is 2.
2. Create the list object LB02. The dimension is Country.
The client sends:
The engine returns:
The list object is created and the handle is 3.
3. Select the values associated to Aachen and Aalborg in the field City.
The client sends:
The engine returns:
The cities Aachen and Aalborg are selected.
See: SelectAssociations method.
4. Get the layout of the list object LB01. The handle of the request is 2 because the handle of the list object is 2.
The client sends:
The engine returns:
The cities Aachen and Aalborg are selected.
5. Get the handle of the field City.
The client sends:
The engine returns:
The handle of the field City is 4.
6. Lock the field City. The handle of the request is 4 because the handle of the field City is 4.
The client sends:
The engine returns:
The selected values are locked.
7. Get the layout of the list object LB01. The handle of the request is 2 because the handle of the list object is 2.
The client sends:
The engine returns:
The cities Aachen and Aalborg in the field City are locked.
8. Search for the values associated to Canada in the field Country. The search context is LockedFieldsOnly (default value). Since the field City is locked, the search is performed on all locked values of the field City.
The city Aachen is associated to the country Germany and the city Aalborg is associated to the country Denmark.
The client sends:
The engine returns:
There is no matching value: the country Canada is not associated to any of the locked values (i.e. the cities Aachen and Aalborg).
See: SearchAssociations method.
9. Search for the values associated to Denmark in the field Country. The search context is LockedFieldsOnly (default value). Since the field City is locked, the search is performed on all locked values of the field City.
The city Aachen is associated to the country Germany and the city Aalborg is associated to the country Denmark.
The client sends:
The engine returns:
There is one matching value: the country Denmark.
See: SearchAssociations method.
10. Unlock the field City. The handle of the request is 4 because the handle of the field City is 4.
The client sends:
The engine returns:
The field City is no longer locked.
11. Search for the values associated to Canada in the field Country. The search context is LockedFieldsOnly (default value). Since the field City is no longer locked, the search is performed on all values.
The client sends:
The engine returns:
There is one matching value: the country Canada.
Did this page help you?
If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!