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
Show 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
*
* Find all entries within the distance of a certain point.
*
* @param $field
* @param $pointX
* @param $pointY
* @param $field
* @param $distance
* @param boolean $dereferenced
* @return string
*/
public
function
geofilt
(
$
pointX
,
$pointY
,
$field
,
$distanc
e
)
public
function
geofilt
(
$
field
,
$pointX
,
$pointY
,
$distance
,
$dereferenced
=
fals
e
)
{
return
$this
->
qparser
(
'geofilt'
,
...
...
@@ -230,7 +231,8 @@ class Helper
'pt'
=>
$pointX
.
','
.
$pointY
,
'sfield'
=>
$field
,
'd'
=>
$distance
)
),
$dereferenced
);
}
...
...
@@ -242,13 +244,14 @@ class Helper
* guaranteed to encompass all of the points of interest, but it may also
* include other points that are slightly outside of the required distance.
*
* @param string $field
* @param string $pointX
* @param string $pointY
* @param string $field
* @param string $distance
* @param boolean $dereferenced
* @return string
*/
public
function
bbox
(
$
pointX
,
$pointY
,
$field
,
$distanc
e
)
public
function
bbox
(
$
field
,
$pointX
,
$pointY
,
$distance
,
$dereferenced
=
fals
e
)
{
return
$this
->
qparser
(
'bbox'
,
...
...
@@ -256,7 +259,8 @@ class Helper
'pt'
=>
$pointX
.
','
.
$pointY
,
'sfield'
=>
$field
,
'd'
=>
$distance
)
),
$dereferenced
);
}
...
...
@@ -269,16 +273,18 @@ class Helper
* or combining the distance with the relevancy score,
* such as boosting by the inverse of the distance.
*
* @param $field
* @param $pointX
* @param $pointY
* @param
$fiel
d
* @param
boolean $dereference
d
* @return string
*/
public
function
geodist
(
$
pointX
,
$pointY
,
$field
)
public
function
geodist
(
$
field
,
$pointX
,
$pointY
,
$dereferenced
=
false
)
{
return
$this
->
functionCall
(
'geodist'
,
array
(
$pointX
,
$pointY
,
$field
)
array
(
'sfield'
=>
$field
,
'pt'
=>
$pointX
.
','
.
$pointY
),
$dereferenced
);
}
...
...
@@ -289,9 +295,10 @@ class Helper
* @param string $name
* @param array $params
* @param boolean $dereferenced
* @param boolean $forceKeys
* @return string
*/
public
function
qparser
(
$name
,
$params
=
array
(),
$dereferenced
=
false
)
public
function
qparser
(
$name
,
$params
=
array
(),
$dereferenced
=
false
,
$forceKeys
=
false
)
{
if
(
$dereferenced
)
{
...
...
@@ -303,8 +310,12 @@ class Helper
}
foreach
(
$params
as
$paramKey
=>
$paramValue
)
{
if
(
is_int
(
$paramKey
)
||
$forceKeys
)
{
$this
->
derefencedParamsLastKey
++
;
$derefKey
=
'deref_'
.
$this
->
derefencedParamsLastKey
;
}
else
{
$derefKey
=
$paramKey
;
}
$this
->
query
->
addParam
(
$derefKey
,
$paramValue
);
$params
[
$paramKey
]
=
'$'
.
$derefKey
;
}
...
...
@@ -312,8 +323,10 @@ class Helper
$output
=
'{!'
.
$name
;
foreach
(
$params
as
$key
=>
$value
)
{
if
(
!
$dereferenced
||
$forceKeys
||
is_int
(
$key
))
{
$output
.=
' '
.
$key
.
'='
.
$value
;
}
}
$output
.=
'}'
;
return
$output
;
...
...
@@ -324,12 +337,20 @@ class Helper
*
* @param string $name
* @param array $params
* @param boolean $dereferenced
* @return string
*/
public
function
functionCall
(
$name
,
$params
=
array
())
public
function
functionCall
(
$name
,
$params
=
array
()
,
$dereferenced
=
false
)
{
if
(
$dereferenced
)
{
foreach
(
$params
as
$key
=>
$value
)
{
$this
->
query
->
addParam
(
$key
,
$value
);
}
return
$name
.
'()'
;
}
else
{
return
$name
.
'('
.
implode
(
$params
,
','
)
.
')'
;
}
}
/**
* Assemble a querystring with placeholders
...
...
@@ -408,7 +429,7 @@ class Helper
*/
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
{
$this
->
assertEquals
(
'{!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
{
$this
->
assertEquals
(
'{!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
()
{
$this
->
assertEquals
(
'geodist(45.15,-93.85,store)'
,
$this
->
helper
->
geodist
(
45.15
,
-
93.85
,
'store'
)
'geodist(store,45.15,-93.85)'
,
$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
{
$this
->
assertEquals
(
'{!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
(
...
...
@@ -139,7 +178,7 @@ class HelperTest extends \PHPUnit_Framework_TestCase
// second call, params should have updated counts
$this
->
assertEquals
(
'{!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
...
...
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