问题
I am trying implement an alphabetical range to perform a query in Solr 3.3. The user wants to fetch a list of restaurants which names start with (for example) A to G. Tried with "frange" function but it includes every field that has the letter. I want to get the restaurants wich names START with a specific letter.
Something like: "Get all restaurants from A to G": (A* and G*) but not (a and g).
Thank you
回答1:
Use name:[a TO h]
where name
field is not tokenized. If required, create a separate copy of the field for this.
If you try this on a tokenized field, then it will match all names which contain a word which starts with one of these letters. Also, you need to 'increment' the last letter of the range. If it is z
, then replace it with *
. For example, if the user is looking for w
to z
then the query should be name:[w TO *]
.
回答2:
Have you tried name:[a TO g]
?
来源:https://stackoverflow.com/questions/8883419/solr-alphabetical-range-query