Skip to main content

Design

The Design blog is all about product and Qlik solutions, such as scripting, data modeling, visual design, extensions, best practices, and more!

Francis_Kabinoff
Employee
Employee

There are 5 methods on the doc class to help you search in various ways. They are the SearchAssociations, SearchObjects, SearchResults, SearchSuggest, and SelectAssociations methods. I’ll touch on all of them in more detail except the SearchObjects method, which is a bit out of scope for this post. Just know that you can search through the objects in a Qlik Sense app with this method.

 

Each of the rest of the methods all take a qOptions parameter, which is a SearchCombinationOptions object. This object has a qSearchFields property which is an array of fields to search. It defaults to all fields. This object also has a qContext property, which takes one of three possible values including “Cleared”, “LockedFieldsOnly”, and “CurrentSelections”. “Cleared” clears all selections in the app before searching, “LockedFieldsOnly” respects selections in locked fields, and “CurrentSelections” respects all selections. One other property worth mentioning on the SearchCombinationOptions object is the qAttributes property. This can be used with the SearchResults method to request more details about the results. Check out the documentation for further details.

 

SearchAssociations

https://help.qlik.com/en-US/sense-developer/June2018/apis/EngineAPI/services-Doc-SearchAssociations....

This method is deprecated, use SearchResults instead.

 

SearchResults

https://help.qlik.com/en-US/sense-developer/June2018/apis/EngineAPI/services-Doc-SearchResults.html

The SearchResults method is useful for display search results similar to how they are displayed in the Qlik Sense client. It takes 3 parameters, an options object, an array of search terms, and the page of results you want to retrieve. The results are returned as an array of objects with information on the search term matched, the field name, the items in the field that were matched, and the ranges in the items of the match. All of this information is useful when displaying search results to the user. If you want to allow the user to select results, you can request the results to contain qElemNumbers by correctly setting the qAttributes property of the qOptions object, but the easiest thing to do is to use the SelectAssociations method.

 

SearchSuggest

https://help.qlik.com/en-US/sense-developer/June2018/apis/EngineAPI/services-Doc-SearchSuggest.html

The SearchSugest method is useful for displaying search suggestions to the user as they search. You can see this kind of functionality in action in the Qlik Sense client or on the Qlik Sense Branch site when you use the search feature and see suggestions pop up as grayed text in the search bar, as well as below the search bar in the dark colored suggestion bar. This method takes 2 parameters, an options object, and an array of search terms. It’s common to use this in conjunction with SearchResults and SelectAssociations to display suggestions.

 

SelectAssociations

https://help.qlik.com/en-US/sense-developer/June2018/apis/EngineAPI/services-Doc-SelectAssociations....

The SelectAssociations method is used for selecting search results. It takes 3 parameters, an options object, an array of search terms, and the index of the search result to select. The most obvious use case for this method is to use it to select results from the SearchResults method. You can display the results of the SearchResults method, and then allow the user to select a result, and call the SelectAssociations method with the same options object and array of search terms as the original SearchResults method call, passing the index of the search result the user clicked. This will select all values in that field that match the search.

Another less obvious use of SelectAssociations is to use it as a “live search,” making selections as the user searches, like the Qlik Sense Branch page. The trick is, you only want to have to search and select in one field, otherwise you would have to loop through results and make selections that could potentially exclude each other. So first you’d have to create a field which contained the values of all the fields you wanted to include in the search, with a key to associate the rows of this field back to the rows of the originating fields. Then you could use the SelectAssociations to search just that field and select the first index of results as the user types in a search bar.

 

SearchListObjectFor

https://help.qlik.com/en-US/sense-developer/June2018/apis/EngineAPI/services-GenericObject-SearchLis...

Unlike the other methods I’ve discussed so far, the SearchListObjectFor method is a method on the GenericObject class, and applies to list objects only. This method takes 2 parameters, a qPath parameter which is the path to the list object, and a qMatch parameter which is the search string. This method provides functionality similar to what you see in filter objects in the Qlik Sense client. The way it works is when you call the SearchListObjectFor method on a list object, it reduces the data in that list object, without affecting the rest of the app. If you want to accept the search and select the values in the list object, you use another function, the AcceptListObjectSearch method.

Using SearchListObjectFor on a list object as opposed to using the search methods on the doc class is useful for creating typeaheads, where all possible search results are displayed when the use clicks the search bar, and are reduced as the user searches, or in custom filter objects.

 

If you guys have any questions about these methods, or using search with Qlik Sense, let me know. Also, checkout this great library on Qlik Branch for searching. http://branch.qlik.com/#!/project/56af9cc5126a633074bea476