London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Excluding pages from index

Vote:
 

Got an issue with trying to disable pages from the Index.

In globla I'm setting up the following:

ontentIndexer.Instance.Conventions.ForInstancesOf<BasePageData>().ShouldIndex(x => !x.HideFromSearch);

   

Setting the HideFromSearch property on a page and running the reindexing job works fine. I.e the page is excluded from the index. But if I go in and set the property and just publish the page it isn't removed from the index. Instead the "old" document of the page is still in the index. 

Is there a way to force Find to delete pages on the publish event?

#76834
Nov 04, 2013 13:59
Vote:
 

This is not exactly the answer to your question, but it will solve your problem:

You can make a filter instead like this:

public ITypeSearch<IBasePageData> HideFromSearchFilter(ITypeSearch<IBasePageData> searchQuery)
{
searchQuery = searchQuery.Filter(x => x.ExcludePageFromSearch.Match(false));
return searchQuery;
}

 

You need to customize the code a some for your solution, but you get the point.

#76877
Nov 05, 2013 13:58
Vote:
 

Thanks Andreas!

 

That would work but as we depend on the Index on more then one place it feels it could become cumbersum. So I would rather see it remove from the Index.

I have been talking to EPi some on the side and it seems what I need to do is to make my own hook on the change event and check if the page should be deleted.

But I might have been able to convince EPi that this should work out of the box so let's keep our fingers crossed! =)

#76879
Nov 05, 2013 14:20
Vote:
 

Hi,

At the moment @Petter Klang you need to do like you said and listen to the event and then check if that thing has changed and then do a delete of the item.

I have also put this on the backlog so that it will be implemented soon.

 

Thanks for pointing us in this direction.

#76880
Nov 05, 2013 14:31
Vote:
 

Hi,

ShouldIndex is called right before indexing so I would just do:

ContentIndexer.Instance.Conventions.ForInstancesOf<StandardpagePageType>().ShouldIndex(x =>
{
var shouldIndex = x.HideFromSearch;
if (!shouldIndex)
{
try
{
ContentIndexer.Instance.Delete(x);
}
catch
{
//ignore
}
}

return shouldIndex;
});

to remove the content.

/Henrik

#77404
Nov 18, 2013 16:21
Vote:
 

Thanks Henrik Lindström, this was exactly what I was after.
One question. Why do you ignore the catch, what can happen there that are of no importence?

#77475
Nov 20, 2013 9:07
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.