Try our conversational search powered by Generative AI!

Exclude pages/nodes with EPiServer Search

Vote:
 

On my website I have multiple pages of type Search Result Page.

If the user searches on a search page which is not an ancestor to a MarketPage I wish to exclude pages which are children to pages of type MarketPage and the MarketPage itself.

Is this possible with EPiServer Search?

 

Startpage / Global site

- About
- Contact
- Search Result Page

- Great Britain Market
  -- Products
  -- Offer
  -- Solutions
  -- About 
  -- Contact
  -- Search result page

- Germany Market
  -- Products
  -- Offer
  -- Solutions
  -- About 
  -- Contact
  -- Search result page

- ...

#85770
May 05, 2014 13:46
Vote:
 

Haven't worked much with EPiServer Search so don't know if there is a "start searching from here property"

But  one way to do it could be to first get a referense to the market page. Could set a property on the searchpage or just get parrent if you know it will always be directly under the market or use the GetAncestors on the serach page and get the first page of the type MarketPage.

Ones we got that you should be able to filter out pages from the results that doesn't have the MarketPage in it's Ancestors.

#85771
May 05, 2014 14:13
Vote:
 

Hi Jonas,

There are two ways to solve this:

1. Filter items during search
2. Filter items during indexing

Option 1

- You search for term X
- EPiSerch returns 100 items
- You use Linq/foreach loop, iterate through every item in the result set and check if the item belongs to the Global site or specific Market group

Option 2

- You create a custom index field, e.g. 'MARKET'
- During indexing time, you fetch the market group your page belongs to (Britain, Germany, Global), and save this value in MARKET field
- You execute the search query: 'give me all items for term X where MARKET=your_current_group or MARKET=Global'

Option 1 is easier for implementation, but it has a few limitations:
1. It's very slow. If EPiSearch returns 100 items, you need to fetch ancestors 100 times (once for each item)
2. If EPiSearch returns first 100 items, and all of them are inside "wrong" Market group, you won't have anything to display to the end user

Option 2 is harder for implementation, but it's lightning fast because you don't have to deal with expensive database queries (fetching ancestors using EPiServer API), just with Lucene.net
Ted Nyberg wrote a great article about adding custom fields to EPiServer search index: http://tedgustaf.com/blog/2013/4/add-custom-fields-to-the-episerver-search-index-with-episerver-7/

#85790
May 05, 2014 21:04
Vote:
 

Hi

I have used the .Filter on the searchdatasource do exlude pages of a specific pagetype from the result. Something like this:

 

dsSearch.Filter += dsSearch_Filter;

    void dsSearch_Filter(object sender, FilterEventArgs e)
        {
            var pageTypeIds = new int[] { Locate.ContentTypeRepository().Load<RoomPageType>().ID };
            e.Pages.FilterByPageType(pageTypeIds);

        }


       public static void FilterByPageType(this PageDataCollection pages, int[] pageTypeId)
        {
            for (var i = pages.Count - 1; i >= 0; i--)
            {
                if (pageTypeId.Contains(pages[i].PageTypeID))
                {
                    pages.RemoveAt(i);
                }
            }
        }

    

 

Using Dejans idea might be much better though. It might also be an idea to set the pagelink property to the diffrent areas you would like to search within.

#85857
May 07, 2014 11:47
Vote:
 

I went for OPTION 1.

 

Thank you all

#85858
Edited, May 07, 2014 11:53
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.