Commit 353a62ac authored by Bas de Nooijer's avatar Bas de Nooijer

Merge pull request #272 from nubs/master

Add wildcard behavior for null endpoints in rangeQuery.
parents b6b78123 e7481912
......@@ -192,10 +192,14 @@ class Helper
* Render a range query
*
* From and to can be any type of data. For instance int, string or point.
* If they are null, then '*' will be used.
*
* Example: rangeQuery('store', '45,-94', '46,-93')
* Returns: store:[45,-94 TO 46,-93]
*
* Example: rangeQuery('store', '5', '*', false)
* Returns: store:{5 TO *}
*
* @param string $field
* @param string $from
* @param string $to
......@@ -204,6 +208,14 @@ class Helper
*/
public function rangeQuery($field, $from, $to, $inclusive = true)
{
if ($from === null) {
$from = '*';
}
if ($to === null) {
$to = '*';
}
if ($inclusive) {
return $field . ':[' . $from . ' TO ' . $to . ']';
} else {
......
......@@ -78,6 +78,32 @@ class HelperTest extends \PHPUnit_Framework_TestCase
);
}
public function testRangeQueryInclusiveNullValues()
{
$this->assertEquals(
'field:[1 TO *]',
$this->helper->rangeQuery('field', 1, null)
);
$this->assertEquals(
'store:[* TO 46,-93]',
$this->helper->rangeQuery('store', null, '46,-93')
);
}
public function testRangeQueryExclusiveNullValues()
{
$this->assertEquals(
'field:{1 TO *}',
$this->helper->rangeQuery('field', 1, null, false)
);
$this->assertEquals(
'store:{* TO 46,-93}',
$this->helper->rangeQuery('store', null, '46,-93', false)
);
}
public function testGeofilt()
{
$this->assertEquals(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment