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
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
SearchClient.Instance.UnifiedSearchFor(q) .Filter(x => ((IContent)x).Ancestors().Match(currentPage.PageLink.ToString())) .GetResult()
Hi,
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) .UsingSynonyms() .WithAndAsDefaultOperator() .ApplyBestBets() .Include(i => i.SearchTitle.AnyWordBeginsWith(query), 5) .Filter(x => ((IContent)x).Ancestors().Match(searchRoot.ID.ToString())) .Skip((page - 1) * hitsPerPage) .Take(hitsPerPage) .StaticallyCacheFor(TimeSpan.FromMinutes(5)) .Track() .GetResult(hitSpecification);
And my Initialization is:
SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<IContent>() .AlwaysApplyFilter(ic => ic.BuildFilter<IContent>() .ExcludeDeleted() .CurrentlyPublished() .ExcludeContentFolders());
I'm still getting the same results on my 2 different searchpages tho (which are pointing at different roots)
Br,
Viktor
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.
Br,
Viktor
"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.
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!
Br,
Viktor
Hi,
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:
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?
Thanks,
Viktor