Stainedart
Stainedart

Reputation: 1969

Solr filter out facet results individually

I am working on filtering out facet returned by solr based on predefined list of criterias.

For example I am querying for documents that are of different types. The facet returned is as follows:

<lst name="facet_counts">
  <lst name="facet_queries"/>
  <lst name="facet_fields">
    <lst name="applicationName">
      <int name="microsoft">2304</int>
      <int name="word">2277</int>
      <int name="0">1550</int>
      <int name="office">598</int>
      <int name="8">471</int>
      <int name="9">446</int>
      <int name="90">445</int>
      <int name="10">435</int>
      <int name="100">426</int>
      <int name="9.0">418</int>
      <int name="10.0">411</int>
      <int name="8.0">375</int>
      <int name="80">375</int>
      <int name="2">328</int>
      <int name="5">308</int>
      <int name="acrobat">272</int>

Lets say I want not show microsoft as a result for this facet_field. The query currently looked like the following. I have give some try with Tag and exclusion filters but im out of luck...

q=*%3A*&wt=xml&indent=true&facet=true&facet.field=applicationName

EDIT My current solution was to add a custom search handler and perform the filtering post-query execution. I would like to have a solution through the query mechanism this way would involve less processing.

Upvotes: 3

Views: 2567

Answers (1)

Alexander Jardim
Alexander Jardim

Reputation: 2476

Have you ever tried the "facet.query" parameter? If I have understood your problem correctly, if you put a facet.query=-applicationName:microsoft on your request, Solr will do exactly what you want. So, it should be like:

q=%3A&facet=true&facet.field=applicationName&facet.query=-applicationName:microsoft


EDIT: The above hint is wrong. It will only return the number of documents that don't have "microsoft" on the field "applicationName".

You should put the same query on your "q" parameter. Just like that:

q=-applicationName:microsoft&facet=true&facet.field=applicationName

Upvotes: 2

Related Questions