SOLR faceted-search to return faces, just like the OR operator

First I’ll try to explain what I would like to achieve using facet search in SOLR before asking a question. Imagine that I have a parameter for a dog that describes what the dog is suitable for, and one dog may have several options. Let me call it "housing." Therefore, the dog is suitable for:

  • in room
  • on open air
  • Children
  • old people
  • security.

So, basically, when I use facet search on this parameter, I get results with the current current database (url query facet=true&facet.field=housing ):

indoors (74), in the open air (63), children (71), old people (65), security (31).

Now, when I check the indoors parameter (url query fq=housing:1&facet=true&facet.field=housing ), I get the following results:

indoors (74), outdoors (53), children (60), old people (53), security (15).

He shows me that if, when checking the next parameter "outdoors", there are 53 dogs that are inside and out. I would like to get a result that would say: "How many dogs will be added to the result if I check the next option." Because there may be dogs that are suitable only outdoors. I would like to get results like this after checking the first parameter β€œindoors”:
indoors (74), outdoors (83), children (78), old people (79), security (75)
OR other way
(+0), on the street (+9), children (+4), people (+5), security (+1)

Is this possible in SOLR faceted-search? Or I use the wrong tool to achieve this. Because basically, when I check "indoors" and "on the street", I get the correct result from the query (url request fq=housing:(1 OR 2)&facet=true&facet.field=housing ). Just the number of faces is not what I expected.

+4
source share
3 answers

I think you will need to use the facet.query parameter, which will allow you to specify a query that will apply only to the cut results, and not to the main query.

This option allows you to specify an arbitrary query in Lucene's default syntax to generate a facet counter. By default, the facet returns the number of unique terms for the "field", while facet.query allows you to determine the number of samples for arbitrary terms or expressions.

In your case, I suppose you will still return the number of faces for unique terms for the "field", but with some additional filters applied.

+6
source

I think the following way should work:

 fq={!tag=housing}housing:1&facet.field={!key=housing}housing&facet.field={!key=housing_ex ex=housing}housing 

And you should get something like:

 "facet_counts": { "facet_queries": {}, "facet_fields": { "housing": [ "1", 74, "2", 53, "3", 60, "4", 53, "5", 15 ], "housing_ex": [ "1", 74, "2", 63, "3", 71, "4", 65, "5", 31 ] } } 

Then you have to do: housing_ex - housing . And the result:

 1: +0 2: +10 3: +11 4: +12 5: +16 

numFound + housing_ex - housing :

 1: 74 2: 84 3: 85 4: 86 5: 90 

facet.query not suitable for many facet values.

+1
source

add parameter & rows = 0

+1
source

Source: https://habr.com/ru/post/1481337/


All Articles