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
9e3ae1fa
Commit
9e3ae1fa
authored
Sep 19, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated geospatial query helper functions to support dereferenced params, fixes issue #114
parent
b2612442
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
27 deletions
+87
-27
library/Solarium/Core/Query/Helper.php
library/Solarium/Core/Query/Helper.php
+42
-21
tests/Solarium/Tests/Core/Query/HelperTest.php
tests/Solarium/Tests/Core/Query/HelperTest.php
+45
-6
No files found.
library/Solarium/Core/Query/Helper.php
View file @
9e3ae1fa
...
@@ -216,13 +216,14 @@ class Helper
...
@@ -216,13 +216,14 @@ class Helper
*
*
* Find all entries within the distance of a certain point.
* Find all entries within the distance of a certain point.
*
*
* @param $field
* @param $pointX
* @param $pointX
* @param $pointY
* @param $pointY
* @param $field
* @param $distance
* @param $distance
* @param boolean $dereferenced
* @return string
* @return string
*/
*/
public
function
geofilt
(
$
pointX
,
$pointY
,
$field
,
$distanc
e
)
public
function
geofilt
(
$
field
,
$pointX
,
$pointY
,
$distance
,
$dereferenced
=
fals
e
)
{
{
return
$this
->
qparser
(
return
$this
->
qparser
(
'geofilt'
,
'geofilt'
,
...
@@ -230,7 +231,8 @@ class Helper
...
@@ -230,7 +231,8 @@ class Helper
'pt'
=>
$pointX
.
','
.
$pointY
,
'pt'
=>
$pointX
.
','
.
$pointY
,
'sfield'
=>
$field
,
'sfield'
=>
$field
,
'd'
=>
$distance
'd'
=>
$distance
)
),
$dereferenced
);
);
}
}
...
@@ -242,13 +244,14 @@ class Helper
...
@@ -242,13 +244,14 @@ class Helper
* guaranteed to encompass all of the points of interest, but it may also
* guaranteed to encompass all of the points of interest, but it may also
* include other points that are slightly outside of the required distance.
* include other points that are slightly outside of the required distance.
*
*
* @param string $pointX
* @param string $field
* @param string $pointY
* @param string $pointX
* @param string $field
* @param string $pointY
* @param string $distance
* @param string $distance
* @param boolean $dereferenced
* @return string
* @return string
*/
*/
public
function
bbox
(
$
pointX
,
$pointY
,
$field
,
$distanc
e
)
public
function
bbox
(
$
field
,
$pointX
,
$pointY
,
$distance
,
$dereferenced
=
fals
e
)
{
{
return
$this
->
qparser
(
return
$this
->
qparser
(
'bbox'
,
'bbox'
,
...
@@ -256,7 +259,8 @@ class Helper
...
@@ -256,7 +259,8 @@ class Helper
'pt'
=>
$pointX
.
','
.
$pointY
,
'pt'
=>
$pointX
.
','
.
$pointY
,
'sfield'
=>
$field
,
'sfield'
=>
$field
,
'd'
=>
$distance
'd'
=>
$distance
)
),
$dereferenced
);
);
}
}
...
@@ -269,16 +273,18 @@ class Helper
...
@@ -269,16 +273,18 @@ class Helper
* or combining the distance with the relevancy score,
* or combining the distance with the relevancy score,
* such as boosting by the inverse of the distance.
* such as boosting by the inverse of the distance.
*
*
* @param $field
* @param $pointX
* @param $pointX
* @param $pointY
* @param $pointY
* @param
$fiel
d
* @param
boolean $dereference
d
* @return string
* @return string
*/
*/
public
function
geodist
(
$
pointX
,
$pointY
,
$field
)
public
function
geodist
(
$
field
,
$pointX
,
$pointY
,
$dereferenced
=
false
)
{
{
return
$this
->
functionCall
(
return
$this
->
functionCall
(
'geodist'
,
'geodist'
,
array
(
$pointX
,
$pointY
,
$field
)
array
(
'sfield'
=>
$field
,
'pt'
=>
$pointX
.
','
.
$pointY
),
$dereferenced
);
);
}
}
...
@@ -289,9 +295,10 @@ class Helper
...
@@ -289,9 +295,10 @@ class Helper
* @param string $name
* @param string $name
* @param array $params
* @param array $params
* @param boolean $dereferenced
* @param boolean $dereferenced
* @param boolean $forceKeys
* @return string
* @return string
*/
*/
public
function
qparser
(
$name
,
$params
=
array
(),
$dereferenced
=
false
)
public
function
qparser
(
$name
,
$params
=
array
(),
$dereferenced
=
false
,
$forceKeys
=
false
)
{
{
if
(
$dereferenced
)
{
if
(
$dereferenced
)
{
...
@@ -303,8 +310,12 @@ class Helper
...
@@ -303,8 +310,12 @@ class Helper
}
}
foreach
(
$params
as
$paramKey
=>
$paramValue
)
{
foreach
(
$params
as
$paramKey
=>
$paramValue
)
{
$this
->
derefencedParamsLastKey
++
;
if
(
is_int
(
$paramKey
)
||
$forceKeys
)
{
$derefKey
=
'deref_'
.
$this
->
derefencedParamsLastKey
;
$this
->
derefencedParamsLastKey
++
;
$derefKey
=
'deref_'
.
$this
->
derefencedParamsLastKey
;
}
else
{
$derefKey
=
$paramKey
;
}
$this
->
query
->
addParam
(
$derefKey
,
$paramValue
);
$this
->
query
->
addParam
(
$derefKey
,
$paramValue
);
$params
[
$paramKey
]
=
'$'
.
$derefKey
;
$params
[
$paramKey
]
=
'$'
.
$derefKey
;
}
}
...
@@ -312,7 +323,9 @@ class Helper
...
@@ -312,7 +323,9 @@ class Helper
$output
=
'{!'
.
$name
;
$output
=
'{!'
.
$name
;
foreach
(
$params
as
$key
=>
$value
)
{
foreach
(
$params
as
$key
=>
$value
)
{
$output
.=
' '
.
$key
.
'='
.
$value
;
if
(
!
$dereferenced
||
$forceKeys
||
is_int
(
$key
))
{
$output
.=
' '
.
$key
.
'='
.
$value
;
}
}
}
$output
.=
'}'
;
$output
.=
'}'
;
...
@@ -322,13 +335,21 @@ class Helper
...
@@ -322,13 +335,21 @@ class Helper
/**
/**
* Render a functionCall
* Render a functionCall
*
*
* @param string $name
* @param string $name
* @param array $params
* @param array $params
* @param boolean $dereferenced
* @return string
* @return string
*/
*/
public
function
functionCall
(
$name
,
$params
=
array
())
public
function
functionCall
(
$name
,
$params
=
array
()
,
$dereferenced
=
false
)
{
{
return
$name
.
'('
.
implode
(
$params
,
','
)
.
')'
;
if
(
$dereferenced
)
{
foreach
(
$params
as
$key
=>
$value
)
{
$this
->
query
->
addParam
(
$key
,
$value
);
}
return
$name
.
'()'
;
}
else
{
return
$name
.
'('
.
implode
(
$params
,
','
)
.
')'
;
}
}
}
/**
/**
...
@@ -408,7 +429,7 @@ class Helper
...
@@ -408,7 +429,7 @@ class Helper
*/
*/
public
function
join
(
$from
,
$to
,
$dereferenced
=
false
)
public
function
join
(
$from
,
$to
,
$dereferenced
=
false
)
{
{
return
$this
->
qparser
(
'join'
,
array
(
'from'
=>
$from
,
'to'
=>
$to
),
$dereferenced
);
return
$this
->
qparser
(
'join'
,
array
(
'from'
=>
$from
,
'to'
=>
$to
),
$dereferenced
,
$dereferenced
);
}
}
}
}
tests/Solarium/Tests/Core/Query/HelperTest.php
View file @
9e3ae1fa
...
@@ -81,7 +81,20 @@ class HelperTest extends \PHPUnit_Framework_TestCase
...
@@ -81,7 +81,20 @@ class HelperTest extends \PHPUnit_Framework_TestCase
{
{
$this
->
assertEquals
(
$this
->
assertEquals
(
'{!geofilt pt=45.15,-93.85 sfield=store d=5}'
,
'{!geofilt pt=45.15,-93.85 sfield=store d=5}'
,
$this
->
helper
->
geofilt
(
45.15
,
-
93.85
,
'store'
,
5
)
$this
->
helper
->
geofilt
(
'store'
,
45.15
,
-
93.85
,
5
)
);
}
public
function
testGeofiltDereferenced
()
{
$this
->
assertEquals
(
'{!geofilt}'
,
$this
->
helper
->
geofilt
(
'store'
,
45.15
,
-
93.85
,
5
,
true
)
);
$this
->
assertEquals
(
array
(
'sfield'
=>
'store'
,
'pt'
=>
'45.15,-93.85'
,
'd'
=>
5
),
$this
->
query
->
getParams
()
);
);
}
}
...
@@ -89,15 +102,41 @@ class HelperTest extends \PHPUnit_Framework_TestCase
...
@@ -89,15 +102,41 @@ class HelperTest extends \PHPUnit_Framework_TestCase
{
{
$this
->
assertEquals
(
$this
->
assertEquals
(
'{!bbox pt=45.15,-93.85 sfield=store d=5}'
,
'{!bbox pt=45.15,-93.85 sfield=store d=5}'
,
$this
->
helper
->
bbox
(
45.15
,
-
93.85
,
'store'
,
5
)
$this
->
helper
->
bbox
(
'store'
,
45.15
,
-
93.85
,
5
)
);
}
public
function
testBboxDereferenced
()
{
$this
->
assertEquals
(
'{!bbox}'
,
$this
->
helper
->
bbox
(
'store'
,
45.15
,
-
93.85
,
5
,
true
)
);
$this
->
assertEquals
(
array
(
'sfield'
=>
'store'
,
'pt'
=>
'45.15,-93.85'
,
'd'
=>
5
),
$this
->
query
->
getParams
()
);
);
}
}
public
function
testGeodist
()
public
function
testGeodist
()
{
{
$this
->
assertEquals
(
$this
->
assertEquals
(
'geodist(45.15,-93.85,store)'
,
'geodist(store,45.15,-93.85)'
,
$this
->
helper
->
geodist
(
45.15
,
-
93.85
,
'store'
)
$this
->
helper
->
geodist
(
'store'
,
45.15
,
-
93.85
)
);
}
public
function
testGeodistDereferenced
()
{
$this
->
assertEquals
(
'geodist()'
,
$this
->
helper
->
geodist
(
'store'
,
45.15
,
-
93.85
,
true
)
);
$this
->
assertEquals
(
array
(
'sfield'
=>
'store'
,
'pt'
=>
'45.15,-93.85'
),
$this
->
query
->
getParams
()
);
);
}
}
...
@@ -128,7 +167,7 @@ class HelperTest extends \PHPUnit_Framework_TestCase
...
@@ -128,7 +167,7 @@ class HelperTest extends \PHPUnit_Framework_TestCase
{
{
$this
->
assertEquals
(
$this
->
assertEquals
(
'{!join from=$deref_1 to=$deref_2}'
,
'{!join from=$deref_1 to=$deref_2}'
,
$this
->
helper
->
qparser
(
'join'
,
array
(
'from'
=>
'manu_id'
,
'to'
=>
'id'
),
true
)
$this
->
helper
->
qparser
(
'join'
,
array
(
'from'
=>
'manu_id'
,
'to'
=>
'id'
),
true
,
true
)
);
);
$this
->
assertEquals
(
$this
->
assertEquals
(
...
@@ -139,7 +178,7 @@ class HelperTest extends \PHPUnit_Framework_TestCase
...
@@ -139,7 +178,7 @@ class HelperTest extends \PHPUnit_Framework_TestCase
// second call, params should have updated counts
// second call, params should have updated counts
$this
->
assertEquals
(
$this
->
assertEquals
(
'{!join from=$deref_3 to=$deref_4}'
,
'{!join from=$deref_3 to=$deref_4}'
,
$this
->
helper
->
qparser
(
'join'
,
array
(
'from'
=>
'cat_id'
,
'to'
=>
'prod_id'
),
true
)
$this
->
helper
->
qparser
(
'join'
,
array
(
'from'
=>
'cat_id'
,
'to'
=>
'prod_id'
),
true
,
true
)
);
);
// previous params should also still be there
// previous params should also still be there
...
...
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