Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Apply A filter on every search request

Vote:
 

I apologize if this has been answered already but i can't seem to locate the answer.

I am looking for a way that on every time we do a search, we apply a filter on every request.  So by example,  i want to filter results based on Site.  Is there a way that instead of using .FilterOnCurrentSite() on every single query we have, is there a way to do this automatically on every query?

Thanks in advance.

#189390
Mar 16, 2018 22:11
Vote:
 

Josh,

There's no built in way to do this AFAIK, but I'd recommend just creating a service class or extension method to access SearchClient.Instance.Search<T> with the FilterOnCurrentSite() extension already added. Then, you can re-use that code anywhere you need to make a search with IClient. Sometimes we'll place all our queries into a SearchManager class and then have a single private generic method in there where we set some base filters, and then each method might add additional filters for what it needs.

Personally, I'm a fan of having things like this be easily visible in the code since that's less "magic", but there's probably also a way to use StructureMap / DI to make this happen globally if you really wanted.

Hope this helps,

/Matt

#189408
Mar 19, 2018 4:25
* 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.