Commit c01ef8a5 authored by Markus Kalkbrenner's avatar Markus Kalkbrenner Committed by GitHub

range query fix (#574)

* don't escape *

* added basic integration tests for range queries and spatial searches

* fixed coding style
parent 1d18512b
...@@ -174,14 +174,19 @@ class Helper ...@@ -174,14 +174,19 @@ class Helper
{ {
if (null === $from) { if (null === $from) {
$from = '*'; $from = '*';
} else {
$from = $this->escapePhrase($from);
} }
if (null === $to) { if (null === $to) {
$to = '*'; $to = '*';
} else {
$to = $this->escapePhrase($to);
} }
$from = $this->escapePhrase($from); if ($inclusive) {
$to = $this->escapePhrase($to); return $field.':['.$from.' TO '.$to.']';
}
if ($inclusive) { if ($inclusive) {
return $field.':['.$from.' TO '.$to.']'; return $field.':['.$from.' TO '.$to.']';
......
...@@ -54,12 +54,12 @@ class HelperTest extends TestCase ...@@ -54,12 +54,12 @@ class HelperTest extends TestCase
public function testRangeQueryInclusiveNullValues() public function testRangeQueryInclusiveNullValues()
{ {
$this->assertSame( $this->assertSame(
'field:["1" TO "*"]', 'field:["1" TO *]',
$this->helper->rangeQuery('field', 1, null) $this->helper->rangeQuery('field', 1, null)
); );
$this->assertSame( $this->assertSame(
'store:["*" TO "46,-93"]', 'store:[* TO "46,-93"]',
$this->helper->rangeQuery('store', null, '46,-93') $this->helper->rangeQuery('store', null, '46,-93')
); );
} }
...@@ -67,12 +67,12 @@ class HelperTest extends TestCase ...@@ -67,12 +67,12 @@ class HelperTest extends TestCase
public function testRangeQueryExclusiveNullValues() public function testRangeQueryExclusiveNullValues()
{ {
$this->assertSame( $this->assertSame(
'field:{"1" TO "*"}', 'field:{"1" TO *}',
$this->helper->rangeQuery('field', 1, null, false) $this->helper->rangeQuery('field', 1, null, false)
); );
$this->assertSame( $this->assertSame(
'store:{"*" TO "46,-93"}', 'store:{* TO "46,-93"}',
$this->helper->rangeQuery('store', null, '46,-93', false) $this->helper->rangeQuery('store', null, '46,-93', false)
); );
} }
......
...@@ -78,6 +78,59 @@ abstract class AbstractTechproductsTest extends TestCase ...@@ -78,6 +78,59 @@ abstract class AbstractTechproductsTest extends TestCase
], $ids); ], $ids);
} }
public function testRangeQueries()
{
$select = $this->client->createSelect();
$select->setQuery(
$select->getHelper()->rangeQuery('price', null, 80)
);
$result = $this->client->select($select);
$this->assertSame(6, $result->getNumFound());
$this->assertSame(6, $result->count());
// VS1GB400C3 costs 74.99 and is the only product in the range between 70.23 and 80.00.
$select->setQuery(
$select->getHelper()->rangeQuery('price', 70.23, 80)
);
$result = $this->client->select($select);
$this->assertSame(1, $result->getNumFound());
$this->assertSame(1, $result->count());
$select->setQuery(
$select->getHelper()->rangeQuery('price', 74.99, null)
);
$result = $this->client->select($select);
$this->assertSame(11, $result->getNumFound());
$this->assertSame(10, $result->count());
$select->setQuery(
$select->getHelper()->rangeQuery('price', 74.99, null, false)
);
$result = $this->client->select($select);
$this->assertSame(10, $result->getNumFound());
$this->assertSame(10, $result->count());
}
public function testSpatial()
{
$select = $this->client->createSelect();
$select->setQuery(
$select->getHelper()->geofilt('store', 40, -100, 100000)
);
$result = $this->client->select($select);
$this->assertSame(14, $result->getNumFound());
$this->assertSame(10, $result->count());
$select->setQuery(
$select->getHelper()->geofilt('store', 40, -100, 1000)
);
$result = $this->client->select($select);
$this->assertSame(10, $result->getNumFound());
$this->assertSame(10, $result->count());
}
public function testSpellcheck() public function testSpellcheck()
{ {
$spellcheck = $this->client->createSpellcheck(); $spellcheck = $this->client->createSpellcheck();
......
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