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
8dd15d36
Commit
8dd15d36
authored
Sep 22, 2011
by
Gasol Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added distributed search (shards) support to Solarium_Query_Select
parent
24da6783
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
3 deletions
+146
-3
library/Solarium/Client/RequestBuilder/Select.php
library/Solarium/Client/RequestBuilder/Select.php
+9
-2
library/Solarium/Query/Select.php
library/Solarium/Query/Select.php
+137
-1
No files found.
library/Solarium/Client/RequestBuilder/Select.php
View file @
8dd15d36
...
@@ -63,6 +63,13 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild
...
@@ -63,6 +63,13 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild
$request
->
addParam
(
'fl'
,
implode
(
','
,
$query
->
getFields
()));
$request
->
addParam
(
'fl'
,
implode
(
','
,
$query
->
getFields
()));
$request
->
addParam
(
'wt'
,
'json'
);
$request
->
addParam
(
'wt'
,
'json'
);
// add shard fields to request
$shards
=
array_values
(
$query
->
getShards
());
if
(
count
(
$shards
))
{
$request
->
addParam
(
'shards'
,
implode
(
','
,
$shards
));
}
$request
->
addParam
(
'shards.qt'
,
$query
->
getShardRequestHandler
());
// add sort fields to request
// add sort fields to request
$sort
=
array
();
$sort
=
array
();
foreach
(
$query
->
getSorts
()
AS
$field
=>
$order
)
{
foreach
(
$query
->
getSorts
()
AS
$field
=>
$order
)
{
...
@@ -93,8 +100,8 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild
...
@@ -93,8 +100,8 @@ class Solarium_Client_RequestBuilder_Select extends Solarium_Client_RequestBuild
$request
=
$componentBuilder
->
build
(
$component
,
$request
);
$request
=
$componentBuilder
->
build
(
$component
,
$request
);
}
}
}
}
return
$request
;
return
$request
;
}
}
}
}
\ No newline at end of file
library/Solarium/Query/Select.php
View file @
8dd15d36
...
@@ -166,6 +166,13 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -166,6 +166,13 @@ class Solarium_Query_Select extends Solarium_Query
*/
*/
protected
$_sorts
=
array
();
protected
$_sorts
=
array
();
/**
* Request to be distributed across all shards in the list
*
* @var array
*/
protected
$_shards
=
array
();
/**
/**
* Filterqueries
* Filterqueries
*
*
...
@@ -210,6 +217,9 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -210,6 +217,9 @@ class Solarium_Query_Select extends Solarium_Query
case
'start'
:
case
'start'
:
$this
->
setStart
((
int
)
$value
);
$this
->
setStart
((
int
)
$value
);
break
;
break
;
case
'shards'
:
$this
->
setShards
(
$value
);
break
;
case
'component'
:
case
'component'
:
$this
->
_createComponents
(
$value
);
$this
->
_createComponents
(
$value
);
break
;
break
;
...
@@ -503,6 +513,132 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -503,6 +513,132 @@ class Solarium_Query_Select extends Solarium_Query
return
$this
;
return
$this
;
}
}
/**
* Add a shard
*
* @param string $key unique string
* @param string $shard The syntax is host:port/base_url
* @return Solarium_Query_Select Provides fluent interface
* @link http://wiki.apache.org/solr/DistributedSearch
*/
public
function
addShard
(
$key
,
$shard
)
{
$this
->
_shards
[
$key
]
=
$shard
;
return
$this
;
}
/*
* Add multiple shards
*
* Example usage:
* <code>
* $client = new Solarium_Client;
* $query = $client->createSelect();
* $query->addShards(array(
* 'core0' => 'localhost:8983/solr/core0',
* 'core1' => 'localhost:8983/solr/core1'
* ));
* $result = $client->select($query);
* </code>
* @param array $shards
* @return Solarium_Query_Select Provides fluent interface
*/
public
function
addShards
(
array
$shards
)
{
foreach
(
$shards
as
$key
=>
$shard
)
{
$this
->
addShard
(
$key
,
$shard
);
}
return
$this
;
}
/**
* Remove a shard
*
* @param string $key
* @return Solarium_Query_Select Provides fluent interface
*/
public
function
removeShard
(
$key
)
{
if
(
isset
(
$this
->
_shards
[
$key
]))
{
unset
(
$this
->
_shards
[
$key
]);
}
return
$this
;
}
/**
* Remove all shards
*
* @return Solarium_Query_Select Provides fluent interface
*/
public
function
clearShards
()
{
$this
->
_shards
=
array
();
return
$this
;
}
/**
* Set multiple shards
*
* This overwrites any existing shards
*
* Example usage:
* <code>
* $client = new Solarium_Client;
* $query = $client->createSelect();
* $query->setShards(array(
* 'core0' => 'localhost:8983/solr/core0',
* 'core1' => 'localhost:8983/solr/core1'
* ));
* $result = $client->select($query);
* </code>
*
* @param array $shards Associative array of shards
* @return Solarium_Query_Select Provides fluent interface
*/
public
function
setShards
(
array
$shards
)
{
$this
->
clearShards
();
$this
->
addShards
(
$shards
);
return
$this
;
}
/**
* Get a list of the shards
*
* @return array
*/
public
function
getShards
()
{
return
$this
->
_shards
;
}
/**
* A sharded request will go to the standard request handler
* (not necessarily the original); this can be overridden via shards.qt
*
* @param string
* @return Solarium_Query_Select Provides fluent interface
*/
public
function
setShardRequestHandler
(
$handler
)
{
$this
->
_setOption
(
'shardhandler'
,
$handler
);
return
$this
;
}
/**
* Get a shard request handler (shards.qt)
*
* @param string
* @return Solarium_Query_Select Provides fluent interface
*/
public
function
getShardRequestHandler
()
{
return
$this
->
getOption
(
'shardhandler'
);
}
/**
/**
* Create a filterquery instance
* Create a filterquery instance
*
*
...
@@ -856,4 +992,4 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -856,4 +992,4 @@ class Solarium_Query_Select extends Solarium_Query
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_SPELLCHECK
,
true
);
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_SPELLCHECK
,
true
);
}
}
}
}
\ No newline at end of file
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