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
f848d228
Commit
f848d228
authored
Dec 20, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for collections
parent
47b74f62
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
205 additions
and
3 deletions
+205
-3
library/Solarium/QueryType/Select/Query/Component/DistributedSearch.php
...um/QueryType/Select/Query/Component/DistributedSearch.php
+96
-0
library/Solarium/QueryType/Select/RequestBuilder/Component/DistributedSearch.php
...ype/Select/RequestBuilder/Component/DistributedSearch.php
+8
-1
tests/Solarium/Tests/QueryType/Select/Query/Component/DistributedSearchTest.php
...ueryType/Select/Query/Component/DistributedSearchTest.php
+78
-1
tests/Solarium/Tests/QueryType/Select/RequestBuilder/Component/DistributedSearchTest.php
...Select/RequestBuilder/Component/DistributedSearchTest.php
+23
-1
No files found.
library/Solarium/QueryType/Select/Query/Component/DistributedSearch.php
View file @
f848d228
...
...
@@ -44,6 +44,7 @@ use Solarium\QueryType\Select\RequestBuilder\Component\DistributedSearch as Requ
* Distributed Search (sharding) component
*
* @link http://wiki.apache.org/solr/DistributedSearch
* @link http://wiki.apache.org/solr/SolrCloud/
*/
class
DistributedSearch
extends
Component
{
...
...
@@ -55,6 +56,13 @@ class DistributedSearch extends Component
*/
protected
$shards
=
array
();
/**
* Requests will be distributed across collections in this list
*
* @var array
*/
protected
$collections
=
array
();
/**
* Get component type
*
...
...
@@ -100,6 +108,9 @@ class DistributedSearch extends Component
case
'shards'
:
$this
->
setShards
(
$value
);
break
;
case
'collections'
:
$this
->
setCollections
(
$value
);
break
;
}
}
}
...
...
@@ -234,4 +245,89 @@ class DistributedSearch extends Component
{
return
$this
->
getOption
(
'shardhandler'
);
}
/**
* Add a collection
*
* @param string $key unique string
* @param string $collection The syntax is host:port/base_url
* @return self Provides fluent interface
* @link http://wiki.apache.org/solr/SolrCloud/
*/
public
function
addCollection
(
$key
,
$collection
)
{
$this
->
collections
[
$key
]
=
$collection
;
return
$this
;
}
/**
* Add multiple collections
*
* @param array $collections
* @return self Provides fluent interface
*/
public
function
addCollections
(
array
$collections
)
{
foreach
(
$collections
as
$key
=>
$collection
)
{
$this
->
addCollection
(
$key
,
$collection
);
}
return
$this
;
}
/**
* Remove a collection
*
* @param string $key
* @return self Provides fluent interface
*/
public
function
removeCollection
(
$key
)
{
if
(
isset
(
$this
->
collections
[
$key
]))
{
unset
(
$this
->
collections
[
$key
]);
}
return
$this
;
}
/**
* Remove all collections
*
* @return self Provides fluent interface
*/
public
function
clearCollections
()
{
$this
->
collections
=
array
();
return
$this
;
}
/**
* Set multiple collections
*
* This overwrites any existing collections
*
* @param array $collections Associative array of collections
* @return self Provides fluent interface
*/
public
function
setCollections
(
array
$collections
)
{
$this
->
clearCollections
();
$this
->
addCollections
(
$collections
);
return
$this
;
}
/**
* Get a list of the collections
*
* @return array
*/
public
function
getCollections
()
{
return
$this
->
collections
;
}
}
library/Solarium/QueryType/Select/RequestBuilder/Component/DistributedSearch.php
View file @
f848d228
...
...
@@ -55,13 +55,20 @@ class DistributedSearch implements ComponentRequestBuilderInterface
*/
public
function
buildComponent
(
$component
,
$request
)
{
// add shard
field
s to request
// add shards to request
$shards
=
array_values
(
$component
->
getShards
());
if
(
count
(
$shards
))
{
$request
->
addParam
(
'shards'
,
implode
(
','
,
$shards
));
}
$request
->
addParam
(
'shards.qt'
,
$component
->
getShardRequestHandler
());
// add collections to request
$collections
=
array_values
(
$component
->
getCollections
());
if
(
count
(
$collections
))
{
$request
->
addParam
(
'collection'
,
implode
(
','
,
$collections
));
}
return
$request
;
}
}
tests/Solarium/Tests/QueryType/Select/Query/Component/DistributedSearchTest.php
View file @
f848d228
...
...
@@ -46,7 +46,7 @@ class DistributedSearchTest extends \PHPUnit_Framework_TestCase
$this
->
distributedSearch
=
new
DistributedSearch
;
}
public
function
testConfigMode
()
public
function
testConfigMode
ForShards
()
{
$options
=
array
(
'shardhandler'
=>
'dummyhandler'
,
...
...
@@ -62,6 +62,19 @@ class DistributedSearchTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
$options
[
'shards'
],
$this
->
distributedSearch
->
getShards
());
}
public
function
testConfigModeForCollections
()
{
$options
=
array
(
'collections'
=>
array
(
'collection1'
=>
'localhost:8983/solr/collection1'
,
'collection2'
=>
'localhost:8983/solr/collection2'
,
)
);
$this
->
distributedSearch
->
setOptions
(
$options
);
$this
->
assertEquals
(
$options
[
'collections'
],
$this
->
distributedSearch
->
getCollections
());
}
public
function
testGetType
()
{
$this
->
assertEquals
(
...
...
@@ -149,4 +162,68 @@ class DistributedSearchTest extends \PHPUnit_Framework_TestCase
);
}
public
function
testAddCollection
()
{
$this
->
distributedSearch
->
addCollection
(
'collection1'
,
'localhost:8983/solr/collection1'
);
$collections
=
$this
->
distributedSearch
->
getCollections
();
$this
->
assertEquals
(
'localhost:8983/solr/collection1'
,
$collections
[
'collection1'
]
);
}
public
function
testRemoveCollection
()
{
$this
->
distributedSearch
->
addCollection
(
'collection1'
,
'localhost:8983/solr/collection1'
);
$this
->
distributedSearch
->
removeCollection
(
'collection1'
);
$collections
=
$this
->
distributedSearch
->
getCollections
();
$this
->
assertFalse
(
isset
(
$collections
[
'collection1'
]));
}
public
function
testClearCollections
()
{
$this
->
distributedSearch
->
addCollections
(
array
(
'collection1'
=>
'localhost:8983/solr/collection1'
,
'collection2'
=>
'localhost:8983/solr/collection2'
,
));
$this
->
distributedSearch
->
clearCollections
();
$collections
=
$this
->
distributedSearch
->
getCollections
();
$this
->
assertTrue
(
is_array
(
$collections
));
$this
->
assertEquals
(
0
,
count
(
$collections
));
}
public
function
testAddCollections
()
{
$collections
=
array
(
'collection1'
=>
'localhost:8983/solr/collection1'
,
'collection2'
=>
'localhost:8983/solr/collection2'
,
);
$this
->
distributedSearch
->
addCollections
(
$collections
);
$this
->
assertEquals
(
$collections
,
$this
->
distributedSearch
->
getCollections
());
}
public
function
testSetCollections
()
{
$this
->
distributedSearch
->
addCollections
(
array
(
'collection1'
=>
'localhost:8983/solr/collection1'
,
'collection2'
=>
'localhost:8983/solr/collection2'
,
));
$this
->
distributedSearch
->
setCollections
(
array
(
'collection3'
=>
'localhost:8983/solr/collection3'
,
'collection4'
=>
'localhost:8983/solr/collection4'
,
'collection5'
=>
'localhost:8983/solr/collection5'
,
));
$collections
=
$this
->
distributedSearch
->
getCollections
();
$this
->
assertEquals
(
3
,
count
(
$collections
));
$this
->
assertEquals
(
array
(
'collection3'
=>
'localhost:8983/solr/collection3'
,
'collection4'
=>
'localhost:8983/solr/collection4'
,
'collection5'
=>
'localhost:8983/solr/collection5'
,
),
$collections
);
}
}
tests/Solarium/Tests/QueryType/Select/RequestBuilder/Component/DistributedSearchTest.php
View file @
f848d228
...
...
@@ -37,7 +37,7 @@ use Solarium\Core\Client\Request;
class
DistributedSearchTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testBuildComponent
()
public
function
testBuildComponent
WithShards
()
{
$builder
=
new
RequestBuilder
;
$request
=
new
Request
();
...
...
@@ -61,4 +61,26 @@ class DistributedSearchTest extends \PHPUnit_Framework_TestCase
);
}
public
function
testBuildComponentWithCollections
()
{
$builder
=
new
RequestBuilder
;
$request
=
new
Request
();
$component
=
new
Component
();
$component
->
addCollection
(
'collection1'
,
'localhost:8983/solr/collection1'
);
$component
->
addCollections
(
array
(
'collection2'
=>
'localhost:8983/solr/collection2'
,
'collection3'
=>
'localhost:8983/solr/collection3'
));
$request
=
$builder
->
buildComponent
(
$component
,
$request
);
$this
->
assertEquals
(
array
(
'collection'
=>
'localhost:8983/solr/collection1,localhost:8983/solr/collection2,localhost:8983/solr/collection3'
,
),
$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