Solr Facet Range with Integers
My index contains peoples information, name, age, phone email etc.
I am faceting on Age. I group ages kinda like Date Range functionality.
My ranges are:
0 to 10
11 to 20
21 to 30
31 to 40 etc etc
When I do a query:
?q=*:*&facet=true&fq=age:[21+TO+30]
It returns all the ages I want in the range 21 to 30, but it also returns the age 3.
?q=*:*&facet=true&fq=age:[11+TO+20]
this does the same thing, but it returns the age 2.
?q=*:*&facet=true&fq=age:[0+TO+10]
this doe开发者_如何学JAVAs the same thing, but it returns the age 1. Can anyone explain this to me - is it a in solr?
In your request, you don't have any facet queries. You are using filter queries. Which will narrow you're results set down.
Perhaps you could try adding some facet.query's to your request and copy the results from the facet.counts area, in to your question above. At the very least this will tell you how many results solr thinks are in the different age ranges:
&facet.query=age:[21+TO+30]&facet.query=age:[11+TO+20]&facet.query=age:[0+TO+10]&facet.query=age:[*+TO+2]&facet.query=age:[*+TO+3]
From trawling the web I found that Solr indexes all data as strings - even when you define it as an integer. Its still a string in Solr:
<field name="age" type="integer" indexed="true" stored="true"/>
So what I needed to do was:
<field name="age" type="sint" indexed="true" stored="true"/>
If you want to order your integers this is the way, I assume the "sint" type was designed specifically for this.
Cheers
I know nothing of solr but I would guess that it is treating your ranges as alphabetical rather than numeric.
You may want to look at this answer which has links to various documents discussing a very similar issue
精彩评论