MySQL 'BETWEEN' query analogue for Solr

86 views Asked by At

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!

2

There are 2 answers

1
alexf On

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]

0
user3656910 On

Right solution is:

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

Thanks ever