Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
I also needed category in my search results and this is how i did it.
var searchServiceResults = _searchService.Search(new SearchRequest {Query = query, LanguageId = lang, SortBy = SortOrder.Relevance},false); var model = new List<AutocompleteViewModel>(); foreach (var hit in searchServiceResults.Hits) { var doc = hit.Document as StandardSearchHit; if (doc == null) continue; if (model.Where(x => x.Category == doc.CategoryBreadcrum).ToList().Count >= 3) continue; if(doc.CategoryId != 0) HitWithCategory(query, searchServiceResults, doc, model, hit); } return model;
Hi, is there a way to be able to get the categories in SearchCategories?
When I execute the GetResult() I get an UnifiedSearchHit object that dosent contain the Categories.
Check the x.C where i want to project Categories.
public static IEnumerable Search(string query)
{
var highLight = new HitSpecification
{
HighlightExcerpt = true,
HighlightTitle = false,
PostTagForAllHighlights = "",
PreTagForAllHighlights = "",
ExcerptLength = 150,
ExcerptHighlightSpecAction = spec => new HighlightSpec { FragmentSize = 300, NumberOfFragments = 1, }
};
var client = SearchClient.Instance;
UnifiedSearchResults result = client.UnifiedSearch()
.For(query)
.WildCardQuery(query, x => x.SearchTitle)
.ApplyBestBets()
.StaticallyCacheFor(CacheTime)
.GetResult(highLight);
return result.Select(x => new SearchResultModel
{
Title = x.Title,
Excerp = x.Excerpt,
Category = x.C,
Link = x.Url,
Description = x.Excerpt,
Changed = x.UpdateDate.Value
});
}
/D