Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
353a62ac
Commit
353a62ac
authored
Sep 17, 2014
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #272 from nubs/master
Add wildcard behavior for null endpoints in rangeQuery.
parents
b6b78123
e7481912
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
library/Solarium/Core/Query/Helper.php
library/Solarium/Core/Query/Helper.php
+12
-0
tests/Solarium/Tests/Core/Query/HelperTest.php
tests/Solarium/Tests/Core/Query/HelperTest.php
+26
-0
No files found.
library/Solarium/Core/Query/Helper.php
View file @
353a62ac
...
@@ -192,10 +192,14 @@ class Helper
...
@@ -192,10 +192,14 @@ class Helper
* Render a range query
* Render a range query
*
*
* From and to can be any type of data. For instance int, string or point.
* 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')
* Example: rangeQuery('store', '45,-94', '46,-93')
* Returns: store:[45,-94 TO 46,-93]
* Returns: store:[45,-94 TO 46,-93]
*
*
* Example: rangeQuery('store', '5', '*', false)
* Returns: store:{5 TO *}
*
* @param string $field
* @param string $field
* @param string $from
* @param string $from
* @param string $to
* @param string $to
...
@@ -204,6 +208,14 @@ class Helper
...
@@ -204,6 +208,14 @@ class Helper
*/
*/
public
function
rangeQuery
(
$field
,
$from
,
$to
,
$inclusive
=
true
)
public
function
rangeQuery
(
$field
,
$from
,
$to
,
$inclusive
=
true
)
{
{
if
(
$from
===
null
)
{
$from
=
'*'
;
}
if
(
$to
===
null
)
{
$to
=
'*'
;
}
if
(
$inclusive
)
{
if
(
$inclusive
)
{
return
$field
.
':['
.
$from
.
' TO '
.
$to
.
']'
;
return
$field
.
':['
.
$from
.
' TO '
.
$to
.
']'
;
}
else
{
}
else
{
...
...
tests/Solarium/Tests/Core/Query/HelperTest.php
View file @
353a62ac
...
@@ -78,6 +78,32 @@ class HelperTest extends \PHPUnit_Framework_TestCase
...
@@ -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
()
public
function
testGeofilt
()
{
{
$this
->
assertEquals
(
$this
->
assertEquals
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment