Created
June 3, 2020 18:07
-
-
Save mattbrailsford/73a0c30b73287d2b6166def056208bac to your computer and use it in GitHub Desktop.
Vendr Faceted Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Perform a faceted search based on product categories | |
var dir = new DirectoryInfo(((LuceneIndex)index).LuceneIndexFolder.FullName); | |
using (var searcher = new IndexSearcher(FSDirectory.Open(dir), false)) | |
using (var factedSearcher = new SimpleFacetedSearch(searcher.IndexReader, new string[] { "searchCategory" })) | |
{ | |
var queryParser = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()); | |
var query = queryParser.Parse(sb.ToString()); | |
var queryResults = factedSearcher.Search(query, ps * p); | |
var facetedResults = new Dictionary<string, PagedResult<IPublishedContent>>(); | |
foreach (SimpleFacetedSearch.HitsPerFacet hpg in queryResults.HitsPerFacet) | |
{ | |
facetedResults.Add(hpg.Name.ToString(), new PagedResult<IPublishedContent>(hpg.HitCount, p, ps) | |
{ | |
Items = hpg.Documents.Skip(ps * (p - 1)).Select(x => UmbracoContext.Content.GetById(int.Parse(x.Get("id")))).ToList() | |
}); | |
} | |
result.Facets = facetedResults; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment