0

I need to make a search request to Apache Solr similar to MySQL BETWEEN query.

In Solr document I have two fields: "postcode_from" and "postcode_to". This is a range of postal codes for some country region or city.

Only integer numbers!!!

I have a value (for example 1234) which is between "postcode_from" and "postcode_to" and I need to find all records which are pass this criteria.

In MySQL it is solving very easy:

SELECT * FROM `postal_location_network` WHERE 1234 BETWEEN `postcode_from` AND `postcode_to`;

How can I compose a proper query for Solr?

Thank you for help!

Abhijit Bashetti
  • 8,518
  • 7
  • 35
  • 47

2 Answers2

0

I'am not sure what you need but something like that is this what you are expected?

q = postcode_from:[yourValue TO *] AND postcode_to:[* TO yourValue]

alexf
  • 1,303
  • 9
  • 20
  • It's not correct. For example: if `yourValue = 5`, `postcode_from = 2` and `postcode_to = 10`... If you use MySQL between the condition returns `true`: `5 BETWEEN 2 AND 10`. But if you represents the same situation with the solution above it seams like this `postcode_from:[5 TO *] AND postcode_to:[* TO 5]`. It's not correct. – Bruno dos Santos Jun 12 '15 at 13:29
0

Right solution is:

q = postcode_from:[* TO yourValue] AND postcode_to:[yourValue TO *]

Thanks ever