var strQuery = client_education.query().q(
'all_type:current_affairs AND active:1 AND ca_id:123)
var next = client_education.query().q(
'all_type:current_affairs AND active:1 AND ca_id>123)
// should return the greater than 123 ca_id from database
// var previous = client_education.query().q(
'all_type:current_affairs AND active:1 AND ca_id<123)
// should return the less than 123 ca_id from database
How can I retrieve values greater than and less than the given id (123) in solr?
Range searches can be done using [start TO end]
, where []
is used to mean including, while {}
is used to mean excluding the start/end.
For any value larger than 123
:
ca_id:{123 TO *]
For any value smaller than 123
(not including):
ca_id:[* TO 123}
This assume that your fields are configured as proper integer fields. If you have configured them a text or string fields, this won't work (and you need to reconfigure them), since 111111
sorts before 123
and thus is considered less than 123
.
But as long as you've configured your fields as numeric / integer fields, the range syntax works as expected.