SOLR: how to exclude fields globally?

686 views Asked by At

Im using apache Solr for my site search. and the website has large number of pages and each page has a field called 'searchEnabled'. This is a boolean field contains values true or false. I want to exclude the disabled pages from all the search results (The site has number of different searches) if the searchEnabled field is set to false.

I can use a filter query(fq) to exclude this field. But my site is using number of different searches with different queries. I do not want to add the filter query in all the search queries across the website. Is there any easy way to disable the indexes with field 'searchEnabled' set to false?

So that no any solr search will return the document/pages where the field value is set to false.

1

There are 1 answers

1
MatsLindh On BEST ANSWER

You can add a parameter that will always be present to solrconfig.xml for the request handler you're making your request against.

By using the name appends for your parameter list, the parameter will always be appended to the other given parameters.

<requestHandler name="/select" class="solr.SearchHandler">
  <lst name="appends">
    <str name="fq">searchEnabled:true</str>
  </lst>
</requestHandler>

This will always add a filter query to your requests behind the scenes that limit the result set to those documents that have searchEnabled set to true.