UnifiedSearch from a specified contentreference (issue)

Vote:
 

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: 

SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf()
                .AlwaysApplyFilter(ic => ic.BuildFilter()
                    .ExcludeDeleted()
                    .CurrentlyPublished()
                    .ExcludeContentFolders()
              .And(x=>x.Ancestors().Match(searchRoot.ID.ToString())));

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

#147543
Apr 18, 2016 13:16
Vote:
 

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

#147546
Apr 18, 2016 13:26
Vote:
 

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()
#147550
Apr 18, 2016 14:22
Vote:
 

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

#147553
Apr 18, 2016 14:36
Vote:
 

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

#147556
Apr 18, 2016 15:29
Vote:
 

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

#147558
Apr 18, 2016 15:43
Vote:
 

"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.

#147559
Apr 18, 2016 15:49
Vote:
 

Thanks for the explanation. I most certain missed that!

#147560
Apr 18, 2016 15:51
Vote:
 

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

#147673
Apr 21, 2016 8:49
Vote:
 

I'm glad it worked out for you! 

#147675
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.