November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
When you call GetContentResult(), you are actually loading the matching content from database (or cache, if cached). if you want specific field (not limited to your CategoryName), you would have to use GetResult() as a projection of the document
Thanks for the answer, Quan.
Hm when I call the GetResult for the ProductContent, I get the exception:
EPiServer.Core.EPiServerException: Please use GetContentResult extension method for getting results with content types
How can I get the product content with GetResult?
How does your code look like? Did you just change the last line to GetResult? you would also need to remove the Search<ProductContent>(). instead: Projections (optimizely.com)
it might not be trivial change
For now, the full search is as following:
var result = SearchClient.Instance
.Search<ProductContent>()
.Filter(x => x.CategoryRouteSegment().MatchCaseInsensitive(categoryRouteSegment.ToString()))
.FilterOnCurrentMarket()
.FilterOnLanguages(new[] { currentLanguageCode })
.FilterForVisitor()
.OrderBy(x => x.SortOrder())
.Skip(paging.Skip())
.Take(paging.PageSize)
.GetContentResult();
So, if I would remove Search<ProductContent>() then - should I match type property with Product Content manualy and have something like ForQuery("*")?
You need to be using something like this
var result = client.Search<BlogPost>() .Select(x => new SearchResult { Title = x.Title, Author = x.Author.Name }) .GetResult();
i.e. a Select query for projection. it might not provide all you need, so you might be forced to load the content yourself (tip: using GetItems is a good way to ensure performance)
Would that be possible for the Product content? Because I got the exception when using GetResult on that:
EPiServer.Core.EPiServerException: Please use GetContentResult extension method for getting results with content types
Yes it should. But the Select part is important because you are getting a projection. Your query should look like this (untested by me obviously)
var result = SearchClient.Instance
.Search<ProductContent>()
.Filter(x => x.CategoryRouteSegment().MatchCaseInsensitive(categoryRouteSegment.ToString()))
.FilterOnCurrentMarket()
.FilterOnLanguages(new[] { currentLanguageCode })
.FilterForVisitor()
.OrderBy(x => x.SortOrder())
.Skip(paging.Skip())
.Take(paging.PageSize)
.Select(x=> new SearchResult {Name = x.Name, ContentLink = x.ContentLink})
.GetResult();
I added extension method to include CategoryName and included that as a field in conventions.
The field is being indexed properly:
The filtering on that field works fine:
The above works correctly.
However, I'd like to access the CategoryName indexed property in each of result.Items object. Is there any way to do that?