1

How could you format a Solr facet query to include two page view ranges?

The following will only return the 200 TO 250 range and nothing from the 500 to 550 range.

<str name="fq">pageviews:[200 TO 250] OR [500 TO 550]</str>

I'm keen to get the number of records matching people with pages views between 200 and 250 and between 500 and 550.

Mark L
  • 12,405
  • 4
  • 28
  • 41

3 Answers3

4

You can also use it as shown below.

fq=pageviews:([200 TO 250] OR [500 TO 550])
Parvin Gasimzade
  • 25,180
  • 8
  • 56
  • 83
4

I believe that the complete answer to this question should include a way to configure all the parameters of these "repeated" facets. This is how it would be done in Solr 4.4.0, using JSON.

"facet.range": [

    "{!key=twohundred " +
        "f.pageviews.facet.range.start=200 " +
        "f.pageviews.facet.range.end=250 " + 
        "f.pageviews.facet.range.gap=1 " +
    "}pageviews",

    "{!key=fivehundred " +
        "f.pageviews.facet.range.start=500 " +
        "f.pageviews.facet.range.end=550 " + 
        "f.pageviews.facet.range.gap=10 " +
    "}pageviews"

]

(Notice that each entry in the array is supposed to be a string without linebreaks, but are divided here for clarity.)

This way each facet can be individually labeled, modified (I changed the gap for 'fivehundred'), or any other parameters can be added (like 'facet.range.other').

Source: https://issues.apache.org/jira/browse/SOLR-1351

juan
  • 1,917
  • 2
  • 16
  • 14
  • This got me most of the way there, and with some minor tweaks I was able to obtain the results I was looking for. I didn't have luck when specifying `facet.range` params per-field within the local parameter, but this did work for me: `facet.range={!key=twohundred_to_twofifty facet.range.start=200 facet.range.end=250 facet.range.gap=1}pageviews&facet.range={!key=fivehundred_to_fivefifty facet.range.start=500 facet.range.end=550 facet.range.gap=10}pageviews` – geogeo Aug 18 '21 at 21:08
3

Turns out I need to mention the field each time:

pageviews:[200 TO 250] OR pageviews:[500 TO 550]
Mark L
  • 12,405
  • 4
  • 28
  • 41