Showing the number of search result in new each facet

Reza Zareian Fard asked on October 20, 2014 02:34

I have faceted search and I want to show the number of result of the search term for each facet. For example if user search "Tax" I want to show how many items we do have in each category which contains this keyword. Would you please tell me how can I manage this requirement?

Recent Answers


Juraj Ondrus answered on December 6, 2014 10:09

Hi Reza,

You will need to use the API like the sample below, however the sample does not take the page permissions into account and maybe some other things. The snippet I found was the following:

private void LuceneSearch()
{
//Get the index searcher
SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("TLSD_Content");
var searcher = index.GetSearcher(true);

//Get the search results for searched text
string term = "TLS";
Lucene.Net.Search.Query searchQuery = MultiFieldQueryParser.Parse(term, new[] { SearchHelper.CONTENT_FIELD }, new[] { BooleanClause.Occur.SHOULD }, new StandardAnalyzer());
var searchQueryFilter = new QueryFilter(searchQuery);
BitArray searchBitArray = searchQueryFilter.Bits(searcher.GetIndexReader());

//Get the search results for filter item
string classname = "tls.nieuws";
var qry1 = new TermQuery(new Lucene.Net.Index.Term("classname", classname));
var qryFilter = new QueryFilter(qry1);
BitArray qry1BitArray = qryFilter.Bits(searcher.GetIndexReader());
int total = GetCardinality(qry1BitArray);

//Combine the resuls
BitArray combinedResults = searchBitArray.And(qry1BitArray);
int total2 = GetCardinality(combinedResults);
}

Best regards,

Juraj Ondrus

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.