Try our conversational search powered by Generative AI!

Get UnifiedSearchHit descendants of PageID

Vote:
 

I know its possible to filter searchresults using siteID in an enterprise solution, but is it possible to filter for descendants of a pageID?

As of now I'm running a method on the resultset, filtering out those PageData objects which are not a descendant of a given pageID.

#69697
Apr 03, 2013 9:28
Vote:
 

Given that you are using EPiServer 7 it is. For EPiServer 6 I don't think it is out of the box although it's quite easy to fix (the Ancestors method used below will need to be added).

Anyway, given EPiServer 7 and using Unified Search (the syntax would be prettier when using "regular" search):

SearchClient.Instance.UnifiedSearchFor("Banana")
    .Filter(x => 
        !x.MatchTypeHierarchy(typeof(PageData)) 
        | ((PageData)x).Ancestors().Match(ContentReference.StartPage.ToString()))
    .GetResult();

    

#69698
Edited, Apr 03, 2013 9:50
Vote:
 

I am trying to achieve this on an Epi 6 R2 site. How would the Ancestors method look like? I can't get it working with it returning a List<string> containing PageReferences (id's) that are made to strings. I'm also having a breakpoint in the extension method but it never hits, so can't figure out if it's even ran. 

#121066
Apr 30, 2015 13:42
Vote:
 

"Ancestors" would need to be a JSON property if you browse your Index in the Find plugin views. Are you seeing it?

#122558
Jun 05, 2015 9:06
Vote:
 

Is this currently the way get matches below a certain page? Seems to work, but I had to change:

ContentReference.StartPage.ToString()

To

ContentReference.StartPage.ID.ToString()

Becase I guess it is the page id we want there, and sometimes it's prefixed by and underscore and workpageid(?)

#139327
Sep 30, 2015 10:15
* 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.