Skip to content

Commit 025639f

Browse files
author
Markus Kalkbrenner
authored
fixes #666 (#667)
* fixes #666 * added integration test
1 parent 746e3df commit 025639f

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to the solarium library will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [5.0.0-beta.1]
8+
### Fixed
9+
- Helper::rangeQuery() must not escape point values. Added a new parameter to turn off escaping.
10+
11+
712
## [5.0.0-alpha.2]
813
### Added
914
- introduced FacetResultInterface

docs/queries/query-helper/query-helper.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Two special types of helper methods are
77
Helper methods for general use
88
------------------------------
99

10-
- rangeQuery($field, $from, $to, $inclusive = true)
10+
- rangeQuery($field, $from, $to, $inclusive = true, $escape = true)
1111
- qparser($name, $params = array())
1212
- functionCall($name, $params = array())
1313
- join($from, $to, $dereferenced = false)

src/Core/Query/Helper.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,33 @@ public function formatDate($input)
159159
* From and to can be any type of data. For instance int, string or point.
160160
* If they are null, then '*' will be used.
161161
*
162-
* Example: rangeQuery('store', '45,-94', '46,-93')
162+
* Example: rangeQuery('store', '45,-94', '46,-93', true, false)
163163
* Returns: store:[45,-94 TO 46,-93]
164164
*
165165
* Example: rangeQuery('store', '5', '*', false)
166-
* Returns: store:{5 TO *}
166+
* Returns: store:{"5" TO *}
167167
*
168168
* @param string $field
169169
* @param string|null $from
170170
* @param string|null $to
171-
* @param bool $inclusive
171+
* @param bool $inclusive TRUE if the the range should include the boundaries, FALSE otherwise
172+
* @param bool $escape Whether the values should be escaped as phrase or not. Default is TRUE because
173+
* escaping is correct for security reasons. But for location searches (point values),
174+
* escaping would break the functionality
172175
*
173176
* @return string
174177
*/
175-
public function rangeQuery(string $field, ?string $from, ?string $to, bool $inclusive = true): string
178+
public function rangeQuery(string $field, ?string $from, ?string $to, bool $inclusive = true, bool $escape = true): string
176179
{
177180
if (null === $from) {
178181
$from = '*';
179-
} else {
182+
} elseif ($escape) {
180183
$from = $this->escapePhrase($from);
181184
}
182185

183186
if (null === $to) {
184187
$to = '*';
185-
} else {
188+
} elseif ($escape) {
186189
$to = $this->escapePhrase($to);
187190
}
188191

tests/Core/Query/HelperTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function testRangeQueryInclusive()
3333
);
3434

3535
$this->assertSame(
36-
'store:["45,-94" TO "46,-93"]',
37-
$this->helper->rangeQuery('store', '45,-94', '46,-93')
36+
'store:[45,-94 TO 46,-93]',
37+
$this->helper->rangeQuery('store', '45,-94', '46,-93', true, false)
3838
);
3939
}
4040

@@ -46,8 +46,8 @@ public function testRangeQueryExclusive()
4646
);
4747

4848
$this->assertSame(
49-
'store:{"45,-94" TO "46,-93"}',
50-
$this->helper->rangeQuery('store', '45,-94', '46,-93', false)
49+
'store:{45,-94 TO 46,-93}',
50+
$this->helper->rangeQuery('store', '45,-94', '46,-93', false, false)
5151
);
5252
}
5353

@@ -59,8 +59,8 @@ public function testRangeQueryInclusiveNullValues()
5959
);
6060

6161
$this->assertSame(
62-
'store:[* TO "46,-93"]',
63-
$this->helper->rangeQuery('store', null, '46,-93')
62+
'store:[* TO 46,-93]',
63+
$this->helper->rangeQuery('store', null, '46,-93', true, false)
6464
);
6565
}
6666

@@ -72,8 +72,8 @@ public function testRangeQueryExclusiveNullValues()
7272
);
7373

7474
$this->assertSame(
75-
'store:{* TO "46,-93"}',
76-
$this->helper->rangeQuery('store', null, '46,-93', false)
75+
'store:{* TO 46,-93}',
76+
$this->helper->rangeQuery('store', null, '46,-93', false, false)
7777
);
7878
}
7979

tests/Integration/AbstractTechproductsTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ public function testRangeQueries()
8787
$result = $this->client->select($select);
8888
$this->assertSame(10, $result->getNumFound());
8989
$this->assertSame(10, $result->count());
90+
91+
$select->setQuery(
92+
$select->getHelper()->rangeQuery('store', '-90,-90', '90,90', true, false)
93+
);
94+
$result = $this->client->select($select);
95+
$this->assertSame(2, $result->getNumFound());
96+
$this->assertSame(2, $result->count());
97+
98+
$select->setQuery(
99+
$select->getHelper()->rangeQuery('store', '-90,-180', '90,180', true, false)
100+
);
101+
$result = $this->client->select($select);
102+
$this->assertSame(14, $result->getNumFound());
103+
$this->assertSame(10, $result->count());
90104
}
91105

92106
/**

0 commit comments

Comments
 (0)