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
88b116ab
Commit
88b116ab
authored
Jul 22, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added grouping component
- added examples for grouping component
parent
a71f798c
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
1220 additions
and
1 deletion
+1220
-1
examples/2.5.5-grouping-by-field.php
examples/2.5.5-grouping-by-field.php
+53
-0
examples/2.5.6-grouping-by-query.php
examples/2.5.6-grouping-by-query.php
+45
-0
examples/index.html
examples/index.html
+2
-0
library/Solarium/Client/Request.php
library/Solarium/Client/Request.php
+4
-0
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/Query/Select.php
library/Solarium/Query/Select.php
+18
-0
library/Solarium/Query/Select/Component/Grouping.php
library/Solarium/Query/Select/Component/Grouping.php
+348
-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
+95
-0
library/Solarium/Result/Select/Grouping/FieldGroup.php
library/Solarium/Result/Select/Grouping/FieldGroup.php
+135
-0
library/Solarium/Result/Select/Grouping/QueryGroup.php
library/Solarium/Result/Select/Grouping/QueryGroup.php
+167
-0
library/Solarium/Result/Select/Grouping/ValueGroup.php
library/Solarium/Result/Select/Grouping/ValueGroup.php
+142
-0
No files found.
examples/2.5.5-grouping-by-field.php
0 → 100644
View file @
88b116ab
<?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.6-grouping-by-query.php
0 → 100644
View file @
88b116ab
<?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/index.html
View file @
88b116ab
...
...
@@ -43,6 +43,8 @@
<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.4-dismax.php"
>
2.5.4 Dismax
</a></li>
<li><a
href=
"2.5.5-grouping-by-field.php"
>
2.5.5 Grouping by field
</a></li>
<li><a
href=
"2.5.6-grouping-by-query.php"
>
2.5.6 Grouping by query
</a></li>
</ul>
<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>
...
...
library/Solarium/Client/Request.php
View file @
88b116ab
...
...
@@ -210,6 +210,10 @@ class Solarium_Client_Request extends Solarium_Configurable
}
$this
->
_params
[
$key
][]
=
$value
;
}
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
;
}
}
...
...
library/Solarium/Client/RequestBuilder/Select/Component/Grouping.php
0 → 100644
View file @
88b116ab
<?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 @
88b116ab
...
...
@@ -76,11 +76,17 @@ class Solarium_Client_ResponseParser_Select extends Solarium_Client_ResponsePars
$components
[
$component
->
getType
()]
=
$componentParser
->
parse
(
$query
,
$component
,
$data
);
}
}
if
(
isset
(
$data
[
'response'
][
'numFound'
]))
{
$numFound
=
$data
[
'response'
][
'numFound'
];
}
else
{
$numFound
=
null
;
}
return
array
(
'status'
=>
$data
[
'responseHeader'
][
'status'
],
'queryTime'
=>
$data
[
'responseHeader'
][
'QTime'
],
'numfound'
=>
$
data
[
'response'
][
'numFound'
]
,
'numfound'
=>
$
numFound
,
'documents'
=>
$documents
,
'components'
=>
$components
,
);
...
...
library/Solarium/Client/ResponseParser/Select/Component/Grouping.php
0 → 100644
View file @
88b116ab
<?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/Query/Select.php
View file @
88b116ab
...
...
@@ -62,6 +62,7 @@ class Solarium_Query_Select extends Solarium_Query
const
COMPONENT_DISMAX
=
'dismax'
;
const
COMPONENT_MORELIKETHIS
=
'morelikethis'
;
const
COMPONENT_HIGHLIGHTING
=
'highlighting'
;
const
COMPONENT_GROUPING
=
'grouping'
;
/**
* Get type for this query
...
...
@@ -114,6 +115,11 @@ class Solarium_Query_Select extends Solarium_Query
'requestbuilder'
=>
'Solarium_Client_RequestBuilder_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'
,
),
);
/**
...
...
@@ -755,4 +761,16 @@ class Solarium_Query_Select extends Solarium_Query
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/Grouping.php
0 → 100644
View file @
88b116ab
<?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
*
* @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
();
/**
* 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
*
* @param array $fields
* @return Solarium_Field_Select_Component_Grouping Provides fluent interface
*/
public
function
addFields
(
$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 $queries
* @return Solarium_Query_Select_Component_Grouping Provides fluent interface
*/
public
function
addQueries
(
$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/Result/Select.php
View file @
88b116ab
...
...
@@ -234,6 +234,18 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
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
*
...
...
library/Solarium/Result/Select/Grouping.php
0 → 100644
View file @
88b116ab
<?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
*
* @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
;
}
/**
* 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 @
88b116ab
<?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
*
* @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 @
88b116ab
<?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
*
* @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 @
88b116ab
<?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
*
* @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
;
}
/**
* 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
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