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
419de8b7
Commit
419de8b7
authored
Jun 13, 2018
by
thomascorthals
Committed by
Markus Kalkbrenner
Jun 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additional tests for cursormark (#601)
* Additional tests for cursormark * Fixed style issues
parent
4cb8fdfd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
5 deletions
+75
-5
examples/7.6-plugin-prefetchiterator.php
examples/7.6-plugin-prefetchiterator.php
+5
-5
tests/Integration/AbstractTechproductsTest.php
tests/Integration/AbstractTechproductsTest.php
+58
-0
tests/QueryType/Select/Query/AbstractQueryTest.php
tests/QueryType/Select/Query/AbstractQueryTest.php
+4
-0
tests/QueryType/Select/RequestBuilderTest.php
tests/QueryType/Select/RequestBuilderTest.php
+8
-0
No files found.
examples/7.6-plugin-prefetchiterator.php
View file @
419de8b7
...
...
@@ -10,16 +10,16 @@ $client = new Solarium\Client($config);
$query
=
$client
->
createSelect
();
$query
->
setFields
(
array
(
'id'
));
// get a plugin instance and apply settings
$prefetch
=
$client
->
getPlugin
(
'prefetchiterator'
);
$prefetch
->
setPrefetch
(
2
);
//fetch 2 rows per query (for real world use this can be way higher)
$prefetch
->
setQuery
(
$query
);
// cursor functionality can be used for efficient deep paging (since Solr 4.7)
$query
->
setCursormark
(
'*'
);
// cursor functionality requires a sort containing a uniqueKey field as tie breaker on top of your desired sorts for the query
$query
->
addSort
(
'id'
,
$query
::
SORT_ASC
);
// get a plugin instance and apply settings
$prefetch
=
$client
->
getPlugin
(
'prefetchiterator'
);
$prefetch
->
setPrefetch
(
2
);
//fetch 2 rows per query (for real world use this can be way higher)
$prefetch
->
setQuery
(
$query
);
// display the total number of documents found by solr
echo
'NumFound: '
.
count
(
$prefetch
);
...
...
tests/Integration/AbstractTechproductsTest.php
View file @
419de8b7
...
...
@@ -351,6 +351,64 @@ abstract class AbstractTechproductsTest extends TestCase
'pc'
=>
3
,
],
$terms
);
}
public
function
testPrefetchIterator
()
{
$select
=
$this
->
client
->
createSelect
();
$prefetch
=
$this
->
client
->
getPlugin
(
'prefetchiterator'
);
$prefetch
->
setPrefetch
(
2
);
$prefetch
->
setQuery
(
$select
);
// count() uses getNumFound() on the result set and wouldn't actually test if all results are iterated
for
(
$i
=
0
;
$prefetch
->
valid
();
++
$i
)
{
$prefetch
->
next
();
}
$this
->
assertSame
(
32
,
$i
);
}
public
function
testPrefetchIteratorWithCursormark
()
{
$select
=
$this
->
client
->
createSelect
();
$select
->
setCursormark
(
'*'
);
$select
->
addSort
(
'id'
,
SelectQuery
::
SORT_ASC
);
$prefetch
=
$this
->
client
->
getPlugin
(
'prefetchiterator'
);
$prefetch
->
setPrefetch
(
2
);
$prefetch
->
setQuery
(
$select
);
// count() uses getNumFound() on the result set and wouldn't actually test if all results are iterated
for
(
$i
=
0
;
$prefetch
->
valid
();
++
$i
)
{
$prefetch
->
next
();
}
$this
->
assertSame
(
32
,
$i
);
}
public
function
testPrefetchIteratorWithoutAndWithCursormark
()
{
$select
=
$this
->
client
->
createSelect
();
$select
->
addSort
(
'id'
,
SelectQuery
::
SORT_ASC
);
$prefetch
=
$this
->
client
->
getPlugin
(
'prefetchiterator'
);
$prefetch
->
setPrefetch
(
2
);
$prefetch
->
setQuery
(
$select
);
$without
=
[];
foreach
(
$prefetch
as
$document
)
{
$without
=
$document
->
id
;
}
$select
=
$this
->
client
->
createSelect
();
$select
->
setCursormark
(
'*'
);
$select
->
addSort
(
'id'
,
SelectQuery
::
SORT_ASC
);
$prefetch
->
setQuery
(
$select
);
$with
=
[];
foreach
(
$prefetch
as
$document
)
{
$with
=
$document
->
id
;
}
$this
->
assertSame
(
$without
,
$with
);
}
}
class
TestQuery
extends
SelectQuery
...
...
tests/QueryType/Select/Query/AbstractQueryTest.php
View file @
419de8b7
...
...
@@ -417,6 +417,8 @@ abstract class AbstractQueryTest extends TestCase
'resultclass'
=>
'MyResultClass'
,
'documentclass'
=>
'MyDocumentClass'
,
'tag'
=>
[
't1'
,
't2'
],
'cursormark'
=>
'*'
,
'splitonwhitespace'
=>
false
,
];
$query
=
new
Query
(
$config
);
...
...
@@ -427,6 +429,8 @@ abstract class AbstractQueryTest extends TestCase
$this
->
assertSame
(
$config
[
'start'
],
$query
->
getStart
());
$this
->
assertSame
(
$config
[
'documentclass'
],
$query
->
getDocumentClass
());
$this
->
assertSame
(
$config
[
'resultclass'
],
$query
->
getResultClass
());
$this
->
assertSame
(
$config
[
'cursormark'
],
$query
->
getCursormark
());
$this
->
assertSame
(
$config
[
'splitonwhitespace'
],
$query
->
getSplitOnWhitespace
());
$this
->
assertSame
(
'published:true'
,
$query
->
getFilterQuery
(
'pub'
)
->
getQuery
());
$this
->
assertSame
(
'online:true'
,
$query
->
getFilterQuery
(
'online'
)
->
getQuery
());
...
...
tests/QueryType/Select/RequestBuilderTest.php
View file @
419de8b7
...
...
@@ -128,6 +128,14 @@ class RequestBuilderTest extends TestCase
$this
->
assertSame
(
'{!tag=t1,t2}cat:1'
,
$request
->
getParam
(
'q'
));
}
public
function
testWithCursormark
()
{
$this
->
query
->
setCursormark
(
'*'
);
$request
=
$this
->
builder
->
build
(
$this
->
query
);
$this
->
assertSame
(
'*'
,
$request
->
getParam
(
'cursorMark'
));
}
public
function
testWithSplitOnWhitespace
()
{
$this
->
query
->
setSplitOnWhitespace
(
false
);
...
...
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