Unified search and categories

Vote:
 

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

#113581
Nov 25, 2014 10:02
Vote:
 

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;



#114440
Dec 11, 2014 15:49
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.