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
e450fb35
Commit
e450fb35
authored
Feb 03, 2014
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds endpoint setting to prefetchiterator plugin (#212)
parent
7228d00b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
2 deletions
+64
-2
library/Solarium/Plugin/PrefetchIterator.php
library/Solarium/Plugin/PrefetchIterator.php
+25
-1
tests/Solarium/Tests/Plugin/PrefetchIteratorTest.php
tests/Solarium/Tests/Plugin/PrefetchIteratorTest.php
+39
-1
No files found.
library/Solarium/Plugin/PrefetchIterator.php
View file @
e450fb35
...
...
@@ -43,6 +43,7 @@ use Solarium\Core\Plugin\Plugin;
use
Solarium\QueryType\Select\Query\Query
as
SelectQuery
;
use
Solarium\QueryType\Select\Result\Result
as
SelectResult
;
use
Solarium\QueryType\Select\Result\DocumentInterface
;
use
Solarium\Core\Client\Endpoint
;
/**
* Prefetch plugin
...
...
@@ -142,6 +143,29 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
return
$this
->
query
;
}
/**
* Set endpoint to use
*
* This overwrites any existing endpoint
*
* @param string|Endpoint $endpoint
*/
public
function
setEndpoint
(
$endpoint
)
{
return
$this
->
setOption
(
'endpoint'
,
$endpoint
);
}
/**
* Get endpoint setting
*
* @return string|Endpoint|null
*/
public
function
getEndpoint
()
{
return
$this
->
getOption
(
'endpoint'
);
}
/**
* Countable implementation
*
...
...
@@ -223,7 +247,7 @@ class PrefetchIterator extends Plugin implements \Iterator, \Countable
protected
function
fetchNext
()
{
$this
->
query
->
setStart
(
$this
->
start
)
->
setRows
(
$this
->
getPrefetch
());
$this
->
result
=
$this
->
client
->
execute
(
$this
->
query
);
$this
->
result
=
$this
->
client
->
execute
(
$this
->
query
,
$this
->
getOption
(
'endpoint'
)
);
$this
->
documents
=
$this
->
result
->
getDocuments
();
$this
->
start
+=
$this
->
getPrefetch
();
}
...
...
tests/Solarium/Tests/Plugin/PrefetchIteratorTest.php
View file @
e450fb35
...
...
@@ -79,7 +79,10 @@ class PrefetchIteratorTest extends \PHPUnit_Framework_TestCase
{
$result
=
$this
->
getResult
();
$mockClient
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
,
array
(
'execute'
));
$mockClient
->
expects
(
$this
->
exactly
(
1
))
->
method
(
'execute'
)
->
will
(
$this
->
returnValue
(
$result
));
$mockClient
->
expects
(
$this
->
exactly
(
1
))
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$this
->
query
),
$this
->
equalTo
(
null
))
->
will
(
$this
->
returnValue
(
$result
));
$this
->
plugin
->
initPlugin
(
$mockClient
,
array
());
$this
->
plugin
->
setQuery
(
$this
->
query
);
...
...
@@ -178,6 +181,41 @@ class PrefetchIteratorTest extends \PHPUnit_Framework_TestCase
return
new
SelectDummy
(
1
,
12
,
$numFound
,
$docs
,
array
());
}
public
function
testSetAndGetEndpointAsString
()
{
$this
->
assertEquals
(
null
,
$this
->
plugin
->
getEndpoint
());
$this
->
plugin
->
setEndpoint
(
's1'
);
$this
->
assertEquals
(
's1'
,
$this
->
plugin
->
getEndpoint
());
}
public
function
testWithSpecificEndpoint
()
{
$result
=
$this
->
getResult
();
$mockClient
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
,
array
(
'execute'
));
$mockClient
->
expects
(
$this
->
exactly
(
1
))
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$this
->
query
),
$this
->
equalTo
(
's2'
))
->
will
(
$this
->
returnValue
(
$result
));
$this
->
plugin
->
initPlugin
(
$mockClient
,
array
());
$this
->
plugin
->
setQuery
(
$this
->
query
)
->
setEndpoint
(
's2'
);
$this
->
assertEquals
(
5
,
count
(
$this
->
plugin
));
}
public
function
testWithSpecificEndpointOption
()
{
$result
=
$this
->
getResult
();
$mockClient
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
,
array
(
'execute'
));
$mockClient
->
expects
(
$this
->
exactly
(
1
))
->
method
(
'execute'
)
->
with
(
$this
->
equalTo
(
$this
->
query
),
$this
->
equalTo
(
's3'
))
->
will
(
$this
->
returnValue
(
$result
));
$this
->
plugin
->
initPlugin
(
$mockClient
,
array
(
'endpoint'
=>
's3'
));
$this
->
plugin
->
setQuery
(
$this
->
query
);
$this
->
assertEquals
(
5
,
count
(
$this
->
plugin
));
}
}
class
SelectDummy
extends
Result
...
...
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