Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Using projections on Unified Search does not work


I am playing around with Projections and it works great until I try it on Unified Search.

Can anyone tell me why (on a Alloy site) get zero matches for the query with an anonymos projection and a whole lot of matches for the one that does not use projections

             var withProjection = _client.UnifiedSearchFor("Alloy")
                    c =>
                            Title = c.SearchTitle

            var witouthProjections = _client.UnifiedSearchFor("Alloy")
May 24, 2015 21:21

UnifiedSearch uses it's own projection rules (defined and modified in the UnifiedSearchRegistry) and relies on the fact that you are querying for the 'magic' ISearchContent (basically you can say that client.UnifiedSearch() == client.Search<ISearchContent>()). Whenever the API see a query for ISearchConent it will interpret it as a UnifiedSearch request and follow all the rules setup in the UnifiedSearchRegistry (what types to query, what projections to use, what filters to add...). However when you modify the procection using .Select() you will transform the query into a query for a new return type (in this case an anonymous class) and your query will no longer be treated as a UnifiedSearch. You can see this by noting that the GetResult() extensions in your example query are different. The one where you have made a custom projection it will fallback to a 'generic' 'GetResult':

public static SearchResults<TResult> GetResult<TResult>(this ISearch<TResult> search)

where the second query will use the UnifiedSearch 'GetResult':

public static UnifiedSearchResults GetResult(this ITypeSearch<ISearchContent> search, HitSpecification hitSpecification = null, bool filterForPublicSearch = true)

So what happens here is simply that your first query will be 'downgraded' into a basic query for all objects in the index directly implementing ISearchContent. Since you probably don't have any objects implementing it directly the result set will be empty.

To clarify this further what happens in the UnifiedSearch case when calling 'GetResult()' it will interpret the query as a UnifiedSearch and instead of querying for ISearchContent it will lookup all object types in the UnifiedSearchRegistry that are registered for UnifiedSearch and query for them (By default all PageData objects and MediaData).

To maybe simplify (or confuse) you can think of UnifiedSearch as advanced projections (it maps you data (pages, media, custom) when indexing into ISearchContent and when querying into UnifedSearchHit) ) and that any custom Select will override this andl downgrade your query into a generic search.

May 25, 2015 14:32
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.