Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Using Search Result Set to populate Smart Search Filter options View modes: 
User avatar
Member
Member
lancetek - 11/24/2011 6:20:05 AM
   
Using Search Result Set to populate Smart Search Filter options
How can I use the results of a Search to populate the Smart Search filter options?

eg: we have a filter 'Parent Nodes' - it lists all the parent nodes(and the document count) of all the 'page(menu items)' objects that have children in the search result.

the Smart Search has a Query field to populate that filter choices - how can I access the search result set to use it to populate the filter choices?

Lance

User avatar
Member
Member
kentico_michal - 11/29/2011 3:55:35 AM
   
RE:Using Search Result Set to populate Smart Search Filter options
Hello,

The search results are stored in the HttpContext.Current.Items collection. You should be able to get it as a hashtable using this code:

Hashtable resultRows = RequestStockHelper.GetItem(SearchHelper.RESULTS_KEY) as Hashtable;

However, it is not possible to query this collection using standard SQL query.

So, you could customize the SearchResults control (~\CMSModules\SmartSearch\Controls\SearchResults.ascx.cs). You can access the search results with the aforementioned code in the Search method after the SearchHelper.Search method is executed:

// Search
DataSet results = SearchHelper.Search(searchText, SearchHelper.GetSort(srt), path, DocumentTypes, culture, defaultCulture, CombineWithDefaultCulture, CheckPermissions, SearchInAttachments, Indexes, displayResults, startPosition, numberOfProceeded, (UserInfo)CMSContext.CurrentUser, out numberOfResults, AttachmentsWhere, AttachmentsOrderBy);

// Get search results
Hashtable resultRows = RequestStockHelper.GetItem(SearchHelper.RESULTS_KEY) as Hashtable;

Then, you can bind some custom filter (e.g. drop-down list control) as you need based on resultRows hashtable.

Best regards,
Michal Legen