search based on Tree level or based on URL

Vote:
 

Hi, 

i have a site with pages like this structure.

a

b

  • c
  • d
  • e

f

  • g
  • h
  • i

suppose if am browsing c page and i click serch button, then i want to display serch results under b level tree.dont want to display f tree level results.

suppose if am browsing g page and i click serch button, then i want to display serch results under f level tree.dont want to display b tree level results.

or 

otehrwise is there any option to filter GetResult() after search hits.

#226646
Edited, Aug 17, 2020 10:48
Vote:
 

When performing the search, you just need to locate what part of the tree structure you are inside, and filter the Ancestors-list by that:

.Filter(x => x.Ancestors().Match(a-b-or-f-page.ContentLink.ToReferenceWithoutVersion().ToString())


If a, b and f are landing pages of the same page type, you could do simething like this:

public static T GetParentOfType<T>(this ContentReference contentReference) where T : PageData
{
	if (contentReference.IsNullOrEmpty())
		return null;

	while (contentReference != ContentReference.EmptyReference)
	{
		var content = contentReference.Get<PageData>();
		if (content is T)
			return content as T;

		if (contentReference.Equals(ContentReference.StartPage))
			return null;

		if (content == null)
			return null;

		contentReference = content.ParentLink;
	}

	return null;
}


And then:

.Filter(x => x.Ancestors().Match(currentPage.GetParentOfType<MyLandingPage>().ContentLink.ToReferenceWithoutVersion().ToString())
#226650
Edited, Aug 17, 2020 12:31
Vote:
 

Hi Tomas.

Thanks for your reply.

am getting below error.

the Ancestorsdoes not exist in the current context.

#226718
Aug 19, 2020 10:05
Tomas Hensrud Gulla - Aug 19, 2020 10:23
Could you post your complete query?
Vote:
 

Ancestors() is an extensions method defined in the namespace EPiServer.Find.Cms.ContentExtensions

What version of Find are you using?

#226741
Edited, Aug 19, 2020 19:04
* 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.