Try our conversational search powered by Generative AI!

UnifiedSearch from a specified contentreference (issue)



I'm trying to build a unifiedsearch that takes the structure in consideration. In other words I want the search to get pages _from or under_ the given contentreference.

I've tried to do this in several ways but for now I have a searchRoot parameter in my search method that in a search setups the following: 

                .AlwaysApplyFilter(ic => ic.BuildFilter()

But the search wont take the searchRoot in consideration. Worth noticing is when i neglect the match it shows nothing, so atleast it reads it.

Someone who can point me in the right direction to do this kind of filter?



Apr 18, 2016 13:16

To give some more information to work with I've also tried the marked answer in this thread but with the same results.

I'm getting results back from the search, so it works overall. It's just the "from specified page" part that don't work.

// Viktor

Apr 18, 2016 13:26

I may have misinterpreted this, but are you executing that code for every search? Because adding conventions should typically only be done once, when the site starts up for example (an initializable module).

Have you tried with a simple unified search query? Something like

                    .Filter(x => ((IContent)x).Ancestors().Match(currentPage.PageLink.ToString()))
Apr 18, 2016 14:22


Yeah I've been messing around a bit.

My search query looks like this (changed my pagedata to Icontent as you suggested)

searchResult = SearchClient.Instance.UnifiedSearchFor(query)
                    .Include(i => i.SearchTitle.AnyWordBeginsWith(query), 5) 
                    .Filter(x => ((IContent)x).Ancestors().Match(searchRoot.ID.ToString()))
                    .Skip((page - 1) * hitsPerPage)

And my Initialization is:

                .AlwaysApplyFilter(ic => ic.BuildFilter<IContent>()

I'm still getting the same results on my 2 different searchpages tho (which are pointing at different roots)



Apr 18, 2016 14:36

I'm guessing this happens because you are using "Include", which will ignore the filters. Try using Filter instead of Include.

Apr 18, 2016 15:29

Thanks for quick answers Per!

Unfortunately this made no difference.

And just of curiosity, wouldn't the filter be applied after the inclusion anyway?

I'm trying to comment out as much as I can now to pinpoint.



Apr 18, 2016 15:43

"Include" is designed to not use any other filters in the query, in case you need to match something specific which may not be part of the filters.

So in this case, every document that contained your query would be returned, regardless of which filters had been added.

Apr 18, 2016 15:49

Thanks for the explanation. I most certain missed that!

Apr 18, 2016 15:51

So, after some more debugging I (of course) found that there were code outside of the actual search who happend to cause the problems I were experiencing.

Above solution with removing .Include and Filtering by ancestor is working.

Thank you so much for your help Per!



Apr 21, 2016 8:49

I'm glad it worked out for you! 

Apr 21, 2016 8:57
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.