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
cfbe19df
Commit
cfbe19df
authored
May 18, 2016
by
Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for deep paging with a cursor
parent
e66f168e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
1 deletion
+93
-1
library/Solarium/Plugin/PrefetchIterator.php
library/Solarium/Plugin/PrefetchIterator.php
+24
-1
library/Solarium/QueryType/Select/Query/Query.php
library/Solarium/QueryType/Select/Query/Query.php
+37
-0
library/Solarium/QueryType/Select/RequestBuilder/RequestBuilder.php
...larium/QueryType/Select/RequestBuilder/RequestBuilder.php
+1
-0
library/Solarium/QueryType/Select/ResponseParser/ResponseParser.php
...larium/QueryType/Select/ResponseParser/ResponseParser.php
+7
-0
library/Solarium/QueryType/Select/Result/Result.php
library/Solarium/QueryType/Select/Result/Result.php
+24
-0
No files found.
library/Solarium/Plugin/PrefetchIterator.php
View file @
cfbe19df
...
...
@@ -91,6 +91,13 @@ class PrefetchIterator extends AbstractPlugin implements \Iterator, \Countable
*/
protected
$position
;
/**
* Cursor mark.
*
* @var string
*/
protected
$cursormark
;
/**
* Documents from the last resultset.
*
...
...
@@ -196,6 +203,10 @@ class PrefetchIterator extends AbstractPlugin implements \Iterator, \Countable
// this condition prevent useless re-fetching of data if a count is done before the iterator is used
if
(
$this
->
start
!==
$this
->
options
[
'prefetch'
])
{
$this
->
start
=
0
;
if
(
null
!==
$this
->
cursormark
)
{
$this
->
cursormark
=
'*'
;
}
}
}
...
...
@@ -251,8 +262,19 @@ class PrefetchIterator extends AbstractPlugin implements \Iterator, \Countable
*/
protected
function
fetchNext
()
{
$this
->
query
->
setStart
(
$this
->
start
)
->
setRows
(
$this
->
getPrefetch
());
if
(
null
===
$this
->
cursormark
&&
null
!==
$this
->
query
->
getCursormark
())
{
$this
->
cursormark
=
'*'
;
}
if
(
null
===
$this
->
cursormark
)
{
$this
->
query
->
setStart
(
$this
->
start
)
->
setRows
(
$this
->
getPrefetch
());
}
else
{
$this
->
query
->
setCursormark
(
$this
->
cursormark
)
->
setRows
(
$this
->
getPrefetch
());
}
$this
->
result
=
$this
->
client
->
execute
(
$this
->
query
,
$this
->
getOption
(
'endpoint'
));
$this
->
cursormark
=
$this
->
result
->
getNextCursorMark
();
$this
->
documents
=
$this
->
result
->
getDocuments
();
$this
->
start
+=
$this
->
getPrefetch
();
}
...
...
@@ -266,5 +288,6 @@ class PrefetchIterator extends AbstractPlugin implements \Iterator, \Countable
$this
->
result
=
null
;
$this
->
documents
=
null
;
$this
->
start
=
0
;
$this
->
cursormark
=
null
;
}
}
library/Solarium/QueryType/Select/Query/Query.php
View file @
cfbe19df
...
...
@@ -1057,6 +1057,40 @@ class Query extends BaseQuery
return
$this
->
addTags
(
$tags
);
}
/**
* Set the cursor mark to fetch.
*
* Cursor functionality requires a sort containing a uniqueKey field tie breaker
*
* @param string $cursormark
*
* @return self Provides fluent interface
*/
public
function
setCursormark
(
$cursormark
)
{
return
$this
->
setOption
(
'cursormark'
,
$cursormark
);
}
/**
* Get the cursor mark.
*
* @return string|null
*/
public
function
getCursormark
()
{
return
$this
->
getOption
(
'cursormark'
);
}
/**
* Remove the cursor mark.
*
* @return self Provides fluent interface
*/
public
function
clearCursormark
()
{
return
$this
->
setOption
(
'cursormark'
,
null
);
}
/**
* Initialize options.
*
...
...
@@ -1094,6 +1128,9 @@ class Query extends BaseQuery
}
$this
->
addTags
(
$value
);
break
;
case
'cursormark'
:
$this
->
setCursormark
(
$value
);
break
;
}
}
}
...
...
library/Solarium/QueryType/Select/RequestBuilder/RequestBuilder.php
View file @
cfbe19df
...
...
@@ -74,6 +74,7 @@ class RequestBuilder extends BaseRequestBuilder
$request
->
addParam
(
'fl'
,
implode
(
','
,
$query
->
getFields
()));
$request
->
addParam
(
'q.op'
,
$query
->
getQueryDefaultOperator
());
$request
->
addParam
(
'df'
,
$query
->
getQueryDefaultField
());
$request
->
addParam
(
'cursorMark'
,
$query
->
getCursormark
());
// add sort fields to request
$sort
=
array
();
...
...
library/Solarium/QueryType/Select/ResponseParser/ResponseParser.php
View file @
cfbe19df
...
...
@@ -107,6 +107,12 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt
$maxScore
=
null
;
}
if
(
isset
(
$data
[
'nextCursorMark'
]))
{
$nextCursorMark
=
$data
[
'nextCursorMark'
];
}
else
{
$nextCursorMark
=
null
;
}
return
$this
->
addHeaderInfo
(
$data
,
array
(
...
...
@@ -114,6 +120,7 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt
'maxscore'
=>
$maxScore
,
'documents'
=>
$documents
,
'components'
=>
$components
,
'nextcursormark'
=>
$nextCursorMark
,
)
);
}
...
...
library/Solarium/QueryType/Select/Result/Result.php
View file @
cfbe19df
...
...
@@ -83,6 +83,15 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
*/
protected
$maxscore
;
/**
* Solr nextcursormark.
*
* Will only be available if 'cursormark' was set for your query
*
* @var string
*/
protected
$nextcursormark
;
/**
* Document instances array.
*
...
...
@@ -171,6 +180,21 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
return
$this
->
maxscore
;
}
/**
* get Solr nextcursormark.
*
* Returns the next cursor mark for deep paging
* Will only be available if 'cursormark' was set for your query
*
* @return string
*/
public
function
getNextCursorMark
()
{
$this
->
parseResponse
();
return
$this
->
nextcursormark
;
}
/**
* Get all documents.
*
...
...
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