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
47b03a15
Commit
47b03a15
authored
Oct 18, 2016
by
Bas de Nooijer
Committed by
GitHub
Oct 18, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #453 from MyHammer/spatial_component
add spatial component
parents
87641c84
5bb0dae1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
274 additions
and
0 deletions
+274
-0
library/Solarium/QueryType/Select/Query/Component/Spatial.php
...ary/Solarium/QueryType/Select/Query/Component/Spatial.php
+96
-0
library/Solarium/QueryType/Select/Query/Query.php
library/Solarium/QueryType/Select/Query/Query.php
+18
-0
library/Solarium/QueryType/Select/RequestBuilder/Component/Spatial.php
...ium/QueryType/Select/RequestBuilder/Component/Spatial.php
+29
-0
tests/Solarium/Tests/QueryType/Select/Query/AbstractQueryTest.php
...larium/Tests/QueryType/Select/Query/AbstractQueryTest.php
+10
-0
tests/Solarium/Tests/QueryType/Select/Query/Component/SpatialTest.php
...um/Tests/QueryType/Select/Query/Component/SpatialTest.php
+88
-0
tests/Solarium/Tests/QueryType/Select/RequestBuilder/Component/SpatialTest.php
...QueryType/Select/RequestBuilder/Component/SpatialTest.php
+33
-0
No files found.
library/Solarium/QueryType/Select/Query/Component/Spatial.php
0 → 100644
View file @
47b03a15
<?php
namespace
Solarium\QueryType\Select\Query\Component
;
use
Solarium\QueryType\Select\Query\Query
as
SelectQuery
;
use
Solarium\QueryType\Select\RequestBuilder\Component\Spatial
as
RequestBuilder
;
/**
* Spatial component.
*
* @link https://cwiki.apache.org/confluence/display/solr/Spatial+Search
*/
class
Spatial
extends
AbstractComponent
{
/**
* Get component type.
*
* @return string
*/
public
function
getType
()
{
return
SelectQuery
::
COMPONENT_SPATIAL
;
}
/**
* Get a requestbuilder for this query.
*
* @return RequestBuilder
*/
public
function
getRequestBuilder
()
{
return
new
RequestBuilder
();
}
/**
* This component has no response parser...
*/
public
function
getResponseParser
()
{
return
;
}
/**
* @param string $sfield
*/
public
function
setField
(
$sfield
)
{
$this
->
setOption
(
'sfield'
,
$sfield
);
}
/**
* @param int $distance
*/
public
function
setDistance
(
$distance
)
{
$this
->
setOption
(
'd'
,
$distance
);
}
/**
* @param string $point
*/
public
function
setPoint
(
$point
)
{
$this
->
setOption
(
'pt'
,
$point
);
}
/**
* Get sfield option.
*
* @return string|null
*/
public
function
getField
()
{
return
$this
->
getOption
(
'sfield'
);
}
/**
* Get d option.
*
* @return int|null
*/
public
function
getDistance
()
{
return
$this
->
getOption
(
'd'
);
}
/**
* Get pt option.
*
* @return int|null
*/
public
function
getPoint
()
{
return
$this
->
getOption
(
'pt'
);
}
}
library/Solarium/QueryType/Select/Query/Query.php
View file @
47b03a15
...
@@ -127,6 +127,11 @@ class Query extends BaseQuery
...
@@ -127,6 +127,11 @@ class Query extends BaseQuery
*/
*/
const
COMPONENT_DEBUG
=
'debug'
;
const
COMPONENT_DEBUG
=
'debug'
;
/**
* Query component spatial.
*/
const
COMPONENT_SPATIAL
=
'spatial'
;
/**
/**
* Default options.
* Default options.
*
*
...
@@ -166,6 +171,7 @@ class Query extends BaseQuery
...
@@ -166,6 +171,7 @@ class Query extends BaseQuery
self
::
COMPONENT_DISTRIBUTEDSEARCH
=>
'Solarium\QueryType\Select\Query\Component\DistributedSearch'
,
self
::
COMPONENT_DISTRIBUTEDSEARCH
=>
'Solarium\QueryType\Select\Query\Component\DistributedSearch'
,
self
::
COMPONENT_STATS
=>
'Solarium\QueryType\Select\Query\Component\Stats\Stats'
,
self
::
COMPONENT_STATS
=>
'Solarium\QueryType\Select\Query\Component\Stats\Stats'
,
self
::
COMPONENT_DEBUG
=>
'Solarium\QueryType\Select\Query\Component\Debug'
,
self
::
COMPONENT_DEBUG
=>
'Solarium\QueryType\Select\Query\Component\Debug'
,
self
::
COMPONENT_SPATIAL
=>
'Solarium\QueryType\Select\Query\Component\Spatial'
,
);
);
/**
/**
...
@@ -1057,6 +1063,18 @@ class Query extends BaseQuery
...
@@ -1057,6 +1063,18 @@ class Query extends BaseQuery
return
$this
->
addTags
(
$tags
);
return
$this
->
addTags
(
$tags
);
}
}
/**
* Get a Spatial component instance.
*
* This is a convenience method that maps presets to getComponent
*
* @return \Solarium\QueryType\Select\Query\Component\Spatial
*/
public
function
getSpatial
()
{
return
$this
->
getComponent
(
self
::
COMPONENT_SPATIAL
,
true
);
}
/**
/**
* Initialize options.
* Initialize options.
*
*
...
...
library/Solarium/QueryType/Select/RequestBuilder/Component/Spatial.php
0 → 100644
View file @
47b03a15
<?php
namespace
Solarium\QueryType\Select\RequestBuilder\Component
;
use
Solarium\QueryType\Select\Query\Component\Spatial
as
SpatialComponent
;
use
Solarium\Core\Client\Request
;
/**
* Add select component spatial to the request.
*/
class
Spatial
implements
ComponentRequestBuilderInterface
{
/**
* Add request settings for Spatial.
*
* @param SpatialComponent $component
* @param Request $request
*
* @return Request
*/
public
function
buildComponent
(
$component
,
$request
)
{
$request
->
addParam
(
'sfield'
,
$component
->
getField
());
$request
->
addParam
(
'pt'
,
$component
->
getPoint
());
$request
->
addParam
(
'd'
,
$component
->
getDistance
());
return
$request
;
}
}
tests/Solarium/Tests/QueryType/Select/Query/AbstractQueryTest.php
View file @
47b03a15
...
@@ -708,4 +708,14 @@ abstract class AbstractQueryTest extends \PHPUnit_Framework_TestCase
...
@@ -708,4 +708,14 @@ abstract class AbstractQueryTest extends \PHPUnit_Framework_TestCase
$this
->
query
->
setTags
(
array
(
't3'
,
't4'
));
$this
->
query
->
setTags
(
array
(
't3'
,
't4'
));
$this
->
assertEquals
(
array
(
't3'
,
't4'
),
$this
->
query
->
getTags
());
$this
->
assertEquals
(
array
(
't3'
,
't4'
),
$this
->
query
->
getTags
());
}
}
public
function
testGetSpatial
()
{
$spatial
=
$this
->
query
->
getSpatial
();
$this
->
assertEquals
(
'Solarium\QueryType\Select\Query\Component\Spatial'
,
get_class
(
$spatial
)
);
}
}
}
tests/Solarium/Tests/QueryType/Select/Query/Component/SpatialTest.php
0 → 100644
View file @
47b03a15
<?php
namespace
Solarium\Tests\QueryType\Select\Query\Component
;
use
Solarium\QueryType\Select\Query\Component\Spatial
;
use
Solarium\QueryType\Select\Query\Query
;
class
SpatialTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @var Spatial
*/
protected
$spatial
;
public
function
setUp
()
{
$this
->
spatial
=
new
Spatial
;
}
public
function
testConfigMode
()
{
$options
=
array
(
'sfield'
=>
'geo'
,
'd'
=>
50
,
'pt'
=>
'48.2233,16.3161'
,
);
$this
->
spatial
->
setOptions
(
$options
);
$this
->
assertEquals
(
$options
[
'sfield'
],
$this
->
spatial
->
getField
());
$this
->
assertEquals
(
$options
[
'd'
],
$this
->
spatial
->
getDistance
());
$this
->
assertEquals
(
$options
[
'pt'
],
$this
->
spatial
->
getPoint
());
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Query
::
COMPONENT_SPATIAL
,
$this
->
spatial
->
getType
()
);
}
public
function
testGetResponseParser
()
{
$this
->
assertEquals
(
null
,
$this
->
spatial
->
getResponseParser
());
}
public
function
testGetRequestBuilder
()
{
$this
->
assertInstanceOf
(
'Solarium\QueryType\Select\RequestBuilder\Component\Spatial'
,
$this
->
spatial
->
getRequestBuilder
()
);
}
public
function
testSetAndGetField
()
{
$value
=
'geo'
;
$this
->
spatial
->
setField
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
spatial
->
getField
()
);
}
public
function
testSetAndGetDistance
()
{
$value
=
'distance'
;
$this
->
spatial
->
setDistance
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
spatial
->
getDistance
()
);
}
public
function
testSetAndGetPoint
()
{
$value
=
'52,13'
;
$this
->
spatial
->
setPoint
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
spatial
->
getPoint
()
);
}
}
tests/Solarium/Tests/QueryType/Select/RequestBuilder/Component/SpatialTest.php
0 → 100644
View file @
47b03a15
<?php
namespace
Solarium\Tests\QueryType\Select\RequestBuilder\Component
;
use
Solarium\QueryType\Select\RequestBuilder\Component\Spatial
as
RequestBuilder
;
use
Solarium\QueryType\Select\Query\Component\Spatial
as
Component
;
use
Solarium\Core\Client\Request
;
class
SpatialTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testBuildComponent
()
{
$builder
=
new
RequestBuilder
();
$request
=
new
Request
();
$component
=
new
Component
();
$component
->
setField
(
'geo'
);
$component
->
setDistance
(
50
);
$component
->
setPoint
(
'48.2233,16.3161'
);
$request
=
$builder
->
buildComponent
(
$component
,
$request
);
$this
->
assertEquals
(
array
(
'pt'
=>
'48.2233,16.3161'
,
'sfield'
=>
'geo'
,
'd'
=>
50
,
),
$request
->
getParams
()
);
}
}
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