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?
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.
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()))
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)
I'm guessing this happens because you are using "Include", which will ignore the filters. Try using Filter instead of Include.
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.
"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.
Thanks for the explanation. I most certain missed that!
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!
I'm glad it worked out for you!