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
a0b541ac
Commit
a0b541ac
authored
Aug 05, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release/2.1.0'
parents
6d1f5d85
e172617d
Changes
46
Hide whitespace changes
Inline
Side-by-side
Showing
46 changed files
with
2580 additions
and
42 deletions
+2580
-42
examples/1.3-basic-update.php
examples/1.3-basic-update.php
+7
-7
examples/2.5.5-edismax.php
examples/2.5.5-edismax.php
+44
-0
examples/2.5.6-grouping-by-field.php
examples/2.5.6-grouping-by-field.php
+53
-0
examples/2.5.7-grouping-by-query.php
examples/2.5.7-grouping-by-query.php
+45
-0
examples/3.1-add-docs.php
examples/3.1-add-docs.php
+7
-8
examples/6.2-escaping.php
examples/6.2-escaping.php
+1
-0
examples/6.3-demo-app.php
examples/6.3-demo-app.php
+0
-8
examples/6.3-placeholder-syntax.php
examples/6.3-placeholder-syntax.php
+45
-0
examples/index.html
examples/index.html
+4
-1
library/Solarium/Client/Request.php
library/Solarium/Client/Request.php
+4
-0
library/Solarium/Client/RequestBuilder/Select/Component/DisMax.php
...olarium/Client/RequestBuilder/Select/Component/DisMax.php
+1
-1
library/Solarium/Client/RequestBuilder/Select/Component/Grouping.php
...arium/Client/RequestBuilder/Select/Component/Grouping.php
+71
-0
library/Solarium/Client/ResponseParser/Select.php
library/Solarium/Client/ResponseParser/Select.php
+7
-1
library/Solarium/Client/ResponseParser/Select/Component/Grouping.php
...arium/Client/ResponseParser/Select/Component/Grouping.php
+121
-0
library/Solarium/Document/ReadWrite.php
library/Solarium/Document/ReadWrite.php
+1
-0
library/Solarium/Query/Helper.php
library/Solarium/Query/Helper.php
+79
-0
library/Solarium/Query/Select.php
library/Solarium/Query/Select.php
+24
-1
library/Solarium/Query/Select/Component/DisMax.php
library/Solarium/Query/Select/Component/DisMax.php
+36
-0
library/Solarium/Query/Select/Component/Facet/Query.php
library/Solarium/Query/Select/Component/Facet/Query.php
+7
-1
library/Solarium/Query/Select/Component/Grouping.php
library/Solarium/Query/Select/Component/Grouping.php
+381
-0
library/Solarium/Query/Select/FilterQuery.php
library/Solarium/Query/Select/FilterQuery.php
+7
-1
library/Solarium/Query/Update.php
library/Solarium/Query/Update.php
+46
-0
library/Solarium/Result/Select.php
library/Solarium/Result/Select.php
+12
-0
library/Solarium/Result/Select/Grouping.php
library/Solarium/Result/Select/Grouping.php
+112
-0
library/Solarium/Result/Select/Grouping/FieldGroup.php
library/Solarium/Result/Select/Grouping/FieldGroup.php
+137
-0
library/Solarium/Result/Select/Grouping/QueryGroup.php
library/Solarium/Result/Select/Grouping/QueryGroup.php
+169
-0
library/Solarium/Result/Select/Grouping/ValueGroup.php
library/Solarium/Result/Select/Grouping/ValueGroup.php
+154
-0
tests/Solarium/Client/RequestBuilder/Select/Component/DisMaxTest.php
...ium/Client/RequestBuilder/Select/Component/DisMaxTest.php
+2
-1
tests/Solarium/Client/RequestBuilder/Select/Component/FacetSetTest.php
...m/Client/RequestBuilder/Select/Component/FacetSetTest.php
+1
-1
tests/Solarium/Client/RequestBuilder/Select/Component/GroupingTest.php
...m/Client/RequestBuilder/Select/Component/GroupingTest.php
+69
-0
tests/Solarium/Client/RequestBuilder/Select/Component/HighlightingTest.php
...ient/RequestBuilder/Select/Component/HighlightingTest.php
+6
-6
tests/Solarium/Client/RequestTest.php
tests/Solarium/Client/RequestTest.php
+18
-0
tests/Solarium/Client/ResponseParser/Select/Component/GroupingTest.php
...m/Client/ResponseParser/Select/Component/GroupingTest.php
+139
-0
tests/Solarium/Client/ResponseParser/SelectTest.php
tests/Solarium/Client/ResponseParser/SelectTest.php
+32
-0
tests/Solarium/Query/HelperTest.php
tests/Solarium/Query/HelperTest.php
+45
-0
tests/Solarium/Query/Select/Component/DisMaxTest.php
tests/Solarium/Query/Select/Component/DisMaxTest.php
+13
-0
tests/Solarium/Query/Select/Component/Facet/QueryTest.php
tests/Solarium/Query/Select/Component/Facet/QueryTest.php
+5
-1
tests/Solarium/Query/Select/Component/GroupingTest.php
tests/Solarium/Query/Select/Component/GroupingTest.php
+199
-0
tests/Solarium/Query/Select/FilterQueryTest.php
tests/Solarium/Query/Select/FilterQueryTest.php
+6
-0
tests/Solarium/Query/SelectTest.php
tests/Solarium/Query/SelectTest.php
+18
-2
tests/Solarium/Query/UpdateTest.php
tests/Solarium/Query/UpdateTest.php
+44
-0
tests/Solarium/Result/Select/Grouping/FieldGroupTest.php
tests/Solarium/Result/Select/Grouping/FieldGroupTest.php
+87
-0
tests/Solarium/Result/Select/Grouping/QueryGroupTest.php
tests/Solarium/Result/Select/Grouping/QueryGroupTest.php
+113
-0
tests/Solarium/Result/Select/Grouping/ValueGroupTest.php
tests/Solarium/Result/Select/Grouping/ValueGroupTest.php
+104
-0
tests/Solarium/Result/Select/GroupingTest.php
tests/Solarium/Result/Select/GroupingTest.php
+92
-0
tests/Solarium/Result/SelectTest.php
tests/Solarium/Result/SelectTest.php
+12
-2
No files found.
examples/1.3-basic-update.php
View file @
a0b541ac
...
@@ -6,19 +6,19 @@ htmlHeader();
...
@@ -6,19 +6,19 @@ htmlHeader();
if
(
$_POST
)
{
if
(
$_POST
)
{
// if data is posted add it to solr
// if data is posted add it to solr
// create a new document for the data
// please note that any type of validation is missing in this example to keep it simple!
$doc
=
new
Solarium_Document_ReadWrite
();
$doc
->
id
=
$_POST
[
'id'
];
$doc
->
name
=
$_POST
[
'name'
];
$doc
->
price
=
$_POST
[
'price'
];
// create a client instance
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
$client
=
new
Solarium_Client
(
$config
);
// get an update query instance
// get an update query instance
$update
=
$client
->
createUpdate
();
$update
=
$client
->
createUpdate
();
// create a new document for the data
// please note that any type of validation is missing in this example to keep it simple!
$doc
=
$update
->
createDocument
();
$doc
->
id
=
$_POST
[
'id'
];
$doc
->
name
=
$_POST
[
'name'
];
$doc
->
price
=
$_POST
[
'price'
];
// add the document and a commit command to the update query
// add the document and a commit command to the update query
$update
->
addDocument
(
$doc
);
$update
->
addDocument
(
$doc
);
$update
->
addCommit
();
$update
->
addCommit
();
...
...
examples/2.5.5-edismax.php
0 → 100644
View file @
a0b541ac
<?php
require
(
'init.php'
);
htmlHeader
();
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get a select query instance
$query
=
$client
->
createSelect
();
// get the dismax component and set a boost query
$dismax
=
$query
->
getDisMax
();
// override the default setting of 'dismax' to enable 'edismax'
$dismax
->
setQueryParser
(
'edismax'
);
// this query is now a dismax query
$query
->
setQuery
(
'memory -printer'
);
// this executes the query and returns the result
$resultset
=
$client
->
select
(
$query
);
// display the total number of documents found by solr
echo
'NumFound: '
.
$resultset
->
getNumFound
();
// show documents using the resultset iterator
foreach
(
$resultset
as
$document
)
{
echo
'<hr/><table>'
;
// the documents are also iterable, to get all fields
foreach
(
$document
AS
$field
=>
$value
)
{
// this converts multivalue fields to a comma-separated string
if
(
is_array
(
$value
))
$value
=
implode
(
', '
,
$value
);
echo
'<tr><th>'
.
$field
.
'</th><td>'
.
$value
.
'</td></tr>'
;
}
echo
'</table>'
;
}
htmlFooter
();
\ No newline at end of file
examples/2.5.6-grouping-by-field.php
0 → 100644
View file @
a0b541ac
<?php
require
(
'init.php'
);
htmlHeader
();
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get a select query instance
$query
=
$client
->
createSelect
();
$query
->
setRows
(
50
);
// get grouping component and set a field to group by
$groupComponent
=
$query
->
getGrouping
();
$groupComponent
->
addField
(
'inStock'
);
// maximum number of items per group
$groupComponent
->
setLimit
(
3
);
// get a group count
$groupComponent
->
setNumberOfGroups
(
true
);
// this executes the query and returns the result
$resultset
=
$client
->
select
(
$query
);
$groups
=
$resultset
->
getGrouping
();
foreach
(
$groups
AS
$groupKey
=>
$fieldGroup
)
{
echo
'<h1>'
.
$groupKey
.
'</h1>'
;
echo
'Matches: '
.
$fieldGroup
->
getMatches
()
.
'<br/>'
;
echo
'Number of groups: '
.
$fieldGroup
->
getNumberOfGroups
();
foreach
(
$fieldGroup
AS
$valueGroup
)
{
echo
'<h2>'
.
(
int
)
$valueGroup
->
getValue
()
.
'</h2>'
;
foreach
(
$valueGroup
AS
$document
)
{
echo
'<hr/><table>'
;
// the documents are also iterable, to get all fields
foreach
(
$document
AS
$field
=>
$value
)
{
// this converts multivalue fields to a comma-separated string
if
(
is_array
(
$value
))
$value
=
implode
(
', '
,
$value
);
echo
'<tr><th>'
.
$field
.
'</th><td>'
.
$value
.
'</td></tr>'
;
}
echo
'</table>'
;
}
}
}
htmlFooter
();
\ No newline at end of file
examples/2.5.7-grouping-by-query.php
0 → 100644
View file @
a0b541ac
<?php
require
(
'init.php'
);
htmlHeader
();
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get a select query instance
$query
=
$client
->
createSelect
();
// get grouping component and create two query groups
$groupComponent
=
$query
->
getGrouping
();
$groupComponent
->
addQuery
(
'price:[0 TO 99.99]'
);
$groupComponent
->
addQuery
(
'price:[100 TO *]'
);
// sorting inside groups
$groupComponent
->
setSort
(
'price desc'
);
// maximum number of items per group
$groupComponent
->
setLimit
(
5
);
// this executes the query and returns the result
$resultset
=
$client
->
select
(
$query
);
$groups
=
$resultset
->
getGrouping
();
foreach
(
$groups
AS
$groupKey
=>
$group
)
{
echo
'<h1>'
.
$groupKey
.
'</h1>'
;
foreach
(
$group
AS
$document
)
{
echo
'<hr/><table>'
;
// the documents are also iterable, to get all fields
foreach
(
$document
AS
$field
=>
$value
)
{
// this converts multivalue fields to a comma-separated string
if
(
is_array
(
$value
))
$value
=
implode
(
', '
,
$value
);
echo
'<tr><th>'
.
$field
.
'</th><td>'
.
$value
.
'</td></tr>'
;
}
echo
'</table>'
;
}
}
htmlFooter
();
\ No newline at end of file
examples/3.1-add-docs.php
View file @
a0b541ac
...
@@ -3,25 +3,24 @@
...
@@ -3,25 +3,24 @@
require
(
'init.php'
);
require
(
'init.php'
);
htmlHeader
();
htmlHeader
();
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get an update query instance
$update
=
$client
->
createUpdate
();
// create a new document for the data
// create a new document for the data
$doc1
=
new
Solarium_Document_ReadWrite
();
$doc1
=
$update
->
createDocument
();
$doc1
->
id
=
123
;
$doc1
->
id
=
123
;
$doc1
->
name
=
'testdoc-1'
;
$doc1
->
name
=
'testdoc-1'
;
$doc1
->
price
=
364
;
$doc1
->
price
=
364
;
// and a second one
// and a second one
$doc2
=
new
Solarium_Document_ReadWrite
();
$doc2
=
$update
->
createDocument
();
$doc2
->
id
=
124
;
$doc2
->
id
=
124
;
$doc2
->
name
=
'testdoc-2'
;
$doc2
->
name
=
'testdoc-2'
;
$doc2
->
price
=
340
;
$doc2
->
price
=
340
;
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get an update query instance
$update
=
$client
->
createUpdate
();
// add the documents and a commit command to the update query
// add the documents and a commit command to the update query
$update
->
addDocuments
(
array
(
$doc1
,
$doc2
));
$update
->
addDocuments
(
array
(
$doc1
,
$doc2
));
$update
->
addCommit
();
$update
->
addCommit
();
...
...
examples/6.2-escaping.php
View file @
a0b541ac
...
@@ -13,6 +13,7 @@ $query = $client->createSelect();
...
@@ -13,6 +13,7 @@ $query = $client->createSelect();
$input
=
'ATA "133'
;
$input
=
'ATA "133'
;
// in this case phrase escaping is used (most common) but you can also do term escaping, see the manual
// in this case phrase escaping is used (most common) but you can also do term escaping, see the manual
// also note that the same can be done using the placeholder syntax, see example 6.3
$helper
=
$query
->
getHelper
();
$helper
=
$query
->
getHelper
();
$query
->
setQuery
(
'features:'
.
$helper
->
escapePhrase
(
$input
));
$query
->
setQuery
(
'features:'
.
$helper
->
escapePhrase
(
$input
));
...
...
examples/6.3-demo-app.php
deleted
100644 → 0
View file @
6d1f5d85
<?php
require
(
'init.php'
);
htmlHeader
();
echo
'TODO'
;
htmlFooter
();
\ No newline at end of file
examples/6.3-placeholder-syntax.php
0 → 100644
View file @
a0b541ac
<?php
require
(
'init.php'
);
htmlHeader
();
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get a select query instance
$query
=
$client
->
createSelect
();
// search input string, this value fails without escaping because of the double-quote
$input
=
'ATA "133'
;
// the placeholder syntax applies phrase escaping to the first term
// see the manual for all supported formats
$query
->
setQuery
(
'features: %p1% AND inStock:%2%'
,
array
(
$input
,
1
));
// show the result after replacing the placeholders with values
echo
$query
->
getQuery
()
.
'<br/>'
;
// this executes the query and returns the result
$resultset
=
$client
->
select
(
$query
);
// display the total number of documents found by solr
echo
'NumFound: '
.
$resultset
->
getNumFound
();
// show documents using the resultset iterator
foreach
(
$resultset
as
$document
)
{
echo
'<hr/><table>'
;
// the documents are also iterable, to get all fields
foreach
(
$document
AS
$field
=>
$value
)
{
// this converts multivalue fields to a comma-separated string
if
(
is_array
(
$value
))
$value
=
implode
(
', '
,
$value
);
echo
'<tr><th>'
.
$field
.
'</th><td>'
.
$value
.
'</td></tr>'
;
}
echo
'</table>'
;
}
htmlFooter
();
\ No newline at end of file
examples/index.html
View file @
a0b541ac
...
@@ -43,6 +43,9 @@
...
@@ -43,6 +43,9 @@
<li><a
href=
"2.5.2-morelikethis.php"
>
2.5.2 MoreLikeThis
</a></li>
<li><a
href=
"2.5.2-morelikethis.php"
>
2.5.2 MoreLikeThis
</a></li>
<li><a
href=
"2.5.3-highlighting.php"
>
2.5.3 Highlighting
</a></li>
<li><a
href=
"2.5.3-highlighting.php"
>
2.5.3 Highlighting
</a></li>
<li><a
href=
"2.5.4-dismax.php"
>
2.5.4 Dismax
</a></li>
<li><a
href=
"2.5.4-dismax.php"
>
2.5.4 Dismax
</a></li>
<li><a
href=
"2.5.5-edismax.php"
>
2.5.5 Edismax
</a></li>
<li><a
href=
"2.5.6-grouping-by-field.php"
>
2.5.5 Grouping by field
</a></li>
<li><a
href=
"2.5.7-grouping-by-query.php"
>
2.5.6 Grouping by query
</a></li>
</ul>
</ul>
<li><a
href=
"2.6-helper-functions.php"
>
2.6 Helper functions
</a></li>
<li><a
href=
"2.6-helper-functions.php"
>
2.6 Helper functions
</a></li>
<li><a
href=
"2.7-query-reuse.php"
>
2.7 Query re-use
</a></li>
<li><a
href=
"2.7-query-reuse.php"
>
2.7 Query re-use
</a></li>
...
@@ -79,7 +82,7 @@
...
@@ -79,7 +82,7 @@
<ul
style=
"list-style:none;"
>
<ul
style=
"list-style:none;"
>
<li><a
href=
"6.1-zend-http-adapter.php"
>
6.1 Zend_Http adapter
</a></li>
<li><a
href=
"6.1-zend-http-adapter.php"
>
6.1 Zend_Http adapter
</a></li>
<li><a
href=
"6.2-escaping.php"
>
6.2 Escaping
</a></li>
<li><a
href=
"6.2-escaping.php"
>
6.2 Escaping
</a></li>
<li><a
href=
"6.3-
demo-app.php"
>
2.7 Demo search (mini) application
</a></li>
<li><a
href=
"6.3-
placeholder-syntax.php"
>
6.3 Placeholder syntax
</a></li>
</ul>
</ul>
</ul>
</ul>
...
...
library/Solarium/Client/Request.php
View file @
a0b541ac
...
@@ -210,6 +210,10 @@ class Solarium_Client_Request extends Solarium_Configurable
...
@@ -210,6 +210,10 @@ class Solarium_Client_Request extends Solarium_Configurable
}
}
$this
->
_params
[
$key
][]
=
$value
;
$this
->
_params
[
$key
][]
=
$value
;
}
else
{
}
else
{
// not all solr handlers support 0/1 as boolean values...
if
(
$value
===
true
)
$value
=
'true'
;
if
(
$value
===
false
)
$value
=
'false'
;
$this
->
_params
[
$key
]
=
$value
;
$this
->
_params
[
$key
]
=
$value
;
}
}
}
}
...
...
library/Solarium/Client/RequestBuilder/Select/Component/DisMax.php
View file @
a0b541ac
...
@@ -55,7 +55,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMax
...
@@ -55,7 +55,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMax
public
function
build
(
$component
,
$request
)
public
function
build
(
$component
,
$request
)
{
{
// enable dismax
// enable dismax
$request
->
addParam
(
'defType'
,
'dismax'
);
$request
->
addParam
(
'defType'
,
$component
->
getQueryParser
()
);
$request
->
addParam
(
'q.alt'
,
$component
->
getQueryAlternative
());
$request
->
addParam
(
'q.alt'
,
$component
->
getQueryAlternative
());
$request
->
addParam
(
'qf'
,
$component
->
getQueryFields
());
$request
->
addParam
(
'qf'
,
$component
->
getQueryFields
());
...
...
library/Solarium/Client/RequestBuilder/Select/Component/Grouping.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Add select component Grouping to the request
*
* @package Solarium
* @subpackage Client
*/
class
Solarium_Client_RequestBuilder_Select_Component_Grouping
{
/**
* Add request settings for Grouping
*
* @param Solarium_Query_Select_Component_Grouping $component
* @param Solarium_Client_Request $request
* @return Solarium_Client_Request
*/
public
function
build
(
$component
,
$request
)
{
// enable grouping
$request
->
addParam
(
'group'
,
'true'
);
$request
->
addParam
(
'group.field'
,
$component
->
getFields
());
$request
->
addParam
(
'group.query'
,
$component
->
getQueries
());
$request
->
addParam
(
'group.limit'
,
$component
->
getLimit
());
$request
->
addParam
(
'group.offset'
,
$component
->
getOffset
());
$request
->
addParam
(
'group.sort'
,
$component
->
getSort
());
$request
->
addParam
(
'group.main'
,
$component
->
getMainResult
());
$request
->
addParam
(
'group.ngroups'
,
$component
->
getNumberOfGroups
());
$request
->
addParam
(
'group.cache.percent'
,
$component
->
getCachePercentage
());
return
$request
;
}
}
\ No newline at end of file
library/Solarium/Client/ResponseParser/Select.php
View file @
a0b541ac
...
@@ -76,11 +76,17 @@ class Solarium_Client_ResponseParser_Select extends Solarium_Client_ResponsePars
...
@@ -76,11 +76,17 @@ class Solarium_Client_ResponseParser_Select extends Solarium_Client_ResponsePars
$components
[
$component
->
getType
()]
=
$componentParser
->
parse
(
$query
,
$component
,
$data
);
$components
[
$component
->
getType
()]
=
$componentParser
->
parse
(
$query
,
$component
,
$data
);
}
}
}
}
if
(
isset
(
$data
[
'response'
][
'numFound'
]))
{
$numFound
=
$data
[
'response'
][
'numFound'
];
}
else
{
$numFound
=
null
;
}
return
array
(
return
array
(
'status'
=>
$data
[
'responseHeader'
][
'status'
],
'status'
=>
$data
[
'responseHeader'
][
'status'
],
'queryTime'
=>
$data
[
'responseHeader'
][
'QTime'
],
'queryTime'
=>
$data
[
'responseHeader'
][
'QTime'
],
'numfound'
=>
$
data
[
'response'
][
'numFound'
]
,
'numfound'
=>
$
numFound
,
'documents'
=>
$documents
,
'documents'
=>
$documents
,
'components'
=>
$components
,
'components'
=>
$components
,
);
);
...
...
library/Solarium/Client/ResponseParser/Select/Component/Grouping.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse select component Grouping result from the data
*
* @package Solarium
* @subpackage Client
*/
class
Solarium_Client_ResponseParser_Select_Component_Grouping
{
/**
* Parse result data into result objects
*
* @param Solarium_Query_Select $query
* @param Solarium_Query_Select_Component_Grouping $grouping
* @param array $data
* @return Solarium_Result_Select_Grouping
*/
public
function
parse
(
$query
,
$grouping
,
$data
)
{
$groups
=
array
();
if
(
isset
(
$data
[
'grouped'
]))
{
// parse field groups
foreach
(
$grouping
->
getFields
()
as
$field
)
{
if
(
isset
(
$data
[
'grouped'
][
$field
]))
{
$result
=
$data
[
'grouped'
][
$field
];
$matches
=
(
isset
(
$result
[
'matches'
]))
?
$result
[
'matches'
]
:
null
;
$groupCount
=
(
isset
(
$result
[
'ngroups'
]))
?
$result
[
'ngroups'
]
:
null
;
$valueGroups
=
array
();
foreach
(
$result
[
'groups'
]
as
$valueGroupResult
)
{
$value
=
(
isset
(
$valueGroupResult
[
'groupValue'
]))
?
$valueGroupResult
[
'groupValue'
]
:
null
;
$numFound
=
(
isset
(
$valueGroupResult
[
'doclist'
][
'numFound'
]))
?
$valueGroupResult
[
'doclist'
][
'numFound'
]
:
null
;
$start
=
(
isset
(
$valueGroupResult
[
'doclist'
][
'start'
]))
?
$valueGroupResult
[
'doclist'
][
'start'
]
:
null
;
// create document instances
$documentClass
=
$query
->
getOption
(
'documentclass'
);
$documents
=
array
();
if
(
isset
(
$valueGroupResult
[
'doclist'
][
'docs'
])
&&
is_array
(
$valueGroupResult
[
'doclist'
][
'docs'
]))
{
foreach
(
$valueGroupResult
[
'doclist'
][
'docs'
]
as
$doc
)
{
$documents
[]
=
new
$documentClass
(
$doc
);
}
}
$valueGroups
[]
=
new
Solarium_Result_Select_Grouping_ValueGroup
(
$value
,
$numFound
,
$start
,
$documents
);
}
$groups
[
$field
]
=
new
Solarium_Result_Select_Grouping_FieldGroup
(
$matches
,
$groupCount
,
$valueGroups
);
}
}
// parse query groups
foreach
(
$grouping
->
getQueries
()
as
$groupQuery
)
{
if
(
isset
(
$data
[
'grouped'
][
$groupQuery
]))
{
$result
=
$data
[
'grouped'
][
$groupQuery
];
// get statistics
$matches
=
(
isset
(
$result
[
'matches'
]))
?
$result
[
'matches'
]
:
null
;
$numFound
=
(
isset
(
$result
[
'doclist'
][
'numFound'
]))
?
$result
[
'doclist'
][
'numFound'
]
:
null
;
$start
=
(
isset
(
$result
[
'doclist'
][
'start'
]))
?
$result
[
'doclist'
][
'start'
]
:
null
;
$maxScore
=
(
isset
(
$result
[
'doclist'
][
'maxScore'
]))
?
$result
[
'doclist'
][
'maxScore'
]
:
null
;
// create document instances
$documentClass
=
$query
->
getOption
(
'documentclass'
);
$documents
=
array
();
if
(
isset
(
$result
[
'doclist'
][
'docs'
])
&&
is_array
(
$result
[
'doclist'
][
'docs'
]))
{
foreach
(
$result
[
'doclist'
][
'docs'
]
as
$doc
)
{
$documents
[]
=
new
$documentClass
(
$doc
);
}
}
// create a group result object
$group
=
new
Solarium_Result_Select_Grouping_QueryGroup
(
$matches
,
$numFound
,
$start
,
$maxScore
,
$documents
);
$groups
[
$groupQuery
]
=
$group
;
}
}
}
return
new
Solarium_Result_Select_Grouping
(
$groups
);
}
}
\ No newline at end of file
library/Solarium/Document/ReadWrite.php
View file @
a0b541ac
...
@@ -75,6 +75,7 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
...
@@ -75,6 +75,7 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
* Constructor
* Constructor
*
*
* @param array $fields
* @param array $fields
* @param array $boosts
*/
*/
public
function
__construct
(
$fields
=
array
(),
$boosts
=
array
())
public
function
__construct
(
$fields
=
array
(),
$boosts
=
array
())
{
{
...
...
library/Solarium/Query/Helper.php
View file @
a0b541ac
...
@@ -47,6 +47,20 @@
...
@@ -47,6 +47,20 @@
class
Solarium_Query_Helper
class
Solarium_Query_Helper
{
{
/**
* Placeholder pattern for use in the assemble method
*
* @var string
*/
protected
$_placeHolderPattern
=
'/%(L|P|T|)([0-9]+)%/i'
;
/**
* Array of parts to use for assembling a query string
*
* @var array
*/
protected
$_assembleParts
;
/**
/**
* Escape a term
* Escape a term
*
*
...
@@ -218,4 +232,69 @@ class Solarium_Query_Helper
...
@@ -218,4 +232,69 @@ class Solarium_Query_Helper
return
$name
.
'('
.
implode
(
$params
,
','
)
.
')'
;
return
$name
.
'('
.
implode
(
$params
,
','
)
.
')'
;
}
}
/**
* Assemble a querystring with placeholders
*
* These placeholder modes are supported:
* %1% = no mode, will default to literal
* %L2% = literal
* %P3% = phrase-escaped
* %T4% = term-escaped
*
* Numbering starts at 1, so number 1 refers to the first entry
* of $parts (which has array key 0)
* You can use the same part multiple times, even in multiple modes.
* The mode letters are not case sensitive.
*
* The mode matching pattern can be customized by overriding the
* value of $this->_placeHolderPattern
*
* @since 2.1.0
*
* @param string $query
* @param array $parts Array of strings
* @return string
*/
public
function
assemble
(
$query
,
$parts
)
{
$this
->
_assembleParts
=
$parts
;
return
preg_replace_callback
(
$this
->
_placeHolderPattern
,
array
(
$this
,
'_renderPlaceHolder'
),
$query
);
}
/**
* Render placeholders in a querystring
*
* @throws Solarium_Exception
* @param array $matches
* @return string
*/
protected
function
_renderPlaceHolder
(
$matches
)
{
$partNumber
=
$matches
[
2
];
$partMode
=
strtoupper
(
$matches
[
1
]);
if
(
isset
(
$this
->
_assembleParts
[
$partNumber
-
1
]))
{
$value
=
$this
->
_assembleParts
[
$partNumber
-
1
];
}
else
{
throw
new
Solarium_Exception
(
'No value supplied for part #'
.
$partNumber
.
' in query assembler'
);
}
switch
(
$partMode
)
{
case
'P'
:
$value
=
$this
->
escapePhrase
(
$value
);
break
;
case
'T'
:
$value
=
$this
->
escapeTerm
(
$value
);
break
;
}
return
$value
;
}
}
}
\ No newline at end of file
library/Solarium/Query/Select.php
View file @
a0b541ac
...
@@ -62,6 +62,7 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -62,6 +62,7 @@ class Solarium_Query_Select extends Solarium_Query
const
COMPONENT_DISMAX
=
'dismax'
;
const
COMPONENT_DISMAX
=
'dismax'
;
const
COMPONENT_MORELIKETHIS
=
'morelikethis'
;
const
COMPONENT_MORELIKETHIS
=
'morelikethis'
;
const
COMPONENT_HIGHLIGHTING
=
'highlighting'
;
const
COMPONENT_HIGHLIGHTING
=
'highlighting'
;
const
COMPONENT_GROUPING
=
'grouping'
;
/**
/**
* Get type for this query
* Get type for this query
...
@@ -114,6 +115,11 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -114,6 +115,11 @@ class Solarium_Query_Select extends Solarium_Query
'requestbuilder'
=>
'Solarium_Client_RequestBuilder_Select_Component_Highlighting'
,
'requestbuilder'
=>
'Solarium_Client_RequestBuilder_Select_Component_Highlighting'
,
'responseparser'
=>
'Solarium_Client_ResponseParser_Select_Component_Highlighting'
,
'responseparser'
=>
'Solarium_Client_ResponseParser_Select_Component_Highlighting'
,
),
),
self
::
COMPONENT_GROUPING
=>
array
(
'component'
=>
'Solarium_Query_Select_Component_Grouping'
,
'requestbuilder'
=>
'Solarium_Client_RequestBuilder_Select_Component_Grouping'
,
'responseparser'
=>
'Solarium_Client_ResponseParser_Select_Component_Grouping'
,
),
);
);
/**
/**
...
@@ -188,10 +194,15 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -188,10 +194,15 @@ class Solarium_Query_Select extends Solarium_Query
* escaping of user input.
* escaping of user input.
*
*
* @param string $query
* @param string $query
* @param array $bind Bind values for placeholders in the query string
* @return Solarium_Query_Select Provides fluent interface
* @return Solarium_Query_Select Provides fluent interface
*/
*/
public
function
setQuery
(
$query
)
public
function
setQuery
(
$query
,
$bind
=
null
)
{
{
if
(
!
is_null
(
$bind
))
{
$query
=
$this
->
getHelper
()
->
assemble
(
$query
,
$bind
);
}
return
$this
->
_setOption
(
'query'
,
trim
(
$query
));
return
$this
->
_setOption
(
'query'
,
trim
(
$query
));
}
}
...
@@ -750,4 +761,16 @@ class Solarium_Query_Select extends Solarium_Query
...
@@ -750,4 +761,16 @@ class Solarium_Query_Select extends Solarium_Query
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
,
true
);
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
,
true
);
}
}
/**
* Get a grouping component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_Grouping
*/
public
function
getGrouping
()
{
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_GROUPING
,
true
);
}
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component/DisMax.php
View file @
a0b541ac
...
@@ -54,6 +54,15 @@ class Solarium_Query_Select_Component_DisMax extends Solarium_Query_Select_Compo
...
@@ -54,6 +54,15 @@ class Solarium_Query_Select_Component_DisMax extends Solarium_Query_Select_Compo
*/
*/
protected
$_type
=
Solarium_Query_Select
::
COMPONENT_DISMAX
;
protected
$_type
=
Solarium_Query_Select
::
COMPONENT_DISMAX
;
/**
* Default options
*
* @var array
*/
protected
$_options
=
array
(
'queryparser'
=>
'dismax'
,
);
/**
/**
* Set QueryAlternative option
* Set QueryAlternative option
*
*
...
@@ -276,4 +285,31 @@ class Solarium_Query_Select_Component_DisMax extends Solarium_Query_Select_Compo
...
@@ -276,4 +285,31 @@ class Solarium_Query_Select_Component_DisMax extends Solarium_Query_Select_Compo
return
$this
->
getOption
(
'boostfunctions'
);
return
$this
->
getOption
(
'boostfunctions'
);
}
}
/**
* Set QueryParser option
*
* Can be used to enable edismax
*
* @since 2.1.0
*
* @param string $parser
* @return Solarium_Query_Select_Component_DisMax Provides fluent interface
*/
public
function
setQueryParser
(
$parser
)
{
return
$this
->
_setOption
(
'queryparser'
,
$parser
);
}
/**
* Get QueryParser option
*
* @since 2.1.0
*
* @return string
*/
public
function
getQueryParser
()
{
return
$this
->
getOption
(
'queryparser'
);
}
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component/Facet/Query.php
View file @
a0b541ac
...
@@ -72,10 +72,16 @@ class Solarium_Query_Select_Component_Facet_Query extends Solarium_Query_Select_
...
@@ -72,10 +72,16 @@ class Solarium_Query_Select_Component_Facet_Query extends Solarium_Query_Select_
* This overwrites the current value
* This overwrites the current value
*
*
* @param string $query
* @param string $query
* @param array $bind Bind values for placeholders in the query string
* @return Solarium_Query_Select_Facet_Query Provides fluent interface
* @return Solarium_Query_Select_Facet_Query Provides fluent interface
*/
*/
public
function
setQuery
(
$query
)
public
function
setQuery
(
$query
,
$bind
=
null
)
{
{
if
(
!
is_null
(
$bind
))
{
$helper
=
new
Solarium_Query_Helper
;
$query
=
$helper
->
assemble
(
$query
,
$bind
);
}
return
$this
->
_setOption
(
'query'
,
$query
);
return
$this
->
_setOption
(
'query'
,
$query
);
}
}
...
...
library/Solarium/Query/Select/Component/Grouping.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Query
*/
/**
* Grouping component
*
* Also known as Result Grouping or Field Collapsing.
* See the Solr wiki for more info about this functionality
*
* @link http://wiki.apache.org/solr/FieldCollapsing
*
* @since 2.1.0
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Component_Grouping
extends
Solarium_Query_Select_Component
{
/**
* Values for format option
*/
const
FORMAT_GROUPED
=
'grouped'
;
const
FORMAT_SIMPLE
=
'simple'
;
/**
* Component type
*
* @var string
*/
protected
$_type
=
Solarium_Query_Select
::
COMPONENT_GROUPING
;
/**
* Fields for grouping
*
* @var array
*/
protected
$_fields
=
array
();
/**
* Queries for grouping
*
* @var array
*/
protected
$_queries
=
array
();
/**
* Initialize options
*
* Several options need some extra checks or setup work, for these options
* the setters are called.
*
* @return void
*/
protected
function
_init
()
{
foreach
(
$this
->
_options
AS
$name
=>
$value
)
{
switch
(
$name
)
{
case
'queries'
:
$this
->
setQueries
(
$value
);
break
;
case
'fields'
:
$this
->
setFields
(
$value
);
break
;
}
}
}
/**
* Add a grouping field
*
* Group based on the unique values of a field
*
* @param string $field
* @return Solarium_Field_Select_Component_Grouping fluent interface
*/
public
function
addField
(
$field
)
{
$this
->
_fields
[]
=
$field
;
return
$this
;
}
/**
* Add multiple grouping fields
*
* You can use an array or a comma separated string as input
*
* @param array|string $fields
* @return Solarium_Field_Select_Component_Grouping Provides fluent interface
*/
public
function
addFields
(
$fields
)
{
if
(
is_string
(
$fields
))
{
$fields
=
explode
(
','
,
$fields
);
$fields
=
array_map
(
'trim'
,
$fields
);
}
$this
->
_fields
=
array_merge
(
$this
->
_fields
,
$fields
);
return
$this
;
}
/**
* Get all fields
*
* @return array
*/
public
function
getFields
()
{
return
$this
->
_fields
;
}
/**
* Remove all fields
*
* @return Solarium_Field_Select_Component_Grouping fluent interface
*/
public
function
clearFields
()
{
$this
->
_fields
=
array
();
return
$this
;
}
/**
* Set multiple fields
*
* This overwrites any existing fields
*
* @param array $fields
*/
public
function
setFields
(
$fields
)
{
$this
->
clearFields
();
$this
->
addFields
(
$fields
);
}
/**
* Add a grouping query
*
* Group documents that match the given query
*
* @param string $query
* @return Solarium_Query_Select_Component_Grouping fluent interface
*/
public
function
addQuery
(
$query
)
{
$this
->
_queries
[]
=
$query
;
return
$this
;
}
/**
* Add multiple grouping queries
*
* @param array|string $queries
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public
function
addQueries
(
$queries
)
{
if
(
!
is_array
(
$queries
))
$queries
=
array
(
$queries
);
$this
->
_queries
=
array_merge
(
$this
->
_queries
,
$queries
);
return
$this
;
}
/**
* Get all queries
*
* @return array
*/
public
function
getQueries
()
{
return
$this
->
_queries
;
}
/**
* Remove all queries
*
* @return Solarium_Query_Select_Component_Grouping fluent interface
*/
public
function
clearQueries
()
{
$this
->
_queries
=
array
();
return
$this
;
}
/**
* Set multiple queries
*
* This overwrites any existing queries
*
* @param array $queries
*/
public
function
setQueries
(
$queries
)
{
$this
->
clearQueries
();
$this
->
addQueries
(
$queries
);
}
/**
* Set limit option
*
* The number of results (documents) to return for each group
*
* @param int $limit
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public
function
setLimit
(
$limit
)
{
return
$this
->
_setOption
(
'limit'
,
$limit
);
}
/**
* Get limit option
*
* @return string|null
*/
public
function
getLimit
()
{
return
$this
->
getOption
(
'limit'
);
}
/**
* Set offset option
*
* The offset into the document list of each group.
*
* @param int $offset
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public
function
setOffset
(
$offset
)
{
return
$this
->
_setOption
(
'offset'
,
$offset
);
}
/**
* Get offset option
*
* @return string|null
*/
public
function
getOffset
()
{
return
$this
->
getOption
(
'offset'
);
}
/**
* Set sort option
*
* How to sort documents within a single group
*
* @param string $sort
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public
function
setSort
(
$sort
)
{
return
$this
->
_setOption
(
'sort'
,
$sort
);
}
/**
* Get sort option
*
* @return string|null
*/
public
function
getSort
()
{
return
$this
->
getOption
(
'sort'
);
}
/**
* Set mainresult option
*
* If true, the result of the first field grouping command is used as the main
* result list in the response, using group format 'simple'
*
* @param boolean $value
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public
function
setMainResult
(
$value
)
{
return
$this
->
_setOption
(
'mainresult'
,
$value
);
}
/**
* Get mainresult option
*
* @return boolean|null
*/
public
function
getMainResult
()
{
return
$this
->
getOption
(
'mainresult'
);
}
/**
* Set numberofgroups option
*
* If true, includes the number of groups that have matched the query.
*
* @param boolean $value
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public
function
setNumberOfGroups
(
$value
)
{
return
$this
->
_setOption
(
'numberofgroups'
,
$value
);
}
/**
* Get numberofgroups option
*
* @return boolean|null
*/
public
function
getNumberOfGroups
()
{
return
$this
->
getOption
(
'numberofgroups'
);
}
/**
* Set cachepercentage option
*
* If > 0 enables grouping cache. Grouping is executed actual two searches.
* This option caches the second search. A value of 0 disables grouping caching.
*
* Tests have shown that this cache only improves search time with boolean queries,
* wildcard queries and fuzzy queries. For simple queries like a term query or
* a match all query this cache has a negative impact on performance
*
* @param integer $value
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public
function
setCachePercentage
(
$value
)
{
return
$this
->
_setOption
(
'cachepercentage'
,
$value
);
}
/**
* Get cachepercentage option
*
* @return integer|null
*/
public
function
getCachePercentage
()
{
return
$this
->
getOption
(
'cachepercentage'
);
}
}
\ No newline at end of file
library/Solarium/Query/Select/FilterQuery.php
View file @
a0b541ac
...
@@ -111,10 +111,16 @@ class Solarium_Query_Select_FilterQuery extends Solarium_Configurable
...
@@ -111,10 +111,16 @@ class Solarium_Query_Select_FilterQuery extends Solarium_Configurable
* This overwrites the current value
* This overwrites the current value
*
*
* @param string $query
* @param string $query
* @param array $bind Bind values for placeholders in the query string
* @return Solarium_Query Provides fluent interface
* @return Solarium_Query Provides fluent interface
*/
*/
public
function
setQuery
(
$query
)
public
function
setQuery
(
$query
,
$bind
=
null
)
{
{
if
(
!
is_null
(
$bind
))
{
$helper
=
new
Solarium_Query_Helper
;
$query
=
$helper
->
assemble
(
$query
,
$bind
);
}
$this
->
_query
=
trim
(
$query
);
$this
->
_query
=
trim
(
$query
);
return
$this
;
return
$this
;
}
}
...
...
library/Solarium/Query/Update.php
View file @
a0b541ac
...
@@ -79,6 +79,7 @@ class Solarium_Query_Update extends Solarium_Query
...
@@ -79,6 +79,7 @@ class Solarium_Query_Update extends Solarium_Query
protected
$_options
=
array
(
protected
$_options
=
array
(
'handler'
=>
'update'
,
'handler'
=>
'update'
,
'resultclass'
=>
'Solarium_Result_Update'
,
'resultclass'
=>
'Solarium_Result_Update'
,
'documentclass'
=>
'Solarium_Document_ReadWrite'
,
);
);
/**
/**
...
@@ -359,4 +360,49 @@ class Solarium_Query_Update extends Solarium_Query
...
@@ -359,4 +360,49 @@ class Solarium_Query_Update extends Solarium_Query
return
$this
->
add
(
null
,
$optimize
);
return
$this
->
add
(
null
,
$optimize
);
}
}
/**
* Set a custom document class for use in the createDocument method
*
* This class should extend Solarium_Document_ReadWrite or
* at least be compatible with it's interface
*
* @param string $value classname
* @return Solarium_Query
*/
public
function
setDocumentClass
(
$value
)
{
return
$this
->
_setOption
(
'documentclass'
,
$value
);
}
/**
* Get the current documentclass option
*
* The value is a classname, not an instance
*
* @return string
*/
public
function
getDocumentClass
()
{
return
$this
->
getOption
(
'documentclass'
);
}
/**
* Create a document object instance
*
* You can optionally directly supply the fields and boosts
* to get a ready-made document instance for direct use in an add command
*
* @since 2.1.0
*
* @param array $fields
* @param array $boosts
* @return Solarium_Document_ReadWrite
*/
public
function
createDocument
(
$fields
=
array
(),
$boosts
=
array
())
{
$class
=
$this
->
getDocumentClass
();
return
new
$class
(
$fields
,
$boosts
);
}
}
}
\ No newline at end of file
library/Solarium/Result/Select.php
View file @
a0b541ac
...
@@ -234,6 +234,18 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
...
@@ -234,6 +234,18 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
);
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
);
}
}
/**
* Get grouping component result
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Result_Select_Grouping
*/
public
function
getGrouping
()
{
return
$this
->
getComponent
(
Solarium_Query_Select
::
COMPONENT_GROUPING
);
}
/**
/**
* Get facetset component result
* Get facetset component result
*
*
...
...
library/Solarium/Result/Select/Grouping.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component grouping result
*
* @since 2.1.0
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_Grouping
implements
IteratorAggregate
,
Countable
{
/**
* Group results array
*
* @var array
*/
protected
$_groups
;
/**
* Constructor
*
* @param array $groups
* @return void
*/
public
function
__construct
(
$groups
)
{
$this
->
_groups
=
$groups
;
}
/**
* Get all groups
*
* @return array
*/
public
function
getGroups
()
{
return
$this
->
_groups
;
}
/**
* Get a group
*
* @param string $key
* @return Solarium_Result_Select_Grouping_FieldGroup|Solarium_Result_Select_Grouping_QueryGroup
*/
public
function
getGroup
(
$key
)
{
if
(
isset
(
$this
->
_groups
[
$key
]))
{
return
$this
->
_groups
[
$key
];
}
else
{
return
null
;
}
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
_groups
);
}
/**
* Countable implementation
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
_groups
);
}
}
\ No newline at end of file
library/Solarium/Result/Select/Grouping/FieldGroup.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component grouping field group result
*
* @since 2.1.0
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_Grouping_FieldGroup
implements
IteratorAggregate
,
Countable
{
/**
* Match count
*
* @var int
*/
protected
$_matches
;
/**
* Number of groups
*
* @var int
*/
protected
$_numberOfGroups
;
/**
* Value groups
*
* @var array
*/
protected
$_valueGroups
;
/**
* Constructor
*
* @param int $matches
* @param int $numberOfGroups
* @param array $groups
* @return void
*/
public
function
__construct
(
$matches
,
$numberOfGroups
,
$groups
)
{
$this
->
_matches
=
$matches
;
$this
->
_numberOfGroups
=
$numberOfGroups
;
$this
->
_valueGroups
=
$groups
;
}
/**
* Get matches value
*
* @return int
*/
public
function
getMatches
()
{
return
$this
->
_matches
;
}
/**
* Get numberOfGroups value
*
* Only available if the numberofgroups option in the query was 'true'
*
* @return int
*/
public
function
getNumberOfGroups
()
{
return
$this
->
_numberOfGroups
;
}
/**
* Get all value groups
*
* @return array
*/
public
function
getValueGroups
()
{
return
$this
->
_valueGroups
;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
_valueGroups
);
}
/**
* Countable implementation
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
_valueGroups
);
}
}
\ No newline at end of file
library/Solarium/Result/Select/Grouping/QueryGroup.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component grouping query group result
*
* @since 2.1.0
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_Grouping_QueryGroup
implements
IteratorAggregate
,
Countable
{
/**
* Match count
*
* @var int
*/
protected
$_matches
;
/**
* NumFound value
*
* @var int
*/
protected
$_numFound
;
/**
* Start offset
*
* @var int
*/
protected
$_start
;
/**
* Maximum score in group
*
* @var float
*/
protected
$_maximumScore
;
/**
* Group documents array
*
* @var array
*/
protected
$_documents
;
/**
* Constructor
*
* @param array $groups
* @return void
*/
public
function
__construct
(
$matches
,
$numFound
,
$start
,
$maximumScore
,
$documents
)
{
$this
->
_matches
=
$matches
;
$this
->
_numFound
=
$numFound
;
$this
->
_start
=
$start
;
$this
->
_maximumScore
=
$maximumScore
;
$this
->
_documents
=
$documents
;
}
/**
* Get matches value
*
* @return int
*/
public
function
getMatches
()
{
return
$this
->
_matches
;
}
/**
* Get numFound value
*
* @return int
*/
public
function
getNumFound
()
{
return
$this
->
_numFound
;
}
/**
* Get start value
*
* @return int
*/
public
function
getStart
()
{
return
$this
->
_start
;
}
/**
* Get maximumScore value
*
* @return int
*/
public
function
getMaximumScore
()
{
return
$this
->
_maximumScore
;
}
/**
* Get all documents
*
* @return array
*/
public
function
getDocuments
()
{
return
$this
->
_documents
;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
_documents
);
}
/**
* Countable implementation
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
_documents
);
}
}
\ No newline at end of file
library/Solarium/Result/Select/Grouping/ValueGroup.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component grouping field value group result
*
* @since 2.1.0
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_Grouping_ValueGroup
implements
IteratorAggregate
,
Countable
{
/**
* Field value
*
* @var string
*/
protected
$_value
;
/**
* NumFound
*
* @var int
*/
protected
$_numFound
;
/**
* Start position
*
* @var int
*/
protected
$_start
;
/**
* Documents in this group
*
* @var array
*/
protected
$_documents
;
/**
* Constructor
*
* @param string $value
* @param int $numFound
* @param int $start
* @param array $documents
* @return void
*/
public
function
__construct
(
$value
,
$numFound
,
$start
,
$documents
)
{
$this
->
_value
=
$value
;
$this
->
_numFound
=
$numFound
;
$this
->
_start
=
$start
;
$this
->
_documents
=
$documents
;
}
/**
* Get value
*
* @return string
*/
public
function
getValue
()
{
return
$this
->
_value
;
}
/**
* Get numFound
*
* @return int
*/
public
function
getNumFound
()
{
return
$this
->
_numFound
;
}
/**
* Get start
*
* @return int
*/
public
function
getStart
()
{
return
$this
->
_start
;
}
/**
* Get all documents
*
* @return array
*/
public
function
getDocuments
()
{
return
$this
->
_documents
;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public
function
getIterator
()
{
return
new
ArrayIterator
(
$this
->
_documents
);
}
/**
* Countable implementation
*
* @return int
*/
public
function
count
()
{
return
count
(
$this
->
_documents
);
}
}
\ No newline at end of file
tests/Solarium/Client/RequestBuilder/Select/Component/DisMaxTest.php
View file @
a0b541ac
...
@@ -38,6 +38,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit
...
@@ -38,6 +38,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit
$request
=
new
Solarium_Client_Request
();
$request
=
new
Solarium_Client_Request
();
$component
=
new
Solarium_Query_Select_Component_DisMax
();
$component
=
new
Solarium_Query_Select_Component_DisMax
();
$component
->
setQueryParser
(
'dummyparser'
);
$component
->
setQueryAlternative
(
'test'
);
$component
->
setQueryAlternative
(
'test'
);
$component
->
setQueryFields
(
'content,name'
);
$component
->
setQueryFields
(
'content,name'
);
$component
->
setMinimumMatch
(
'75%'
);
$component
->
setMinimumMatch
(
'75%'
);
...
@@ -52,7 +53,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit
...
@@ -52,7 +53,7 @@ class Solarium_Client_RequestBuilder_Select_Component_DisMaxTest extends PHPUnit
$this
->
assertEquals
(
$this
->
assertEquals
(
array
(
array
(
'defType'
=>
'd
ismax
'
,
'defType'
=>
'd
ummyparser
'
,
'q.alt'
=>
'test'
,
'q.alt'
=>
'test'
,
'qf'
=>
'content,name'
,
'qf'
=>
'content,name'
,
'mm'
=>
'75%'
,
'mm'
=>
'75%'
,
...
...
tests/Solarium/Client/RequestBuilder/Select/Component/FacetSetTest.php
View file @
a0b541ac
...
@@ -126,7 +126,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn
...
@@ -126,7 +126,7 @@ class Solarium_Client_RequestBuilder_Select_Component_FacetSetTest extends PHPUn
);
);
$this
->
assertEquals
(
$this
->
assertEquals
(
'?facet=true&facet.missing=
1
&facet.limit=10&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40'
,
'?facet=true&facet.missing=
true
&facet.limit=10&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40'
,
urldecode
(
$request
->
getUri
())
urldecode
(
$request
->
getUri
())
);
);
}
}
...
...
tests/Solarium/Client/RequestBuilder/Select/Component/GroupingTest.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Client_RequestBuilder_Select_Component_GroupingTest
extends
PHPUnit_Framework_TestCase
{
public
function
testBuild
()
{
$builder
=
new
Solarium_Client_RequestBuilder_Select_Component_Grouping
;
$request
=
new
Solarium_Client_Request
();
$component
=
new
Solarium_Query_Select_Component_Grouping
();
$component
->
setFields
(
array
(
'fieldA'
,
'fieldB'
));
$component
->
setQueries
(
array
(
'cat:1'
,
'cat:2'
));
$component
->
setLimit
(
12
);
$component
->
setOffset
(
2
);
$component
->
setSort
(
'score desc'
);
$component
->
setMainResult
(
true
);
$component
->
setNumberOfGroups
(
false
);
$component
->
setCachePercentage
(
50
);
$request
=
$builder
->
build
(
$component
,
$request
);
$this
->
assertEquals
(
array
(
'group'
=>
'true'
,
'group.field'
=>
array
(
'fieldA'
,
'fieldB'
),
'group.query'
=>
array
(
'cat:1'
,
'cat:2'
),
'group.limit'
=>
12
,
'group.offset'
=>
2
,
'group.sort'
=>
'score desc'
,
'group.main'
=>
'true'
,
'group.ngroups'
=>
'false'
,
'group.cache.percent'
=>
50
,
),
$request
->
getParams
()
);
}
}
tests/Solarium/Client/RequestBuilder/Select/Component/HighlightingTest.php
View file @
a0b541ac
...
@@ -63,12 +63,12 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
...
@@ -63,12 +63,12 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
$this
->
assertEquals
(
$this
->
assertEquals
(
array
(
array
(
'hl'
=>
true
,
'hl'
=>
'true'
,
'hl.fl'
=>
'fieldA,fieldB'
,
'hl.fl'
=>
'fieldA,fieldB'
,
'hl.snippets'
=>
2
,
'hl.snippets'
=>
2
,
'hl.fragsize'
=>
3
,
'hl.fragsize'
=>
3
,
'hl.mergeContiguous'
=>
true
,
'hl.mergeContiguous'
=>
'true'
,
'hl.requireFieldMatch'
=>
false
,
'hl.requireFieldMatch'
=>
'false'
,
'hl.maxAnalyzedChars'
=>
100
,
'hl.maxAnalyzedChars'
=>
100
,
'hl.alternateField'
=>
'fieldC'
,
'hl.alternateField'
=>
'fieldC'
,
'hl.maxAlternateFieldLength'
=>
5
,
'hl.maxAlternateFieldLength'
=>
5
,
...
@@ -78,9 +78,9 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
...
@@ -78,9 +78,9 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
'hl.fragmenter'
=>
'myFragmenter'
,
'hl.fragmenter'
=>
'myFragmenter'
,
'hl.fragListBuilder'
=>
'myFragListBuilder'
,
'hl.fragListBuilder'
=>
'myFragListBuilder'
,
'hl.fragmentsBuilder'
=>
'myFragmentsBuilder'
,
'hl.fragmentsBuilder'
=>
'myFragmentsBuilder'
,
'hl.useFastVectorHighlighter'
=>
false
,
'hl.useFastVectorHighlighter'
=>
'false'
,
'hl.usePhraseHighlighter'
=>
true
,
'hl.usePhraseHighlighter'
=>
'true'
,
'hl.highlightMultiTerm'
=>
true
,
'hl.highlightMultiTerm'
=>
'true'
,
'hl.regex.slop'
=>
1.3
,
'hl.regex.slop'
=>
1.3
,
'hl.regex.pattern'
=>
'mypattern'
,
'hl.regex.pattern'
=>
'mypattern'
,
),
),
...
...
tests/Solarium/Client/RequestTest.php
View file @
a0b541ac
...
@@ -172,6 +172,24 @@ class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase
...
@@ -172,6 +172,24 @@ class Solarium_Client_RequestTest extends PHPUnit_Framework_TestCase
);
);
}
}
public
function
testAddParamBoolean
()
{
$params
=
array
(
'param1'
=>
true
,
'param2'
=>
false
,
);
$this
->
_request
->
addParams
(
$params
);
$this
->
assertEquals
(
array
(
'param1'
=>
'true'
,
'param2'
=>
'false'
,
),
$this
->
_request
->
getParams
()
);
}
public
function
testAddParamMultivalue
()
public
function
testAddParamMultivalue
()
{
{
$params
=
array
(
$params
=
array
(
...
...
tests/Solarium/Client/ResponseParser/Select/Component/GroupingTest.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Client_ResponseParser_Select_Component_GroupingTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Client_ResponseParser_Select_Component_Grouping
*/
protected
$_parser
;
/**
* @var Solarium_Query_Select
*/
protected
$_query
;
/**
* @var Solarium_Query_Select_Component_Grouping
*/
protected
$_grouping
;
/**
* @var Solarium_Result_Select_Grouping
*/
protected
$_result
;
public
function
setUp
()
{
$this
->
_parser
=
new
Solarium_Client_ResponseParser_Select_Component_Grouping
;
$this
->
_query
=
new
Solarium_Query_Select
();
$this
->
_grouping
=
$this
->
_query
->
getGrouping
();
$this
->
_grouping
->
addField
(
'fieldA'
);
$this
->
_grouping
->
addQuery
(
'cat:1'
);
$data
=
array
(
'grouped'
=>
array
(
'fieldA'
=>
array
(
'matches'
=>
25
,
'ngroups'
=>
12
,
'groups'
=>
array
(
array
(
'groupValue'
=>
'test value'
,
'doclist'
=>
array
(
'numFound'
=>
13
,
'docs'
=>
array
(
array
(
'id'
=>
1
,
'name'
=>
'test'
)
)
)
)
)
),
'cat:1'
=>
array
(
'matches'
=>
40
,
'doclist'
=>
array
(
'numFound'
=>
22
,
'docs'
=>
array
(
array
(
'id'
=>
2
,
'name'
=>
'dummy2'
),
array
(
'id'
=>
5
,
'name'
=>
'dummy5'
)
)
)
)
)
);
$this
->
_result
=
$this
->
_parser
->
parse
(
$this
->
_query
,
$this
->
_grouping
,
$data
);
}
public
function
testGroupParsing
()
{
$this
->
assertEquals
(
2
,
count
(
$this
->
_result
->
getGroups
()));
$fieldGroup
=
$this
->
_result
->
getGroup
(
'fieldA'
);
$queryGroup
=
$this
->
_result
->
getGroup
(
'cat:1'
);
$this
->
assertEquals
(
'Solarium_Result_Select_Grouping_FieldGroup'
,
get_class
(
$fieldGroup
));
$this
->
assertEquals
(
'Solarium_Result_Select_Grouping_QueryGroup'
,
get_class
(
$queryGroup
));
}
public
function
testFieldGroupParsing
()
{
$fieldGroup
=
$this
->
_result
->
getGroup
(
'fieldA'
);
$valueGroups
=
$fieldGroup
->
getValueGroups
();
$this
->
assertEquals
(
25
,
$fieldGroup
->
getMatches
());
$this
->
assertEquals
(
12
,
$fieldGroup
->
getNumberOfGroups
());
$this
->
assertEquals
(
1
,
count
(
$valueGroups
));
$valueGroup
=
$valueGroups
[
0
];
$this
->
assertEquals
(
13
,
$valueGroup
->
getNumFound
());
$docs
=
$valueGroup
->
getDocuments
();
$this
->
assertEquals
(
'test'
,
$docs
[
0
]
->
name
);
}
public
function
testQueryGroupParsing
()
{
$queryGroup
=
$this
->
_result
->
getGroup
(
'cat:1'
);
$this
->
assertEquals
(
40
,
$queryGroup
->
getMatches
());
$this
->
assertEquals
(
22
,
$queryGroup
->
getNumFound
());
$docs
=
$queryGroup
->
getDocuments
();
$this
->
assertEquals
(
'dummy5'
,
$docs
[
1
]
->
name
);
}
public
function
testParseNoData
()
{
$result
=
$this
->
_parser
->
parse
(
$this
->
_query
,
$this
->
_grouping
,
array
());
$this
->
assertEquals
(
array
(),
$result
->
getGroups
());
}
}
tests/Solarium/Client/ResponseParser/SelectTest.php
View file @
a0b541ac
...
@@ -76,8 +76,40 @@ class Solarium_Client_ResponseParser_SelectTest extends PHPUnit_Framework_TestCa
...
@@ -76,8 +76,40 @@ class Solarium_Client_ResponseParser_SelectTest extends PHPUnit_Framework_TestCa
Solarium_Query_Select
::
COMPONENT_FACETSET
=>
new
Solarium_Result_Select_FacetSet
(
array
())
Solarium_Query_Select
::
COMPONENT_FACETSET
=>
new
Solarium_Result_Select_FacetSet
(
array
())
);
);
$this
->
assertEquals
(
$components
,
$result
[
'components'
]);
$this
->
assertEquals
(
$components
,
$result
[
'components'
]);
}
public
function
testParseWithoutNumFound
()
{
$data
=
array
(
'response'
=>
array
(
'docs'
=>
array
(
array
(
'fieldA'
=>
1
,
'fieldB'
=>
'Test'
),
array
(
'fieldA'
=>
2
,
'fieldB'
=>
'Test2'
)
),
),
'responseHeader'
=>
array
(
'status'
=>
1
,
'QTime'
=>
13
,
)
);
$query
=
new
Solarium_Query_Select
(
array
(
'documentclass'
=>
'Solarium_Document_ReadWrite'
));
$query
->
getFacetSet
();
$resultStub
=
$this
->
getMock
(
'Solarium_Result_Select'
,
array
(),
array
(),
''
,
false
);
$resultStub
->
expects
(
$this
->
once
())
->
method
(
'getData'
)
->
will
(
$this
->
returnValue
(
$data
));
$resultStub
->
expects
(
$this
->
once
())
->
method
(
'getQuery'
)
->
will
(
$this
->
returnValue
(
$query
));
$parser
=
new
Solarium_Client_ResponseParser_Select
;
$result
=
$parser
->
parse
(
$resultStub
);
$this
->
assertEquals
(
1
,
$result
[
'status'
]);
$this
->
assertEquals
(
13
,
$result
[
'queryTime'
]);
$this
->
assertEquals
(
null
,
$result
[
'numfound'
]);
}
}
}
}
tests/Solarium/Query/HelperTest.php
View file @
a0b541ac
...
@@ -152,4 +152,49 @@ class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase
...
@@ -152,4 +152,49 @@ class Solarium_Query_HelperTest extends PHPUnit_Framework_TestCase
);
);
}
}
public
function
testAssemble
()
{
// test single basic placeholder
$this
->
assertEquals
(
'id:456 AND cat:2'
,
$this
->
_helper
->
assemble
(
'id:%1% AND cat:2'
,
array
(
456
))
);
// test multiple basic placeholders and placeholder repeat
$this
->
assertEquals
(
'(id:456 AND cat:2) OR (id:456 AND cat:1)'
,
$this
->
_helper
->
assemble
(
'(id:%1% AND cat:%2%) OR (id:%1% AND cat:%3%)'
,
array
(
456
,
2
,
1
))
);
// test literal placeholder (same as basic)
$this
->
assertEquals
(
'id:456 AND cat:2'
,
$this
->
_helper
->
assemble
(
'id:%L1% AND cat:2'
,
array
(
456
))
);
// test term placeholder
$this
->
assertEquals
(
'cat:2 AND content:a\\+b'
,
$this
->
_helper
->
assemble
(
'cat:2 AND content:%T1%'
,
array
(
'a+b'
))
);
// test term placeholder case-insensitive
$this
->
assertEquals
(
'cat:2 AND content:a\\+b'
,
$this
->
_helper
->
assemble
(
'cat:2 AND content:%t1%'
,
array
(
'a+b'
))
);
// test phrase placeholder
$this
->
assertEquals
(
'cat:2 AND content:"a+\\"b"'
,
$this
->
_helper
->
assemble
(
'cat:2 AND content:%P1%'
,
array
(
'a+"b'
))
);
}
public
function
testAssembleInvalidPartNumber
()
{
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
_helper
->
assemble
(
'cat:%1% AND content:%2%'
,
array
(
'value1'
));
}
}
}
tests/Solarium/Query/Select/Component/DisMaxTest.php
View file @
a0b541ac
...
@@ -45,6 +45,7 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
...
@@ -45,6 +45,7 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
public
function
testConfigMode
()
public
function
testConfigMode
()
{
{
$options
=
array
(
$options
=
array
(
'queryparser'
=>
'edismax'
,
'queryalternative'
=>
'*:*'
,
'queryalternative'
=>
'*:*'
,
'queryfields'
=>
'title^2.0 description'
,
'queryfields'
=>
'title^2.0 description'
,
'minimummatch'
=>
'2.0'
,
'minimummatch'
=>
'2.0'
,
...
@@ -58,6 +59,7 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
...
@@ -58,6 +59,7 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
$this
->
_disMax
->
setOptions
(
$options
);
$this
->
_disMax
->
setOptions
(
$options
);
$this
->
assertEquals
(
$options
[
'queryparser'
],
$this
->
_disMax
->
getQueryParser
());
$this
->
assertEquals
(
$options
[
'queryalternative'
],
$this
->
_disMax
->
getQueryAlternative
());
$this
->
assertEquals
(
$options
[
'queryalternative'
],
$this
->
_disMax
->
getQueryAlternative
());
$this
->
assertEquals
(
$options
[
'queryfields'
],
$this
->
_disMax
->
getQueryFields
());
$this
->
assertEquals
(
$options
[
'queryfields'
],
$this
->
_disMax
->
getQueryFields
());
$this
->
assertEquals
(
$options
[
'minimummatch'
],
$this
->
_disMax
->
getMinimumMatch
());
$this
->
assertEquals
(
$options
[
'minimummatch'
],
$this
->
_disMax
->
getMinimumMatch
());
...
@@ -77,6 +79,17 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
...
@@ -77,6 +79,17 @@ class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestC
);
);
}
}
public
function
testSetAndGetQueryParser
()
{
$value
=
'dummyparser'
;
$this
->
_disMax
->
setQueryParser
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getQueryParser
()
);
}
public
function
testSetAndGetQueryAlternative
()
public
function
testSetAndGetQueryAlternative
()
{
{
$value
=
'*:*'
;
$value
=
'*:*'
;
...
...
tests/Solarium/Query/Select/Component/Facet/QueryTest.php
View file @
a0b541ac
...
@@ -71,5 +71,9 @@ class Solarium_Query_Select_Component_Facet_QueryTest extends PHPUnit_Framework_
...
@@ -71,5 +71,9 @@ class Solarium_Query_Select_Component_Facet_QueryTest extends PHPUnit_Framework_
$this
->
assertEquals
(
'category:1'
,
$this
->
_facet
->
getQuery
());
$this
->
assertEquals
(
'category:1'
,
$this
->
_facet
->
getQuery
());
}
}
public
function
testSetAndGetQueryWithBind
()
{
$this
->
_facet
->
setQuery
(
'id:%1%'
,
array
(
678
));
$this
->
assertEquals
(
'id:678'
,
$this
->
_facet
->
getQuery
());
}
}
}
tests/Solarium/Query/Select/Component/GroupingTest.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Query_Select_Component_GroupingTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_Grouping
*/
protected
$_grouping
;
public
function
setUp
()
{
$this
->
_grouping
=
new
Solarium_Query_Select_Component_Grouping
;
}
public
function
testConfigMode
()
{
$options
=
array
(
'fields'
=>
array
(
'fieldA'
,
'fieldB'
),
'queries'
=>
array
(
'cat:3'
,
'cat:4'
),
'limit'
=>
8
,
'offset'
=>
1
,
'sort'
=>
'score desc'
,
'mainresult'
=>
false
,
'numberofgroups'
=>
true
,
'cachepercentage'
=>
45
,
);
$this
->
_grouping
->
setOptions
(
$options
);
$this
->
assertEquals
(
$options
[
'fields'
],
$this
->
_grouping
->
getFields
());
$this
->
assertEquals
(
$options
[
'queries'
],
$this
->
_grouping
->
getQueries
());
$this
->
assertEquals
(
$options
[
'limit'
],
$this
->
_grouping
->
getLimit
());
$this
->
assertEquals
(
$options
[
'offset'
],
$this
->
_grouping
->
getOffset
());
$this
->
assertEquals
(
$options
[
'sort'
],
$this
->
_grouping
->
getSort
());
$this
->
assertEquals
(
$options
[
'mainresult'
],
$this
->
_grouping
->
getMainResult
());
$this
->
assertEquals
(
$options
[
'numberofgroups'
],
$this
->
_grouping
->
getNumberOfGroups
());
$this
->
assertEquals
(
$options
[
'cachepercentage'
],
$this
->
_grouping
->
getCachePercentage
());
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select
::
COMPONENT_GROUPING
,
$this
->
_grouping
->
getType
());
}
public
function
testSetAndGetFieldsSingle
()
{
$value
=
'fieldC'
;
$this
->
_grouping
->
setFields
(
$value
);
$this
->
assertEquals
(
array
(
$value
),
$this
->
_grouping
->
getFields
()
);
}
public
function
testSetAndGetFieldsCommaSeparated
()
{
$value
=
'fieldD, fieldE'
;
$this
->
_grouping
->
setFields
(
$value
);
$this
->
assertEquals
(
array
(
'fieldD'
,
'fieldE'
,
),
$this
->
_grouping
->
getFields
()
);
}
public
function
testSetAndGetFieldsArray
()
{
$values
=
array
(
'fieldD'
,
'fieldE'
);
$this
->
_grouping
->
setFields
(
$values
);
$this
->
assertEquals
(
$values
,
$this
->
_grouping
->
getFields
()
);
}
public
function
testSetAndGetQueriesSingle
()
{
$value
=
'cat:3'
;
$this
->
_grouping
->
setQueries
(
$value
);
$this
->
assertEquals
(
array
(
$value
),
$this
->
_grouping
->
getQueries
()
);
}
public
function
testSetAndGetQueriesArray
()
{
$values
=
array
(
'cat:5'
,
'cat:6'
);
$this
->
_grouping
->
setQueries
(
$values
);
$this
->
assertEquals
(
$values
,
$this
->
_grouping
->
getQueries
()
);
}
public
function
testSetAndGetLimit
()
{
$value
=
'12'
;
$this
->
_grouping
->
setLimit
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getLimit
()
);
}
public
function
testSetAndGetOffset
()
{
$value
=
'2'
;
$this
->
_grouping
->
setOffset
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getOffset
()
);
}
public
function
testSetAndGetSort
()
{
$value
=
'price desc'
;
$this
->
_grouping
->
setSort
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getSort
()
);
}
public
function
testSetAndGetMainResult
()
{
$value
=
true
;
$this
->
_grouping
->
setMainResult
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getMainResult
()
);
}
public
function
testSetAndGetNumberOfGroups
()
{
$value
=
true
;
$this
->
_grouping
->
setNumberOfGroups
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getNumberOfGroups
()
);
}
public
function
testSetAndGetCachePercentage
()
{
$value
=
40
;
$this
->
_grouping
->
setCachePercentage
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_grouping
->
getCachePercentage
()
);
}
}
tests/Solarium/Query/Select/FilterQueryTest.php
View file @
a0b541ac
...
@@ -69,6 +69,12 @@ class Solarium_Query_Select_FilterQueryTest extends PHPUnit_Framework_TestCase
...
@@ -69,6 +69,12 @@ class Solarium_Query_Select_FilterQueryTest extends PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'category:1'
,
$this
->
_filterQuery
->
getQuery
());
$this
->
assertEquals
(
'category:1'
,
$this
->
_filterQuery
->
getQuery
());
}
}
public
function
testSetAndGetQueryWithBind
()
{
$this
->
_filterQuery
->
setQuery
(
'id:%1%'
,
array
(
678
));
$this
->
assertEquals
(
'id:678'
,
$this
->
_filterQuery
->
getQuery
());
}
public
function
testAddTag
()
public
function
testAddTag
()
{
{
$this
->
_filterQuery
->
addTag
(
'testtag'
);
$this
->
_filterQuery
->
addTag
(
'testtag'
);
...
...
tests/Solarium/Query/SelectTest.php
View file @
a0b541ac
...
@@ -56,6 +56,12 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -56,6 +56,12 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'*:*'
,
$this
->
_query
->
getQuery
());
$this
->
assertEquals
(
'*:*'
,
$this
->
_query
->
getQuery
());
}
}
public
function
testSetAndGetQueryWithBind
()
{
$this
->
_query
->
setQuery
(
'id:%1%'
,
array
(
678
));
$this
->
assertEquals
(
'id:678'
,
$this
->
_query
->
getQuery
());
}
public
function
testSetAndGetResultClass
()
public
function
testSetAndGetResultClass
()
{
{
$this
->
_query
->
setResultClass
(
'MyResult'
);
$this
->
_query
->
setResultClass
(
'MyResult'
);
...
@@ -471,11 +477,21 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -471,11 +477,21 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
public
function
testGetHighlighting
()
public
function
testGetHighlighting
()
{
{
$
dismax
=
$this
->
_query
->
getHighlighting
();
$
hlt
=
$this
->
_query
->
getHighlighting
();
$this
->
assertEquals
(
$this
->
assertEquals
(
'Solarium_Query_Select_Component_Highlighting'
,
'Solarium_Query_Select_Component_Highlighting'
,
get_class
(
$dismax
)
get_class
(
$hlt
)
);
}
public
function
testGetGrouping
()
{
$grouping
=
$this
->
_query
->
getGrouping
();
$this
->
assertEquals
(
'Solarium_Query_Select_Component_Grouping'
,
get_class
(
$grouping
)
);
);
}
}
...
...
tests/Solarium/Query/UpdateTest.php
View file @
a0b541ac
...
@@ -402,4 +402,48 @@ class Solarium_Query_UpdateTest extends PHPUnit_Framework_TestCase
...
@@ -402,4 +402,48 @@ class Solarium_Query_UpdateTest extends PHPUnit_Framework_TestCase
$this
->
_query
->
createCommand
(
'invalidtype'
);
$this
->
_query
->
createCommand
(
'invalidtype'
);
}
}
public
function
testSetAndGetDocumentClass
()
{
$this
->
_query
->
setDocumentClass
(
'MyDocument'
);
$this
->
assertEquals
(
'MyDocument'
,
$this
->
_query
->
getDocumentClass
());
}
public
function
testCreateDocument
()
{
$doc
=
$this
->
_query
->
createDocument
();
$this
->
assertThat
(
$doc
,
$this
->
isInstanceOf
(
$this
->
_query
->
getDocumentClass
()));
}
public
function
testCreateDocumentWithCustomClass
()
{
$this
->
_query
->
setDocumentClass
(
'MyCustomDoc'
);
$doc
=
$this
->
_query
->
createDocument
();
$this
->
assertThat
(
$doc
,
$this
->
isInstanceOf
(
'MyCustomDoc'
));
}
public
function
testCreateDocumentWithFieldsAndBoosts
()
{
$fields
=
array
(
'id'
=>
1
,
'name'
=>
'testname'
);
$boosts
=
array
(
'name'
=>
2.7
);
$doc
=
$this
->
_query
->
createDocument
(
$fields
,
$boosts
);
$this
->
assertThat
(
$doc
,
$this
->
isInstanceOf
(
$this
->
_query
->
getDocumentClass
()));
$this
->
assertEquals
(
$fields
,
$doc
->
getFields
()
);
$this
->
assertEquals
(
2.7
,
$doc
->
getFieldBoost
(
'name'
)
);
}
}
class
MyCustomDoc
extends
Solarium_Document_ReadWrite
{
}
}
tests/Solarium/Result/Select/Grouping/FieldGroupTest.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Result_Select_Grouping_FieldGroupTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Grouping_FieldGroup
*/
protected
$_group
;
protected
$_matches
,
$_numberOfGroups
,
$_items
;
public
function
setUp
()
{
$this
->
_matches
=
12
;
$this
->
_numberOfGroups
=
6
;
$this
->
_items
=
array
(
'key1'
=>
'content1'
,
'key2'
=>
'content2'
,
);
$this
->
_group
=
new
Solarium_Result_Select_Grouping_FieldGroup
(
$this
->
_matches
,
$this
->
_numberOfGroups
,
$this
->
_items
);
}
public
function
testGetMatches
()
{
$this
->
assertEquals
(
$this
->
_matches
,
$this
->
_group
->
getMatches
()
);
}
public
function
testGetNumberOfGroups
()
{
$this
->
assertEquals
(
$this
->
_numberOfGroups
,
$this
->
_group
->
getNumberOfGroups
()
);
}
public
function
testIterator
()
{
$items
=
array
();
foreach
(
$this
->
_group
AS
$key
=>
$item
)
{
$items
[
$key
]
=
$item
;
}
$this
->
assertEquals
(
$this
->
_items
,
$items
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_items
),
count
(
$this
->
_group
));
}
}
tests/Solarium/Result/Select/Grouping/QueryGroupTest.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Result_Select_Grouping_QueryGroupTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Grouping_QueryGroup
*/
protected
$_group
;
protected
$_matches
,
$_numFound
,
$_start
,
$_maximumScore
,
$_items
;
public
function
setUp
()
{
$this
->
_matches
=
12
;
$this
->
_numFound
=
6
;
$this
->
_start
=
2
;
$this
->
_maximumScore
=
0.89
;
$this
->
_items
=
array
(
'key1'
=>
'content1'
,
'key2'
=>
'content2'
,
);
$this
->
_group
=
new
Solarium_Result_Select_Grouping_QueryGroup
(
$this
->
_matches
,
$this
->
_numFound
,
$this
->
_start
,
$this
->
_maximumScore
,
$this
->
_items
);
}
public
function
testGetMatches
()
{
$this
->
assertEquals
(
$this
->
_matches
,
$this
->
_group
->
getMatches
()
);
}
public
function
testGetNumFound
()
{
$this
->
assertEquals
(
$this
->
_numFound
,
$this
->
_group
->
getNumFound
()
);
}
public
function
testGetStart
()
{
$this
->
assertEquals
(
$this
->
_start
,
$this
->
_group
->
getStart
()
);
}
public
function
testGetMaximumScore
()
{
$this
->
assertEquals
(
$this
->
_maximumScore
,
$this
->
_group
->
getMaximumScore
()
);
}
public
function
testGetDocuments
()
{
$this
->
assertEquals
(
$this
->
_items
,
$this
->
_group
->
getDocuments
()
);
}
public
function
testIterator
()
{
$items
=
array
();
foreach
(
$this
->
_group
AS
$key
=>
$item
)
{
$items
[
$key
]
=
$item
;
}
$this
->
assertEquals
(
$this
->
_items
,
$items
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_items
),
count
(
$this
->
_group
));
}
}
tests/Solarium/Result/Select/Grouping/ValueGroupTest.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Result_Select_Grouping_ValueGroupTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Grouping_ValueGroup
*/
protected
$_group
;
protected
$_value
,
$_numFound
,
$_start
,
$_items
;
public
function
setUp
()
{
$this
->
_value
=
'test value'
;
$this
->
_numFound
=
6
;
$this
->
_start
=
2
;
$this
->
_items
=
array
(
'key1'
=>
'content1'
,
'key2'
=>
'content2'
,
);
$this
->
_group
=
new
Solarium_Result_Select_Grouping_ValueGroup
(
$this
->
_value
,
$this
->
_numFound
,
$this
->
_start
,
$this
->
_items
);
}
public
function
testGetValue
()
{
$this
->
assertEquals
(
$this
->
_value
,
$this
->
_group
->
getValue
()
);
}
public
function
testGetNumFound
()
{
$this
->
assertEquals
(
$this
->
_numFound
,
$this
->
_group
->
getNumFound
()
);
}
public
function
testGetStart
()
{
$this
->
assertEquals
(
$this
->
_start
,
$this
->
_group
->
getStart
()
);
}
public
function
testGetDocuments
()
{
$this
->
assertEquals
(
$this
->
_items
,
$this
->
_group
->
getDocuments
()
);
}
public
function
testIterator
()
{
$items
=
array
();
foreach
(
$this
->
_group
AS
$key
=>
$item
)
{
$items
[
$key
]
=
$item
;
}
$this
->
assertEquals
(
$this
->
_items
,
$items
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_items
),
count
(
$this
->
_group
));
}
}
tests/Solarium/Result/Select/GroupingTest.php
0 → 100644
View file @
a0b541ac
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Result_Select_GroupingTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Grouping
*/
protected
$_grouping
;
protected
$_items
;
public
function
setUp
()
{
$this
->
_items
=
array
(
'key1'
=>
'content1'
,
'key2'
=>
'content2'
,
);
$this
->
_grouping
=
new
Solarium_Result_Select_Grouping
(
$this
->
_items
);
}
public
function
testGetGroups
()
{
$this
->
assertEquals
(
$this
->
_items
,
$this
->
_grouping
->
getGroups
()
);
}
public
function
testGetGroup
()
{
$this
->
assertEquals
(
$this
->
_items
[
'key1'
],
$this
->
_grouping
->
getGroup
(
'key1'
)
);
}
public
function
testGetGroupInvalid
()
{
$this
->
assertEquals
(
null
,
$this
->
_grouping
->
getGroup
(
'invalidkey'
)
);
}
public
function
testIterator
()
{
$items
=
array
();
foreach
(
$this
->
_grouping
AS
$key
=>
$item
)
{
$items
[
$key
]
=
$item
;
}
$this
->
assertEquals
(
$this
->
_items
,
$items
);
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_items
),
count
(
$this
->
_grouping
));
}
}
tests/Solarium/Result/SelectTest.php
View file @
a0b541ac
...
@@ -37,7 +37,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -37,7 +37,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
*/
*/
protected
$_result
;
protected
$_result
;
protected
$_numFound
,
$_docs
,
$_components
,
$_facetSet
,
$_moreLikeThis
,
$_highlighting
;
protected
$_numFound
,
$_docs
,
$_components
,
$_facetSet
,
$_moreLikeThis
,
$_highlighting
,
$_grouping
;
public
function
setUp
()
public
function
setUp
()
{
{
...
@@ -51,11 +51,13 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -51,11 +51,13 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
$this
->
_facetSet
=
'dummy-facetset-value'
;
$this
->
_facetSet
=
'dummy-facetset-value'
;
$this
->
_moreLikeThis
=
'dummy-facetset-value'
;
$this
->
_moreLikeThis
=
'dummy-facetset-value'
;
$this
->
_highlighting
=
'dummy-highlighting-value'
;
$this
->
_highlighting
=
'dummy-highlighting-value'
;
$this
->
_grouping
=
'dummy-grouping-value'
;
$this
->
_components
=
array
(
$this
->
_components
=
array
(
Solarium_Query_Select
::
COMPONENT_FACETSET
=>
$this
->
_facetSet
,
Solarium_Query_Select
::
COMPONENT_FACETSET
=>
$this
->
_facetSet
,
Solarium_Query_Select
::
COMPONENT_MORELIKETHIS
=>
$this
->
_moreLikeThis
,
Solarium_Query_Select
::
COMPONENT_MORELIKETHIS
=>
$this
->
_moreLikeThis
,
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
=>
$this
->
_highlighting
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
=>
$this
->
_highlighting
,
Solarium_Query_Select
::
COMPONENT_GROUPING
=>
$this
->
_grouping
);
);
$this
->
_result
=
new
Solarium_Result_SelectDummy
(
1
,
12
,
$this
->
_numFound
,
$this
->
_docs
,
$this
->
_components
);
$this
->
_result
=
new
Solarium_Result_SelectDummy
(
1
,
12
,
$this
->
_numFound
,
$this
->
_docs
,
$this
->
_components
);
...
@@ -118,6 +120,14 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -118,6 +120,14 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
);
);
}
}
public
function
testGetGrouping
()
{
$this
->
assertEquals
(
$this
->
_components
[
Solarium_Query_Select
::
COMPONENT_GROUPING
],
$this
->
_result
->
getGrouping
()
);
}
public
function
testIterator
()
public
function
testIterator
()
{
{
$docs
=
array
();
$docs
=
array
();
...
...
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