Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE

searchResults method: retrieve string results based on search terms

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
Joseph_Musekura
Support
Support

searchResults method: retrieve string results based on search terms

Last Update:

May 10, 2022 1:43:00 PM

Updated By:

Jamie_Gregory

Created date:

Aug 17, 2021 8:37:09 AM

Attachments

You can build a search capability using methods like searchResults() and the selectAssociations(). The difference these methods is highlighted in  "search functionality with Qlik Sense Engine API " .

Below extract uses  searchResults() and the selectAssociations() methods

app.searchResults([$(this).val()], 
       {qOffset:0, qCount: 15},
        //limiting search to field Country
       {qSearchFields: ['Country'], qContext: 'CurrentSelections'}, 
	 //{qContext: 'CurrentSelections'}, 
	function(reply){
	   $(".qs-search-results").html("");
	   if (reply.qResult.qTotalNumberOfGroups === 0){
	       return;
	   };
	   $(".qs-search-results").append("<ul>");
	   var searchResults = reply.qResult.qSearchGroupArray; 
	   searchResults.forEach(function(result, i){
		result.qItems.forEach(function(item){
		  $(".qs-search-results ul").append("<li data-index='" + i + "'>");
		  $(".qs-search-results ul li:last-child").append("<div class='qs-search-item-identifier'>" + item.qIdentifier + "</div");
		  var matchString = "";
		 item.qItemMatches.forEach(function (match) {
		 	matchString += match.qText;
		 });
		 $(".qs-search-results ul li:last-child").append("<div class='qs-search-item-string'>" + matchString + "</div>");
	  });
	});
					
	$(".qs-search-results li").click(function() {
	   app.selectAssociations($(this).data("index"), [$(".qs-search").val()], {qContext: 'CurrentSelections'});
	   $(".qs-search").val("");
	   $(".qs-search-results").html("");
      });
});

 

A complete demo can be found in Custom Search Functionality in Capability APIs  or  attached & tested mashup sample "searchResultAPIEx".

From the attached mashup searchResultAPIEx, we noticed that, even if a field in source qvf is AUTO sorted or sorted alphabetically, the result of searchResults method is sorted by STATE.

search by country.png

 

Environments

  • Qlik Sense Enterprise for Windows
Version history
Last update:
‎2022-05-10 01:43 PM
Updated by: