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));
You need to customize the code a some for your solution, but you get the point.
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! =)
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.
ShouldIndex is called right before indexing so I would just do:
var shouldIndex = x.HideFromSearch;
to remove the content.
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?
Got an issue with trying to disable pages from the Index.
In globla I'm setting up the following:
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?