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
aca37f29
Commit
aca37f29
authored
Apr 21, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/facet-improvements' into develop
parents
31dc7f69
114f3b2c
Changes
27
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
2703 additions
and
345 deletions
+2703
-345
library/Solarium/Client/Request/Select.php
library/Solarium/Client/Request/Select.php
+104
-8
library/Solarium/Client/Response/Select.php
library/Solarium/Client/Response/Select.php
+75
-16
library/Solarium/Query/Select.php
library/Solarium/Query/Select.php
+61
-127
library/Solarium/Query/Select/Component.php
library/Solarium/Query/Select/Component.php
+2
-0
library/Solarium/Query/Select/Component/DisMax.php
library/Solarium/Query/Select/Component/DisMax.php
+278
-0
library/Solarium/Query/Select/Component/Facet.php
library/Solarium/Query/Select/Component/Facet.php
+8
-5
library/Solarium/Query/Select/Component/Facet/Field.php
library/Solarium/Query/Select/Component/Facet/Field.php
+8
-8
library/Solarium/Query/Select/Component/Facet/MultiQuery.php
library/Solarium/Query/Select/Component/Facet/MultiQuery.php
+292
-0
library/Solarium/Query/Select/Component/Facet/Query.php
library/Solarium/Query/Select/Component/Facet/Query.php
+1
-1
library/Solarium/Query/Select/Component/Facet/Range.php
library/Solarium/Query/Select/Component/Facet/Range.php
+270
-0
library/Solarium/Query/Select/Component/FacetSet.php
library/Solarium/Query/Select/Component/FacetSet.php
+331
-0
library/Solarium/Query/Select/Component/MoreLikeThis.php
library/Solarium/Query/Select/Component/MoreLikeThis.php
+1
-20
library/Solarium/Result/Select/Facet/MultiQuery.php
library/Solarium/Result/Select/Facet/MultiQuery.php
+51
-0
library/Solarium/Result/Select/Facet/Range.php
library/Solarium/Result/Select/Facet/Range.php
+128
-0
tests/Solarium/Client/Request/SelectTest.php
tests/Solarium/Client/Request/SelectTest.php
+53
-5
tests/Solarium/Query/Select/Component/DisMaxTest.php
tests/Solarium/Query/Select/Component/DisMaxTest.php
+152
-0
tests/Solarium/Query/Select/Component/Facet/FieldTest.php
tests/Solarium/Query/Select/Component/Facet/FieldTest.php
+3
-3
tests/Solarium/Query/Select/Component/Facet/MultiQueryTest.php
.../Solarium/Query/Select/Component/Facet/MultiQueryTest.php
+349
-0
tests/Solarium/Query/Select/Component/Facet/QueryTest.php
tests/Solarium/Query/Select/Component/Facet/QueryTest.php
+3
-3
tests/Solarium/Query/Select/Component/Facet/RangeTest.php
tests/Solarium/Query/Select/Component/Facet/RangeTest.php
+104
-0
tests/Solarium/Query/Select/Component/FacetSetTest.php
tests/Solarium/Query/Select/Component/FacetSetTest.php
+233
-0
tests/Solarium/Query/Select/Component/FacetTest.php
tests/Solarium/Query/Select/Component/FacetTest.php
+2
-2
tests/Solarium/Query/Select/Component/MoreLikeThisTest.php
tests/Solarium/Query/Select/Component/MoreLikeThisTest.php
+6
-1
tests/Solarium/Query/SelectTest.php
tests/Solarium/Query/SelectTest.php
+25
-146
tests/Solarium/Result/Select/Facet/MultiQueryTest.php
tests/Solarium/Result/Select/Facet/MultiQueryTest.php
+68
-0
tests/Solarium/Result/Select/Facet/RangeTest.php
tests/Solarium/Result/Select/Facet/RangeTest.php
+92
-0
tests/bootstrap.php
tests/bootstrap.php
+3
-0
No files found.
library/Solarium/Client/Request/Select.php
View file @
aca37f29
...
...
@@ -87,39 +87,66 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
case
Solarium_Query_Select_Component
::
MORELIKETHIS
:
$this
->
addMoreLikeThis
(
$component
);
break
;
case
Solarium_Query_Select_Component
::
FACETSET
:
$this
->
addFacetSet
(
$component
);
break
;
case
Solarium_Query_Select_Component
::
DISMAX
:
$this
->
addDisMax
(
$component
);
break
;
default
:
throw
new
Solarium_Exception
(
'Unknown component type'
);
}
}
$facets
=
$this
->
_query
->
getFacets
();
return
$this
->
buildUri
();
}
/**
* @throws Solarium_Exception
* @param Solarium_Query_Select_Component_FacetSet $facetSet
* @return void
*/
public
function
addFacetSet
(
$facetSet
)
{
$facets
=
$facetSet
->
getFacets
();
if
(
count
(
$facets
)
!==
0
)
{
// enable faceting
$this
->
_params
[
'facet'
]
=
'true'
;
// global facet params
$this
->
addParam
(
'facet.sort'
,
$facetSet
->
getSort
());
$this
->
addParam
(
'facet.prefix'
,
$facetSet
->
getPrefix
());
$this
->
addParam
(
'facet.missing'
,
$facetSet
->
getMissing
());
$this
->
addParam
(
'facet.mincount'
,
$facetSet
->
getMinCount
());
$this
->
addParam
(
'facet.limit'
,
$facetSet
->
getLimit
());
foreach
(
$facets
AS
$facet
)
{
switch
(
$facet
->
getType
())
{
case
Solarium_Query_Select_Facet
::
FIELD
:
case
Solarium_Query_Select_
Component_
Facet
::
FIELD
:
$this
->
addFacetField
(
$facet
);
break
;
case
Solarium_Query_Select_Facet
::
QUERY
:
case
Solarium_Query_Select_
Component_
Facet
::
QUERY
:
$this
->
addFacetQuery
(
$facet
);
break
;
case
Solarium_Query_Select_Component_Facet
::
MULTIQUERY
:
$this
->
addFacetMultiQuery
(
$facet
);
break
;
case
Solarium_Query_Select_Component_Facet
::
RANGE
:
$this
->
addFacetRange
(
$facet
);
break
;
default
:
throw
new
Solarium_Exception
(
'Unknown facet type'
);
}
}
}
return
$this
->
buildUri
();
}
/**
* Add params for a field facet to request
*
* @param
mixe
d $facet
* @param
Solarium_Query_Select_Component_Facet_Fiel
d $facet
* @return void
*/
public
function
addFacetField
(
$facet
)
...
...
@@ -144,9 +171,9 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
}
/**
* Add params for a f
ield
query to request
* Add params for a f
acet
query to request
*
* @param
mixed
$facet
* @param
Solarium_Query_Select_Component_Facet_Query
$facet
* @return void
*/
public
function
addFacetQuery
(
$facet
)
...
...
@@ -160,6 +187,53 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
);
}
/**
* Add params for a multiquery facet to request
*
* @param Solarium_Query_Select_Component_Facet_MultiQuery $facet
* @return void
*/
public
function
addFacetMultiQuery
(
$facet
)
{
foreach
(
$facet
->
getQueries
()
AS
$facetQuery
)
{
$this
->
addFacetQuery
(
$facetQuery
);
}
}
/**
* Add params for a range facet to request
*
* @param Solarium_Query_Select_Component_Facet_Range $facet
* @return void
*/
public
function
addFacetRange
(
$facet
)
{
$field
=
$facet
->
getField
();
$this
->
addParam
(
'facet.range'
,
$this
->
renderLocalParams
(
$field
,
array
(
'key'
=>
$facet
->
getKey
(),
'ex'
=>
$facet
->
getExcludes
())
)
);
$this
->
addParam
(
"f.
$field
.facet.range.start"
,
$facet
->
getStart
());
$this
->
addParam
(
"f.
$field
.facet.range.end"
,
$facet
->
getEnd
());
$this
->
addParam
(
"f.
$field
.facet.range.gap"
,
$facet
->
getGap
());
$this
->
addParam
(
"f.
$field
.facet.range.hardend"
,
$facet
->
getHardend
());
$other
=
explode
(
','
,
$facet
->
getOther
());
foreach
(
$other
AS
$otherValue
)
{
$this
->
addParam
(
"f.
$field
.facet.range.other"
,
trim
(
$otherValue
));
}
$include
=
explode
(
','
,
$facet
->
getInclude
());
foreach
(
$include
AS
$includeValue
)
{
$this
->
addParam
(
"f.
$field
.facet.range.include"
,
trim
(
$includeValue
));
}
}
/**
* Add params for morelikethis
*
...
...
@@ -183,4 +257,26 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
$this
->
addParam
(
'mlt.count'
,
$component
->
getCount
());
}
/**
* Add params for DisMax
*
* @param Solarium_Query_Select_Component_DisMax $component
* @return void
*/
public
function
addDisMax
(
$component
)
{
// enable dismax
$this
->
_params
[
'defType'
]
=
'dismax'
;
$this
->
addParam
(
'q.alt'
,
$component
->
getQueryAlternative
());
$this
->
addParam
(
'qf'
,
$component
->
getQueryFields
());
$this
->
addParam
(
'mm'
,
$component
->
getMinimumMatch
());
$this
->
addParam
(
'pf'
,
$component
->
getPhraseFields
());
$this
->
addParam
(
'ps'
,
$component
->
getPhraseSlop
());
$this
->
addParam
(
'qs'
,
$component
->
getQueryPhraseSlop
());
$this
->
addParam
(
'tie'
,
$component
->
getTie
());
$this
->
addParam
(
'bq'
,
$component
->
getBoostQuery
());
$this
->
addParam
(
'bf'
,
$component
->
getBoostFunctions
());
}
}
\ No newline at end of file
library/Solarium/Client/Response/Select.php
View file @
aca37f29
...
...
@@ -89,22 +89,14 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
case
Solarium_Query_Select_Component
::
MORELIKETHIS
:
$this
->
_addMoreLikeThis
(
$component
);
break
;
default
:
throw
new
Solarium_Exception
(
'Unknown component type'
);
}
}
// create facet results
foreach
(
$this
->
_query
->
getFacets
()
AS
$facet
)
{
switch
(
$facet
->
getType
())
{
case
Solarium_Query_Select_Facet
::
FIELD
:
$this
->
_addFacetField
(
$facet
);
case
Solarium_Query_Select_Component
::
FACETSET
:
$this
->
_addFacetSet
(
$component
);
break
;
case
Solarium_Query_Select_
Facet
::
QUERY
:
$this
->
_addFacetQuery
(
$facet
);
case
Solarium_Query_Select_
Component
::
DISMAX
:
// no result action needed
break
;
default
:
throw
new
Solarium_Exception
(
'Unknown
face
t type'
);
throw
new
Solarium_Exception
(
'Unknown
componen
t type'
);
}
}
...
...
@@ -120,10 +112,33 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
);
}
protected
function
_addFacetSet
(
$facetSet
)
{
// create facet results
foreach
(
$facetSet
->
getFacets
()
AS
$facet
)
{
switch
(
$facet
->
getType
())
{
case
Solarium_Query_Select_Component_Facet
::
FIELD
:
$this
->
_addFacetField
(
$facet
);
break
;
case
Solarium_Query_Select_Component_Facet
::
QUERY
:
$this
->
_addFacetQuery
(
$facet
);
break
;
case
Solarium_Query_Select_Component_Facet
::
MULTIQUERY
:
$this
->
_addFacetMultiQuery
(
$facet
);
break
;
case
Solarium_Query_Select_Component_Facet
::
RANGE
:
$this
->
_addFacetRange
(
$facet
);
break
;
default
:
throw
new
Solarium_Exception
(
'Unknown facet type'
);
}
}
}
/**
* Add a facet result for a field facet
*
* @param
mixe
d $facet
* @param
Solarium_Query_Select_Component_Facet_Fiel
d $facet
* @return void
*/
protected
function
_addFacetField
(
$facet
)
...
...
@@ -147,9 +162,9 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
}
/**
* Add a facet result for a f
ield
query
* Add a facet result for a f
acet
query
*
* @param
mixed
$facet
* @param
Solarium_Query_Select_Component_Facet_Query
$facet
* @return void
*/
protected
function
_addFacetQuery
(
$facet
)
...
...
@@ -163,6 +178,50 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
}
}
/**
* Add a facet result for a multiquery facet
*
* @param Solarium_Query_Select_Component_Facet_MultiQuery $facet
* @return void
*/
protected
function
_addFacetMultiQuery
(
$facet
)
{
$values
=
array
();
foreach
(
$facet
->
getQueries
()
AS
$query
)
{
$key
=
$query
->
getKey
();
if
(
isset
(
$this
->
_data
[
'facet_counts'
][
'facet_queries'
][
$key
]))
{
$count
=
$this
->
_data
[
'facet_counts'
][
'facet_queries'
][
$key
];
$values
[
$key
]
=
$count
;
}
}
$this
->
_facets
[
$facet
->
getKey
()]
=
new
Solarium_Result_Select_Facet_MultiQuery
(
$values
);
}
/**
* Add a facet result for a range facet
*
* @param Solarium_Query_Select_Component_Facet_Range $facet
* @return void
*/
protected
function
_addFacetRange
(
$facet
)
{
$key
=
$facet
->
getKey
();
if
(
isset
(
$this
->
_data
[
'facet_counts'
][
'facet_ranges'
][
$key
]))
{
$data
=
$this
->
_data
[
'facet_counts'
][
'facet_ranges'
][
$key
];
$before
=
(
isset
(
$data
[
'before'
]))
?
$data
[
'before'
]
:
null
;
$after
=
(
isset
(
$data
[
'after'
]))
?
$data
[
'after'
]
:
null
;
$between
=
(
isset
(
$data
[
'after'
]))
?
$data
[
'after'
]
:
null
;
$this
->
_facets
[
$key
]
=
new
Solarium_Result_Select_Facet_Range
(
$data
[
'counts'
],
$before
,
$after
,
$between
);
}
}
/**
* Add morelikethis result
*
...
...
library/Solarium/Query/Select.php
View file @
aca37f29
...
...
@@ -90,13 +90,6 @@ class Solarium_Query_Select extends Solarium_Query
*/
protected
$_filterQueries
=
array
();
/**
* Facets
*
* @var array
*/
protected
$_facets
=
array
();
/**
* Search components
*
...
...
@@ -122,9 +115,6 @@ class Solarium_Query_Select extends Solarium_Query
case
'filterquery'
:
$this
->
addFilterQueries
(
$value
);
break
;
case
'facet'
:
$this
->
addFacets
(
$value
);
break
;
case
'sort'
:
$this
->
addSortFields
(
$value
);
break
;
...
...
@@ -137,6 +127,9 @@ class Solarium_Query_Select extends Solarium_Query
case
'start'
:
$this
->
setStart
((
int
)
$value
);
break
;
case
'component'
:
$this
->
_createComponents
(
$value
);
break
;
}
}
}
...
...
@@ -537,119 +530,6 @@ class Solarium_Query_Select extends Solarium_Query
$this
->
addFilterQueries
(
$filterQueries
);
}
/**
* Add a facet
*
* @param Solarium_Query_Select_Facet|array $facet
* @return Solarium_Query Provides fluent interface
*/
public
function
addFacet
(
$facet
)
{
if
(
is_array
(
$facet
))
{
$className
=
'Solarium_Query_Select_Facet_'
.
ucfirst
(
$facet
[
'type'
]);
$facet
=
new
$className
(
$facet
);
}
$key
=
$facet
->
getKey
();
if
(
0
===
strlen
(
$key
))
{
throw
new
Solarium_Exception
(
'A facet must have a key value'
);
}
if
(
array_key_exists
(
$key
,
$this
->
_facets
))
{
throw
new
Solarium_Exception
(
'A facet must have a unique key value'
.
' within a query'
);
}
$this
->
_facets
[
$key
]
=
$facet
;
return
$this
;
}
/**
* Add multiple facets
*
* @param array $facets
* @return Solarium_Query Provides fluent interface
*/
public
function
addFacets
(
array
$facets
)
{
foreach
(
$facets
AS
$key
=>
$facet
)
{
// in case of a config array: add key to config
if
(
is_array
(
$facet
)
&&
!
isset
(
$facet
[
'key'
]))
{
$facet
[
'key'
]
=
$key
;
}
$this
->
addFacet
(
$facet
);
}
return
$this
;
}
/**
* Get a facet
*
* @param string $key
* @return string
*/
public
function
getFacet
(
$key
)
{
if
(
isset
(
$this
->
_facets
[
$key
]))
{
return
$this
->
_facets
[
$key
];
}
else
{
return
null
;
}
}
/**
* Get all facets
*
* @return array
*/
public
function
getFacets
()
{
return
$this
->
_facets
;
}
/**
* Remove a single facet by key
*
* @param string $key
* @return Solarium_Query Provides fluent interface
*/
public
function
removeFacet
(
$key
)
{
if
(
isset
(
$this
->
_facets
[
$key
]))
{
unset
(
$this
->
_facets
[
$key
]);
}
return
$this
;
}
/**
* Remove all facets
*
* @return Solarium_Query Provides fluent interface
*/
public
function
clearFacets
()
{
$this
->
_facets
=
array
();
return
$this
;
}
/**
* Set multiple facets
*
* This overwrites any existing facets
*
* @param array $facets
*/
public
function
setFacets
(
$facets
)
{
$this
->
clearFacets
();
$this
->
addFacets
(
$facets
);
}
/**
* Get all registered components
*
...
...
@@ -668,15 +548,31 @@ class Solarium_Query_Select extends Solarium_Query
*
* @param string $key Use one of the constants
* @param string $autoload Class to autoload if component needs to be created
* @param array $config Configuration to use for autoload
* @return object|null
*/
public
function
getComponent
(
$key
,
$autoload
=
null
)
public
function
getComponent
(
$key
,
$autoload
=
false
,
$config
=
null
)
{
if
(
isset
(
$this
->
_components
[
$key
]))
{
return
$this
->
_components
[
$key
];
}
else
{
if
(
$autoload
!==
null
)
{
$component
=
new
$autoload
;
if
(
$autoload
==
true
)
{
switch
(
$key
)
{
case
Solarium_Query_Select_Component
::
MORELIKETHIS
:
$className
=
'Solarium_Query_Select_Component_MoreLikeThis'
;
break
;
case
Solarium_Query_Select_Component
::
FACETSET
:
$className
=
'Solarium_Query_Select_Component_FacetSet'
;
break
;
case
Solarium_Query_Select_Component
::
DISMAX
:
$className
=
'Solarium_Query_Select_Component_DisMax'
;
break
;
default
:
throw
new
Solarium_Exception
(
'Cannot autoload unknown component: '
.
$key
);
}
$component
=
new
$className
(
$config
);
$this
->
setComponent
(
$key
,
$component
);
return
$this
->
_components
[
$key
];
}
...
...
@@ -713,6 +609,20 @@ class Solarium_Query_Select extends Solarium_Query
return
$this
;
}
/**
* Build component instances based on config
*
* @param array $configs
* @return void
*/
protected
function
_createComponents
(
$configs
)
{
foreach
(
$configs
AS
$type
=>
$config
)
{
$this
->
getComponent
(
$type
,
true
,
$config
);
}
}
/**
* Get a MoreLikeThis component instance
*
...
...
@@ -722,7 +632,31 @@ class Solarium_Query_Select extends Solarium_Query
*/
public
function
getMoreLikeThis
()
{
return
$this
->
getComponent
(
'MoreLikeThis'
,
'Solarium_Query_Select_Component_MoreLikeThis'
);
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
MORELIKETHIS
,
true
);
}
/**
* Get a FacetSet component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_FacetSet
*/
public
function
getFacetSet
()
{
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
FACETSET
,
true
);
}
/**
* Get a DisMax component instance
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Query_Select_Component_DisMax
*/
public
function
getDisMax
()
{
return
$this
->
getComponent
(
Solarium_Query_Select_Component
::
DISMAX
,
true
);
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component.php
View file @
aca37f29
...
...
@@ -48,6 +48,8 @@ class Solarium_Query_Select_Component extends Solarium_Configurable
* Component types
*/
const
MORELIKETHIS
=
'morelikethis'
;
const
FACETSET
=
'facetset'
;
const
DISMAX
=
'dismax'
;
/**
* Component type
...
...
library/Solarium/Query/Select/Component/DisMax.php
0 → 100644
View file @
aca37f29
<?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
*
* @package Solarium
* @subpackage Query
*/
/**
* DisMax component
*
* @link http://wiki.apache.org/solr/DisMaxQParserPlugin
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Component_DisMax
extends
Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
protected
$_type
=
self
::
DISMAX
;
/**
* Set QueryAlternative option
*
* If specified, this query will be used (and parsed by default using
* standard query parsing syntax) when the main query string is not
* specified or blank.
*
* @param string $queryAlternative
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public
function
setQueryAlternative
(
$queryAlternative
)
{
return
$this
->
_setOption
(
'queryalternative'
,
$queryAlternative
);
}
/**
* Get QueryAlternative option
*
* @return string|null
*/
public
function
getQueryAlternative
()
{
return
$this
->
getOption
(
'queryalternative'
);
}
/**
* Set QueryFields option
*
* List of fields and the "boosts" to associate with each of them when
* building DisjunctionMaxQueries from the user's query.
*
* The format supported is "fieldOne^2.3 fieldTwo fieldThree^0.4"
*
* @param string $queryFields
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public
function
setQueryFields
(
$queryFields
)
{
return
$this
->
_setOption
(
'queryfields'
,
$queryFields
);
}
/**
* Get QueryFields option
*
* @return string|null
*/
public
function
getQueryFields
()
{
return
$this
->
getOption
(
'queryfields'
);
}
/**
* Set MinimumMatch option
*
* This option makes it possible to say that a certain minimum number of
* clauses must match. See Solr manual for details.
*
* @param string $minimumMatch
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public
function
setMinimumMatch
(
$minimumMatch
)
{
return
$this
->
_setOption
(
'minimummatch'
,
$minimumMatch
);
}
/**
* Get MinimumMatch option
*
* @return string|null
*/
public
function
getMinimumMatch
()
{
return
$this
->
getOption
(
'minimummatch'
);
}
/**
* Set PhraseFields option
*
* This param can be used to "boost" the score of documents in cases
* where all of the terms in the "q" param appear in close proximity.
*
* Format is: "fieldA^1.0 fieldB^2.2"
*
* @param string $phraseFields
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public
function
setPhraseFields
(
$phraseFields
)
{
return
$this
->
_setOption
(
'phrasefields'
,
$phraseFields
);
}
/**
* Get PhraseFields option
*
* @return string|null
*/
public
function
getPhraseFields
()
{
return
$this
->
getOption
(
'phrasefields'
);
}
/**
* Set PhraseSlop option
*
* Amount of slop on phrase queries built for "pf" fields
* (affects boosting)
*
* @param string $phraseSlop
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public
function
setPhraseSlop
(
$phraseSlop
)
{
return
$this
->
_setOption
(
'phraseslop'
,
$phraseSlop
);
}
/**
* Get PhraseSlop option
*
* @return string|null
*/
public
function
getPhraseSlop
()
{
return
$this
->
getOption
(
'phraseslop'
);
}
/**
* Set QueryPhraseSlop option
*
* Amount of slop on phrase queries explicitly included in the user's
* query string (in qf fields; affects matching)
*
* @param string $queryPhraseSlop
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public
function
setQueryPhraseSlop
(
$queryPhraseSlop
)
{
return
$this
->
_setOption
(
'queryphraseslop'
,
$queryPhraseSlop
);
}
/**
* Get QueryPhraseSlop option
*
* @return string|null
*/
public
function
getQueryPhraseSlop
()
{
return
$this
->
getOption
(
'queryphraseslop'
);
}
/**
* Set Tie option
*
* Float value to use as tiebreaker in DisjunctionMaxQueries
*
* @param float $tie
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public
function
setTie
(
$tie
)
{
return
$this
->
_setOption
(
'tie'
,
$tie
);
}
/**
* Get Tie option
*
* @return float|null
*/
public
function
getTie
()
{
return
$this
->
getOption
(
'tie'
);
}
/**
* Set BoostQuery option
*
* A raw query string (in the SolrQuerySyntax) that will be included
* with the user's query to influence the score.
*
* @param string $boostQuery
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public
function
setBoostQuery
(
$boostQuery
)
{
return
$this
->
_setOption
(
'boostquery'
,
$boostQuery
);
}
/**
* Get BoostQuery option
*
* @return string|null
*/
public
function
getBoostQuery
()
{
return
$this
->
getOption
(
'boostquery'
);
}
/**
* Set BoostFunctions option
*
* Functions (with optional boosts) that will be included in the
* user's query to influence the score.
*
* Format is: "funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2"
*
* @param string $boostFunctions
* @return Solarium_Query_Component_DisMax Provides fluent interface
*/
public
function
setBoostFunctions
(
$boostFunctions
)
{
return
$this
->
_setOption
(
'boostfunctions'
,
$boostFunctions
);
}
/**
* Get BoostFunctions option
*
* @return string|null
*/
public
function
getBoostFunctions
()
{
return
$this
->
getOption
(
'boostfunctions'
);
}
}
\ No newline at end of file
library/Solarium/Query/Select/Facet.php
→
library/Solarium/Query/Select/
Component/
Facet.php
View file @
aca37f29
...
...
@@ -43,7 +43,7 @@
* @package Solarium
* @subpackage Query
*/
abstract
class
Solarium_Query_Select_Facet
extends
Solarium_Configurable
abstract
class
Solarium_Query_Select_
Component_
Facet
extends
Solarium_Configurable
{
/**
...
...
@@ -51,6 +51,8 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
*/
const
QUERY
=
'query'
;
const
FIELD
=
'field'
;
const
MULTIQUERY
=
'multiquery'
;
const
RANGE
=
'range'
;
/**
* Exclude tags for this facet
...
...
@@ -82,6 +84,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
case
'exclude'
:
if
(
!
is_array
(
$value
))
$value
=
array
(
$value
);
$this
->
setExcludes
(
$value
);
unset
(
$this
->
_options
[
'exclude'
]);
break
;
}
}
...
...
@@ -101,7 +104,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
* Set key value
*
* @param string $value
* @return Solarium_Query_Select_Facet Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet Provides fluent interface
*/
public
function
setKey
(
$value
)
{
...
...
@@ -112,7 +115,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
* Add an exclude tag
*
* @param string $tag
* @return Solarium_Query_Select_Facet Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet Provides fluent interface
*/
public
function
addExclude
(
$exclude
)
{
...
...
@@ -124,7 +127,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
* Add multiple exclude tags
*
* @param array $excludes
* @return Solarium_Query_Select_Facet Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet Provides fluent interface
*/
public
function
addExcludes
(
array
$excludes
)
{
...
...
@@ -149,7 +152,7 @@ abstract class Solarium_Query_Select_Facet extends Solarium_Configurable
* Remove a single exclude tag
*
* @param string $exclude
* @return Solarium_Query_Select_Facet Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet Provides fluent interface
*/
public
function
removeExclude
(
$exclude
)
{
...
...
library/Solarium/Query/Select/Facet/Field.php
→
library/Solarium/Query/Select/
Component/
Facet/Field.php
View file @
aca37f29
...
...
@@ -43,7 +43,7 @@
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_
Facet_Field
extends
Solarium_Query_Selec
t_Facet
class
Solarium_Query_Select_
Component_Facet_Field
extends
Solarium_Query_Select_Componen
t_Facet
{
/**
...
...
@@ -81,7 +81,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the field name
*
* @param string $query
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_Field Provides fluent interface
*/
public
function
setField
(
$field
)
{
...
...
@@ -104,7 +104,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Use one of the SORT_* constants as the value
*
* @param string $sort
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_Field Provides fluent interface
*/
public
function
setSort
(
$sort
)
{
...
...
@@ -125,7 +125,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Limit the terms for faceting by a prefix
*
* @param string $prefix
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_Field Provides fluent interface
*/
public
function
setPrefix
(
$prefix
)
{
...
...
@@ -146,7 +146,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the facet limit
*
* @param int $limit
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_Field Provides fluent interface
*/
public
function
setLimit
(
$limit
)
{
...
...
@@ -167,7 +167,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the facet offset
*
* @param int $offset
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_Field Provides fluent interface
*/
public
function
setOffset
(
$offset
)
{
...
...
@@ -188,7 +188,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the facet mincount
*
* @param int $mincount
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_Field Provides fluent interface
*/
public
function
setMinCount
(
$minCount
)
{
...
...
@@ -209,7 +209,7 @@ class Solarium_Query_Select_Facet_Field extends Solarium_Query_Select_Facet
* Set the missing count option
*
* @param boolean $missing
* @return Solarium_Query_Select_Facet_Field Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_Field Provides fluent interface
*/
public
function
setMissing
(
$missing
)
{
...
...
library/Solarium/Query/Select/Component/Facet/MultiQuery.php
0 → 100644
View file @
aca37f29
<?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
*
* @package Solarium
* @subpackage Query
*/
/**
* Facet MultiQuery
*
* This is a 'virtual' querytype that combines multiple facet queries into a
* single resultset
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Component_Facet_MultiQuery
extends
Solarium_Query_Select_Component_Facet
{
/**
* Facet query objects
*
* @var array
*/
protected
$_facetQueries
=
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
'query'
:
if
(
!
is_array
(
$value
))
$value
=
array
(
$value
);
$this
->
addQueries
(
$value
);
break
;
}
}
}
/**
* Get the facet type
*
* @return string
*/
public
function
getType
()
{
return
self
::
MULTIQUERY
;
}
/**
* Create a new facetQuery
*
* Convenience method so you don't need to manually create facetquery
* objects.
*
* @param string $key
* @param string $query
* @param array $excludes
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public
function
createQuery
(
$key
,
$query
,
$excludes
=
array
())
{
// merge excludes with shared excludes
$excludes
=
array_merge
(
$this
->
getExcludes
(),
$excludes
);
$facetQuery
=
new
Solarium_Query_Select_Component_Facet_Query
;
$facetQuery
->
setKey
(
$key
);
$facetQuery
->
setQuery
(
$query
);
$facetQuery
->
setExcludes
(
$excludes
);
return
$this
->
addQuery
(
$facetQuery
);
}
/**
* Add a facetquery
*
* Supports a facetquery instance or a config array, in that case a new
* facetquery instance wil be created based on the options.
*
* @param Solarium_Query_Select_Component_Facet_Query|array $facetQuery
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public
function
addQuery
(
$facetQuery
)
{
if
(
is_array
(
$facetQuery
))
{
$facetQuery
=
new
Solarium_Query_Select_Component_Facet_Query
(
$facetQuery
);
}
$key
=
$facetQuery
->
getKey
();
if
(
0
===
strlen
(
$key
))
{
throw
new
Solarium_Exception
(
'A facetquery must have a key value'
);
}
if
(
array_key_exists
(
$key
,
$this
->
_facetQueries
))
{
throw
new
Solarium_Exception
(
'A query must have a unique key'
.
' value within a multiquery facet'
);
}
// forward shared excludes
$facetQuery
->
addExcludes
(
$this
->
getExcludes
());
$this
->
_facetQueries
[
$key
]
=
$facetQuery
;
return
$this
;
}
/**
* Add multiple facetqueries
*
* @param array $facetQueries Instances or config array
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public
function
addQueries
(
array
$facetQueries
)
{
foreach
(
$facetQueries
AS
$key
=>
$facetQuery
)
{
// in case of a config array: add key to config
if
(
is_array
(
$facetQuery
)
&&
!
isset
(
$facetQuery
[
'key'
]))
{
$facetQuery
[
'key'
]
=
$key
;
}
$this
->
addQuery
(
$facetQuery
);
}
return
$this
;
}
/**
* Get a facetquery
*
* @param string $key
* @return string
*/
public
function
getQuery
(
$key
)
{
if
(
isset
(
$this
->
_facetQueries
[
$key
]))
{
return
$this
->
_facetQueries
[
$key
];
}
else
{
return
null
;
}
}
/**
* Get all facetqueries
*
* @return array
*/
public
function
getQueries
()
{
return
$this
->
_facetQueries
;
}
/**
* Remove a single facetquery by key
*
* @param string $key
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public
function
removeQuery
(
$key
)
{
if
(
isset
(
$this
->
_facetQueries
[
$key
]))
{
unset
(
$this
->
_facetQueries
[
$key
]);
}
return
$this
;
}
/**
* Remove all facetqueries
*
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public
function
clearQueries
()
{
$this
->
_facetQueries
=
array
();
return
$this
;
}
/**
* Set multiple facetqueries
*
* This overwrites any existing facetqueries
*
* @param array $facetQueries
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public
function
setQueries
(
$facetQueries
)
{
$this
->
clearQueries
();
return
$this
->
addQueries
(
$facetQueries
);
}
/**
* Add an exclude tag
*
* Excludes added to the MultiQuery facet a shared by all underlying
* FacetQueries, so they must be forwarded to any existing instances.
*
* If you don't want to share an exclude use the addExclude method of a
* specific FacetQuery instance instead.
*
* @param string $tag
* @return Solarium_Query_Select_Component_Facet Provides fluent interface
*/
public
function
addExclude
(
$exclude
)
{
foreach
(
$this
->
_facetQueries
AS
$facetQuery
)
{
$facetQuery
->
addExclude
(
$exclude
);
}
return
parent
::
addExclude
(
$exclude
);
}
/**
* Remove a single exclude tag
*
* Excludes added to the MultiQuery facet a shared by all underlying
* FacetQueries, so changes must be forwarded to any existing instances.
*
* If you don't want this use the removeExclude method of a
* specific FacetQuery instance instead.
*
* @param string $exclude
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public
function
removeExclude
(
$exclude
)
{
foreach
(
$this
->
_facetQueries
AS
$facetQuery
)
{
$facetQuery
->
removeExclude
(
$exclude
);
}
return
parent
::
removeExclude
(
$exclude
);
}
/**
* Remove all excludes
*
* Excludes added to the MultiQuery facet a shared by all underlying
* FacetQueries, so changes must be forwarded to any existing instances.
*
* If you don't want this use the clearExcludes method of a
* specific FacetQuery instance instead.
*
* @return Solarium_Query_Select_Component_Facet_MultiQuery Provides fluent interface
*/
public
function
clearExcludes
()
{
foreach
(
$this
->
_facetQueries
AS
$facetQuery
)
{
$facetQuery
->
clearExcludes
();
}
return
parent
::
clearExcludes
();
}
}
\ No newline at end of file
library/Solarium/Query/Select/Facet/Query.php
→
library/Solarium/Query/Select/
Component/
Facet/Query.php
View file @
aca37f29
...
...
@@ -43,7 +43,7 @@
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_
Facet_Query
extends
Solarium_Query_Selec
t_Facet
class
Solarium_Query_Select_
Component_Facet_Query
extends
Solarium_Query_Select_Componen
t_Facet
{
/**
...
...
library/Solarium/Query/Select/Component/Facet/Range.php
0 → 100644
View file @
aca37f29
<?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
*
* @package Solarium
* @subpackage Query
*/
/**
* Facet range
*
* @link http://wiki.apache.org/solr/SimpleFacetParameters#Facet_by_Range
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Component_Facet_Range
extends
Solarium_Query_Select_Component_Facet
{
/**
* Values for the 'other' option
*/
const
OTHER_BEFORE
=
'before'
;
const
OTHER_AFTER
=
'after'
;
const
OTHER_BETWEEN
=
'between'
;
const
OTHER_ALL
=
'all'
;
const
OTHER_NONE
=
'none'
;
/**
* Values for the 'include' option
*/
const
INCLUDE_LOWER
=
'lower'
;
const
INCLUDE_UPPER
=
'upper'
;
const
INCLUDE_EDGE
=
'edge'
;
const
INCLUDE_OUTER
=
'outer'
;
const
INCLUDE_ALL
=
'all'
;
/**
* 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
'include'
:
$this
->
setInclude
(
$value
);
break
;
case
'other'
:
$this
->
setOther
(
$value
);
break
;
}
}
}
/**
* Get the facet type
*
* @return string
*/
public
function
getType
()
{
return
self
::
RANGE
;
}
/**
* Set the field name
*
* @param string $query
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public
function
setField
(
$field
)
{
return
$this
->
_setOption
(
'field'
,
$field
);
}
/**
* Get the field name
*
* @return string
*/
public
function
getField
()
{
return
$this
->
getOption
(
'field'
);
}
/**
* Set the lower bound of the range
*
* @param string $start
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public
function
setStart
(
$start
)
{
return
$this
->
_setOption
(
'start'
,
$start
);
}
/**
* Get the lower bound of the range
*
* @return string
*/
public
function
getStart
()
{
return
$this
->
getOption
(
'start'
);
}
/**
* Set the upper bound of the range
*
* @param string $end
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public
function
setEnd
(
$end
)
{
return
$this
->
_setOption
(
'end'
,
$end
);
}
/**
* Get the upper bound of the range
*
* @return string
*/
public
function
getEnd
()
{
return
$this
->
getOption
(
'end'
);
}
/**
* Set range gap
*
* The size of each range expressed as a value to be added to the lower bound
*
* @param string $gap
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public
function
setGap
(
$gap
)
{
return
$this
->
_setOption
(
'gap'
,
$gap
);
}
/**
* Get range gap
*
* The size of each range expressed as a value to be added to the lower bound
*
* @return string
*/
public
function
getGap
()
{
return
$this
->
getOption
(
'gap'
);
}
/**
* Set hardend option
*
* A Boolean parameter instructing Solr what to do in the event that facet.range.gap
* does not divide evenly between facet.range.start and facet.range.end
*
* @param boolean $hardend
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public
function
setHardend
(
$hardend
)
{
return
$this
->
_setOption
(
'hardend'
,
$hardend
);
}
/**
* Get hardend option
*
* @return boolean
*/
public
function
getHardend
()
{
return
$this
->
getOption
(
'hardend'
);
}
/**
* Set other counts
*
* Use one of the constants as value.
* If you want to use multiple values supply an array or comma separated string
*
* @param string|array $other
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public
function
setOther
(
$other
)
{
if
(
is_array
(
$other
))
{
$other
=
implode
(
','
,
$other
);
}
return
$this
->
_setOption
(
'other'
,
$other
);
}
/**
* Get other counts
*
* In case of multiple values a comma separated string will be returned
*
* @return string
*/
public
function
getOther
()
{
return
$this
->
getOption
(
'other'
);
}
/**
* Set include option
*
* Use one of the constants as value.
* If you want to use multiple values supply an array or comma separated string
*
* @param string|array $include
* @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
*/
public
function
setInclude
(
$include
)
{
if
(
is_array
(
$include
))
{
$include
=
implode
(
','
,
$include
);
}
return
$this
->
_setOption
(
'include'
,
$include
);
}
/**
* Get include option
*
* In case of multiple values a comma separated string will be returned
*
* @return string
*/
public
function
getInclude
()
{
return
$this
->
getOption
(
'include'
);
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component/FacetSet.php
0 → 100644
View file @
aca37f29
<?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
*
* @package Solarium
* @subpackage Query
*/
/**
* MoreLikeThis component
*
* @link http://wiki.apache.org/solr/MoreLikeThis
*
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Component_FacetSet
extends
Solarium_Query_Select_Component
{
/**
* Component type
*
* @var string
*/
protected
$_type
=
self
::
FACETSET
;
/**
* Default options
*
* @var array
*/
protected
$_options
=
array
();
/**
* Facets
*
* @var array
*/
protected
$_facets
=
array
();
/**
* Initialize options
*
* Several options need some extra checks or setup work, for these options
* the setters are called.
*
* @return void
*/
protected
function
_init
()
{
if
(
isset
(
$this
->
_options
[
'facet'
]))
{
foreach
(
$this
->
_options
[
'facet'
]
AS
$key
=>
$config
)
{
if
(
!
isset
(
$config
[
'key'
]))
{
$config
[
'key'
]
=
$key
;
}
$this
->
addFacet
(
$config
);
}
}
}
/**
* Limit the terms for faceting by a prefix
*
* This is a global value for all facets in this facetset
*
* @param string $prefix
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public
function
setPrefix
(
$prefix
)
{
return
$this
->
_setOption
(
'prefix'
,
$prefix
);
}
/**
* Get the facet prefix
*
* This is a global value for all facets in this facetset
*
* @return string
*/
public
function
getPrefix
()
{
return
$this
->
getOption
(
'prefix'
);
}
/**
* Set the facet sort order
*
* Use one of the SORT_* constants as the value
*
* This is a global value for all facets in this facetset
*
* @param string $sort
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public
function
setSort
(
$sort
)
{
return
$this
->
_setOption
(
'sort'
,
$sort
);
}
/**
* Get the facet sort order
*
* This is a global value for all facets in this facetset
*
* @return string
*/
public
function
getSort
()
{
return
$this
->
getOption
(
'sort'
);
}
/**
* Set the facet limit
*
* This is a global value for all facets in this facetset
*
* @param int $limit
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public
function
setLimit
(
$limit
)
{
return
$this
->
_setOption
(
'limit'
,
$limit
);
}
/**
* Get the facet limit
*
* This is a global value for all facets in this facetset
*
* @return string
*/
public
function
getLimit
()
{
return
$this
->
getOption
(
'limit'
);
}
/**
* Set the facet mincount
*
* This is a global value for all facets in this facetset
*
* @param int $mincount
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public
function
setMinCount
(
$minCount
)
{
return
$this
->
_setOption
(
'mincount'
,
$minCount
);
}
/**
* Get the facet mincount
*
* This is a global value for all facets in this facetset
*
* @return int
*/
public
function
getMinCount
()
{
return
$this
->
getOption
(
'mincount'
);
}
/**
* Set the missing count option
*
* This is a global value for all facets in this facetset
*
* @param boolean $missing
* @return Solarium_Query_Select_Component_FacetSet Provides fluent interface
*/
public
function
setMissing
(
$missing
)
{
return
$this
->
_setOption
(
'missing'
,
$missing
);
}
/**
* Get the facet missing option
*
* This is a global value for all facets in this facetset
*
* @return boolean
*/
public
function
getMissing
()
{
return
$this
->
getOption
(
'missing'
);
}
/**
* Add a facet
*
* @param Solarium_Query_Select_Component_Facet|array $facet
* @return Solarium_Query Provides fluent interface
*/
public
function
addFacet
(
$facet
)
{
if
(
is_array
(
$facet
))
{
$className
=
'Solarium_Query_Select_Component_Facet_'
.
ucfirst
(
$facet
[
'type'
]);
$facet
=
new
$className
(
$facet
);
}
$key
=
$facet
->
getKey
();
if
(
0
===
strlen
(
$key
))
{
throw
new
Solarium_Exception
(
'A facet must have a key value'
);
}
if
(
array_key_exists
(
$key
,
$this
->
_facets
))
{
throw
new
Solarium_Exception
(
'A facet must have a unique key value'
.
' within a query'
);
}
$this
->
_facets
[
$key
]
=
$facet
;
return
$this
;
}
/**
* Add multiple facets
*
* @param array $facets
* @return Solarium_Query Provides fluent interface
*/
public
function
addFacets
(
array
$facets
)
{
foreach
(
$facets
AS
$key
=>
$facet
)
{
// in case of a config array: add key to config
if
(
is_array
(
$facet
)
&&
!
isset
(
$facet
[
'key'
]))
{
$facet
[
'key'
]
=
$key
;
}
$this
->
addFacet
(
$facet
);
}
return
$this
;
}
/**
* Get a facet
*
* @param string $key
* @return string
*/
public
function
getFacet
(
$key
)
{
if
(
isset
(
$this
->
_facets
[
$key
]))
{
return
$this
->
_facets
[
$key
];
}
else
{
return
null
;
}
}
/**
* Get all facets
*
* @return array
*/
public
function
getFacets
()
{
return
$this
->
_facets
;
}
/**
* Remove a single facet by key
*
* @param string $key
* @return Solarium_Query Provides fluent interface
*/
public
function
removeFacet
(
$key
)
{
if
(
isset
(
$this
->
_facets
[
$key
]))
{
unset
(
$this
->
_facets
[
$key
]);
}
return
$this
;
}
/**
* Remove all facets
*
* @return Solarium_Query Provides fluent interface
*/
public
function
clearFacets
()
{
$this
->
_facets
=
array
();
return
$this
;
}
/**
* Set multiple facets
*
* This overwrites any existing facets
*
* @param array $facets
*/
public
function
setFacets
(
$facets
)
{
$this
->
clearFacets
();
$this
->
addFacets
(
$facets
);
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component/MoreLikeThis.php
View file @
aca37f29
...
...
@@ -43,8 +43,7 @@
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_Component_MoreLikeThis
extends
Solarium_Query_Select_Component
class
Solarium_Query_Select_Component_MoreLikeThis
extends
Solarium_Query_Select_Component
{
/**
...
...
@@ -54,24 +53,6 @@ class Solarium_Query_Select_Component_MoreLikeThis
*/
protected
$_type
=
self
::
MORELIKETHIS
;
/**
* Default options
*
* @var array
*/
protected
$_options
=
array
(
'fields'
=>
null
,
'minimumtermfrequency'
=>
null
,
'minimumdocumentfrequency'
=>
null
,
'minimumwordlength'
=>
null
,
'maximumwordlength'
=>
null
,
'maximumqueryterms'
=>
null
,
'maximumnumberoftokens'
=>
null
,
'boost'
=>
null
,
'queryfields'
=>
null
,
'count'
=>
null
,
);
/**
* Set fields option
*
...
...
library/Solarium/Result/Select/Facet/MultiQuery.php
0 → 100644
View file @
aca37f29
<?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
*
* @package Solarium
* @subpackage Result
*/
/**
* Select multiquery facet result
*
* A multiquery facet will usually return a dataset of multiple rows, in each
* row a query key and it's count. You can access the values as an array using
* {@link getValues()} or iterate this object.
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_Facet_MultiQuery
extends
Solarium_Result_Select_Facet_Field
{
}
\ No newline at end of file
library/Solarium/Result/Select/Facet/Range.php
0 → 100644
View file @
aca37f29
<?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
*
* @package Solarium
* @subpackage Result
*/
/**
* Select range facet result
*
* A multiquery facet will usually return a dataset of multiple count, in each
* row a range as key and it's count. You can access the values as an array using
* {@link getValues()} or iterate this object.
*
* The extra counts 'before', 'between' and 'after' are only available if the
* right settings for the option 'other' were used in the query.
*
* @package Solarium
* @subpackage Result
*/
class
Solarium_Result_Select_Facet_Range
extends
Solarium_Result_Select_Facet_Field
{
/**
* Count of all records with field values lower then lower bound of the first range
*
* @var int
*/
protected
$_before
;
/**
* Count of all records with field values greater then the upper bound of the last range
*
* @var int
*/
protected
$_after
;
/**
* Count all records with field values between the start and end bounds of all ranges
*
* @var int
*/
protected
$_between
;
/**
* Constructor
*
* @param array $values
* @return void
*/
public
function
__construct
(
$values
,
$before
,
$after
,
$between
)
{
$this
->
_values
=
$values
;
$this
->
_before
=
$before
;
$this
->
_after
=
$after
;
$this
->
_between
=
$between
;
}
/**
* Get 'before' count
*
* Count of all records with field values lower then lower bound of the first range
* Only available if the 'other' setting was used in the query facet.
*
* @return int
*/
public
function
getBefore
()
{
return
$this
->
_before
;
}
/**
* Get 'after' count
*
* Count of all records with field values greater then the upper bound of the last range
* Only available if the 'other' setting was used in the query facet.
*
* @return int
*/
public
function
getAfter
()
{
return
$this
->
_after
;
}
/**
* Get 'between' count
*
* Count all records with field values between the start and end bounds of all ranges
* Only available if the 'other' setting was used in the query facet.
*
* @return int
*/
public
function
getBetween
()
{
return
$this
->
_between
;
}
}
\ No newline at end of file
tests/Solarium/Client/Request/SelectTest.php
View file @
aca37f29
...
...
@@ -111,8 +111,9 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
public
function
testSelectUrlWithFacets
()
{
$this
->
_query
->
addFacet
(
new
Solarium_Query_Select_Facet_Field
(
array
(
'key'
=>
'f1'
,
'field'
=>
'owner'
)));
$this
->
_query
->
addFacet
(
new
Solarium_Query_Select_Facet_Query
(
array
(
'key'
=>
'f2'
,
'query'
=>
'category:23'
)));
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
Solarium_Query_Select_Component_Facet_Field
(
array
(
'key'
=>
'f1'
,
'field'
=>
'owner'
)));
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
Solarium_Query_Select_Component_Facet_Query
(
array
(
'key'
=>
'f2'
,
'query'
=>
'category:23'
)));
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
Solarium_Query_Select_Component_Facet_MultiQuery
(
array
(
'key'
=>
'f3'
,
'query'
=>
array
(
'f4'
=>
array
(
'query'
=>
'category:40'
)))));
$request
=
new
Solarium_Client_Request_Select
(
$this
->
_options
,
$this
->
_query
);
$this
->
assertEquals
(
...
...
@@ -121,14 +122,61 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
);
$this
->
assertEquals
(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.field={!key=f1}owner&facet.query={!key=f2}category:23'
,
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.field={!key=f1}owner&facet.query={!key=f2}category:23&facet.query={!key=f4}category:40'
,
urldecode
(
$request
->
getUri
())
);
}
public
function
testSelectUrlWithRangeFacet
()
{
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
Solarium_Query_Select_Component_Facet_Range
(
array
(
'key'
=>
'f1'
,
'field'
=>
'price'
,
'start'
=>
'1'
,
'end'
=>
100
,
'gap'
=>
10
,
'other'
=>
'all'
,
'include'
=>
'outer'
)
));
$request
=
new
Solarium_Client_Request_Select
(
$this
->
_options
,
$this
->
_query
);
$this
->
assertEquals
(
null
,
$request
->
getRawData
()
);
$this
->
assertEquals
(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&facet=true&facet.range={!key=f1}price&f.price.facet.range.start=1&f.price.facet.range.end=100&f.price.facet.range.gap=10&f.price.facet.range.other=all&f.price.facet.range.include=outer'
,
urldecode
(
$request
->
getUri
())
);
}
public
function
testSelectUrlWithFacetsAndGlobalFacetSettings
()
{
$this
->
_query
->
getFacetSet
()
->
setMissing
(
true
);
$this
->
_query
->
getFacetSet
()
->
setLimit
(
10
);
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
Solarium_Query_Select_Component_Facet_Field
(
array
(
'key'
=>
'f1'
,
'field'
=>
'owner'
)));
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
Solarium_Query_Select_Component_Facet_Query
(
array
(
'key'
=>
'f2'
,
'query'
=>
'category:23'
)));
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
Solarium_Query_Select_Component_Facet_MultiQuery
(
array
(
'key'
=>
'f3'
,
'query'
=>
array
(
'f4'
=>
array
(
'query'
=>
'category:40'
)))));
$request
=
new
Solarium_Client_Request_Select
(
$this
->
_options
,
$this
->
_query
);
$this
->
assertEquals
(
null
,
$request
->
getRawData
()
);
$this
->
assertEquals
(
'http://127.0.0.1:80/solr/select?q=*:*&start=0&rows=10&fl=*,score&wt=json&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'
,
urldecode
(
$request
->
getUri
())
);
}
public
function
testUnknownFacetType
()
{
$this
->
_query
->
addFacet
(
new
UnknownFacet
(
array
(
'key'
=>
'f1'
,
'field'
=>
'owner'
)));
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
UnknownFacet
(
array
(
'key'
=>
'f1'
,
'field'
=>
'owner'
)));
$this
->
setExpectedException
(
'Solarium_Exception'
);
$request
=
new
Solarium_Client_Request_Select
(
$this
->
_options
,
$this
->
_query
);
$request
->
getUri
();
...
...
@@ -163,7 +211,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
}
class
UnknownFacet
extends
Solarium_Query_Select_Facet_Field
{
class
UnknownFacet
extends
Solarium_Query_Select_
Component_
Facet_Field
{
public
function
getType
()
{
...
...
tests/Solarium/Query/Select/Component/DisMaxTest.php
0 → 100644
View file @
aca37f29
<?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_DisMaxTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_DisMax
*/
protected
$_disMax
;
public
function
setUp
()
{
$this
->
_disMax
=
new
Solarium_Query_Select_Component_DisMax
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select_Component
::
DISMAX
,
$this
->
_disMax
->
getType
()
);
}
public
function
testSetAndGetQueryAlternative
()
{
$value
=
'*:*'
;
$this
->
_disMax
->
setQueryAlternative
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getQueryAlternative
()
);
}
public
function
testSetAndGetQueryFields
()
{
$value
=
'title^2.0 description'
;
$this
->
_disMax
->
setQueryFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getQueryFields
()
);
}
public
function
testSetAndGetMinimumMatch
()
{
$value
=
'2.0'
;
$this
->
_disMax
->
setMinimumMatch
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getMinimumMatch
()
);
}
public
function
testSetAndGetPhraseFields
()
{
$value
=
'title^2.0 description^3.5'
;
$this
->
_disMax
->
setPhraseFields
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getPhraseFields
()
);
}
public
function
testSetAndGetPhraseSlop
()
{
$value
=
'2'
;
$this
->
_disMax
->
setPhraseSlop
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getPhraseSlop
()
);
}
public
function
testSetAndGetQueryPhraseSlop
()
{
$value
=
'3'
;
$this
->
_disMax
->
setQueryPhraseSlop
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getQueryPhraseSlop
()
);
}
public
function
testSetAndGetTie
()
{
$value
=
2.1
;
$this
->
_disMax
->
setTie
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getTie
()
);
}
public
function
testSetAndGetBoostQuery
()
{
$value
=
'cat:1^3'
;
$this
->
_disMax
->
setBoostQuery
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getBoostQuery
()
);
}
public
function
testSetAndGetBoostFunctions
()
{
$value
=
'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2'
;
$this
->
_disMax
->
setBoostFunctions
(
$value
);
$this
->
assertEquals
(
$value
,
$this
->
_disMax
->
getBoostFunctions
()
);
}
}
tests/Solarium/Query/Select/Facet/FieldTest.php
→
tests/Solarium/Query/Select/
Component/
Facet/FieldTest.php
View file @
aca37f29
...
...
@@ -29,20 +29,20 @@
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Query_Select_Facet_FieldTest
extends
PHPUnit_Framework_TestCase
class
Solarium_Query_Select_
Component_
Facet_FieldTest
extends
PHPUnit_Framework_TestCase
{
protected
$_facet
;
public
function
setUp
()
{
$this
->
_facet
=
new
Solarium_Query_Select_Facet_Field
;
$this
->
_facet
=
new
Solarium_Query_Select_
Component_
Facet_Field
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select_Facet
::
FIELD
,
Solarium_Query_Select_
Component_
Facet
::
FIELD
,
$this
->
_facet
->
getType
()
);
}
...
...
tests/Solarium/Query/Select/Component/Facet/MultiQueryTest.php
0 → 100644
View file @
aca37f29
This diff is collapsed.
Click to expand it.
tests/Solarium/Query/Select/Facet/QueryTest.php
→
tests/Solarium/Query/Select/
Component/
Facet/QueryTest.php
View file @
aca37f29
...
...
@@ -29,20 +29,20 @@
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Query_Select_Facet_QueryTest
extends
PHPUnit_Framework_TestCase
class
Solarium_Query_Select_
Component_
Facet_QueryTest
extends
PHPUnit_Framework_TestCase
{
protected
$_facet
;
public
function
setUp
()
{
$this
->
_facet
=
new
Solarium_Query_Select_Facet_Query
;
$this
->
_facet
=
new
Solarium_Query_Select_
Component_
Facet_Query
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select_Facet
::
QUERY
,
Solarium_Query_Select_
Component_
Facet
::
QUERY
,
$this
->
_facet
->
getType
()
);
}
...
...
tests/Solarium/Query/Select/Component/Facet/RangeTest.php
0 → 100644
View file @
aca37f29
<?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_Facet_RangeTest
extends
PHPUnit_Framework_TestCase
{
protected
$_facet
;
public
function
setUp
()
{
$this
->
_facet
=
new
Solarium_Query_Select_Component_Facet_Range
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select_Component_Facet
::
RANGE
,
$this
->
_facet
->
getType
()
);
}
public
function
testSetAndGetField
()
{
$this
->
_facet
->
setField
(
'price'
);
$this
->
assertEquals
(
'price'
,
$this
->
_facet
->
getField
());
}
public
function
testSetAndGetStart
()
{
$this
->
_facet
->
setStart
(
1
);
$this
->
assertEquals
(
1
,
$this
->
_facet
->
getStart
());
}
public
function
testSetAndGetEnd
()
{
$this
->
_facet
->
setEnd
(
100
);
$this
->
assertEquals
(
100
,
$this
->
_facet
->
getEnd
());
}
public
function
testSetAndGetGap
()
{
$this
->
_facet
->
setGap
(
10
);
$this
->
assertEquals
(
10
,
$this
->
_facet
->
getGap
());
}
public
function
testSetAndGetHardend
()
{
$this
->
_facet
->
setHardend
(
true
);
$this
->
assertEquals
(
true
,
$this
->
_facet
->
getHardend
());
}
public
function
testSetAndGetOther
()
{
$this
->
_facet
->
setOther
(
'all'
);
$this
->
assertEquals
(
'all'
,
$this
->
_facet
->
getOther
());
}
public
function
testSetAndGetOtherArray
()
{
$this
->
_facet
->
setOther
(
array
(
'before'
,
'after'
));
$this
->
assertEquals
(
'before,after'
,
$this
->
_facet
->
getOther
());
}
public
function
testSetAndGetInclude
()
{
$this
->
_facet
->
setInclude
(
'all'
);
$this
->
assertEquals
(
'all'
,
$this
->
_facet
->
getInclude
());
}
public
function
testSetAndGetIncludeArray
()
{
$this
->
_facet
->
setInclude
(
array
(
'lower'
,
'upper'
));
$this
->
assertEquals
(
'lower,upper'
,
$this
->
_facet
->
getInclude
());
}
}
tests/Solarium/Query/Select/Component/FacetSetTest.php
0 → 100644
View file @
aca37f29
<?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_FacetSetTest
extends
PHPUnit_Framework_TestCase
{
protected
$_facetSet
;
public
function
setUp
()
{
$this
->
_facetSet
=
new
Solarium_Query_Select_Component_FacetSet
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select_Component
::
FACETSET
,
$this
->
_facetSet
->
getType
());
}
public
function
testSetAndGetSort
()
{
$this
->
_facetSet
->
setSort
(
'index'
);
$this
->
assertEquals
(
'index'
,
$this
->
_facetSet
->
getSort
());
}
public
function
testSetAndGetPrefix
()
{
$this
->
_facetSet
->
setPrefix
(
'xyz'
);
$this
->
assertEquals
(
'xyz'
,
$this
->
_facetSet
->
getPrefix
());
}
public
function
testSetAndGetLimit
()
{
$this
->
_facetSet
->
setLimit
(
12
);
$this
->
assertEquals
(
12
,
$this
->
_facetSet
->
getLimit
());
}
public
function
testSetAndGetMinCount
()
{
$this
->
_facetSet
->
setMincount
(
100
);
$this
->
assertEquals
(
100
,
$this
->
_facetSet
->
getMincount
());
}
public
function
testSetAndGetMissing
()
{
$this
->
_facetSet
->
setMissing
(
true
);
$this
->
assertEquals
(
true
,
$this
->
_facetSet
->
getMissing
());
}
public
function
testAddAndGetFacet
()
{
$fq
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$this
->
_facetSet
->
addFacet
(
$fq
);
$this
->
assertEquals
(
$fq
,
$this
->
_facetSet
->
getFacet
(
'f1'
)
);
}
public
function
testAddFacetWithoutKey
()
{
$fq
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq
->
setQuery
(
'category:1'
);
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
_facetSet
->
addFacet
(
$fq
);
}
public
function
testAddFacetWithUsedKey
()
{
$fq1
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq2
->
setKey
(
'f1'
)
->
setQuery
(
'category:2'
);
$this
->
_facetSet
->
addFacet
(
$fq1
);
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
_facetSet
->
addFacet
(
$fq2
);
}
public
function
testGetInvalidFacet
()
{
$this
->
assertEquals
(
null
,
$this
->
_facetSet
->
getFacet
(
'invalidtag'
)
);
}
public
function
testAddFacets
()
{
$fq1
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_facetSet
->
addFacets
(
$facets
);
$this
->
assertEquals
(
$facets
,
$this
->
_facetSet
->
getFacets
()
);
}
public
function
testAddFacetsWithConfig
()
{
$facets
=
array
(
array
(
'type'
=>
'query'
,
'key'
=>
'f1'
,
'query'
=>
'category:1'
),
'f2'
=>
array
(
'type'
=>
'query'
,
'query'
=>
'category:2'
)
);
$this
->
_facetSet
->
addFacets
(
$facets
);
$this
->
assertEquals
(
2
,
count
(
$this
->
_facetSet
->
getFacets
())
);
}
public
function
testRemoveFacet
()
{
$fq1
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_facetSet
->
addFacets
(
$facets
);
$this
->
_facetSet
->
removeFacet
(
'f1'
);
$this
->
assertEquals
(
array
(
'f2'
=>
$fq2
),
$this
->
_facetSet
->
getFacets
()
);
}
public
function
testRemoveInvalidFacet
()
{
$fq1
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_facetSet
->
addFacets
(
$facets
);
$this
->
_facetSet
->
removeFacet
(
'f3'
);
//continue silently
$this
->
assertEquals
(
$facets
,
$this
->
_facetSet
->
getFacets
()
);
}
public
function
testClearFacets
()
{
$fq1
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_facetSet
->
addFacets
(
$facets
);
$this
->
_facetSet
->
clearFacets
();
$this
->
assertEquals
(
array
(),
$this
->
_facetSet
->
getFacets
()
);
}
public
function
testSetFacets
()
{
$fq1
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_facetSet
->
addFacets
(
$facets
);
$fq3
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq3
->
setKey
(
'f3'
)
->
setQuery
(
'category:3'
);
$fq4
=
new
Solarium_Query_Select_Component_Facet_Query
;
$fq4
->
setKey
(
'f4'
)
->
setQuery
(
'category:4'
);
$facets
=
array
(
'f3'
=>
$fq3
,
'f4'
=>
$fq4
);
$this
->
_facetSet
->
setFacets
(
$facets
);
$this
->
assertEquals
(
$facets
,
$this
->
_facetSet
->
getFacets
()
);
}
}
tests/Solarium/Query/Select/FacetTest.php
→
tests/Solarium/Query/Select/
Component/
FacetTest.php
View file @
aca37f29
...
...
@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Query_Select_FacetTest
extends
PHPUnit_Framework_TestCase
class
Solarium_Query_Select_
Component_
FacetTest
extends
PHPUnit_Framework_TestCase
{
protected
$_facet
;
...
...
@@ -91,7 +91,7 @@ class Solarium_Query_Select_FacetTest extends PHPUnit_Framework_TestCase
}
}
class
TestFacet
extends
Solarium_Query_Select_Facet
{
class
TestFacet
extends
Solarium_Query_Select_
Component_
Facet
{
public
function
getType
()
{
...
...
tests/Solarium/Query/Select/Component/MoreLikeThisTest.php
View file @
aca37f29
...
...
@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
*/
class
Solarium_Query_Select_Component_
m
oreLikeThisTest
extends
PHPUnit_Framework_TestCase
class
Solarium_Query_Select_Component_
M
oreLikeThisTest
extends
PHPUnit_Framework_TestCase
{
protected
$_mlt
;
...
...
@@ -39,6 +39,11 @@ class Solarium_Query_Select_Component_moreLikeThisTest extends PHPUnit_Framework
$this
->
_mlt
=
new
Solarium_Query_Select_Component_MoreLikeThis
;
}
public
function
testGetType
()
{
$this
->
assertEquals
(
Solarium_Query_Select_Component
::
MORELIKETHIS
,
$this
->
_mlt
->
getType
());
}
public
function
testSetAndGetFields
()
{
$value
=
'name,description'
;
...
...
tests/Solarium/Query/SelectTest.php
View file @
aca37f29
...
...
@@ -340,147 +340,6 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
);
}
public
function
testAddAndGetFacet
()
{
$fq
=
new
Solarium_Query_Select_Facet_Query
;
$fq
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$this
->
_query
->
addFacet
(
$fq
);
$this
->
assertEquals
(
$fq
,
$this
->
_query
->
getFacet
(
'f1'
)
);
}
public
function
testAddFacetWithoutKey
()
{
$fq
=
new
Solarium_Query_Select_Facet_Query
;
$fq
->
setQuery
(
'category:1'
);
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
_query
->
addFacet
(
$fq
);
}
public
function
testAddFacetWithUsedKey
()
{
$fq1
=
new
Solarium_Query_Select_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Facet_Query
;
$fq2
->
setKey
(
'f1'
)
->
setQuery
(
'category:2'
);
$this
->
_query
->
addFacet
(
$fq1
);
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
_query
->
addFacet
(
$fq2
);
}
public
function
testGetInvalidFacet
()
{
$this
->
assertEquals
(
null
,
$this
->
_query
->
getFacet
(
'invalidtag'
)
);
}
public
function
testAddFacets
()
{
$fq1
=
new
Solarium_Query_Select_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_query
->
addFacets
(
$facets
);
$this
->
assertEquals
(
$facets
,
$this
->
_query
->
getFacets
()
);
}
public
function
testRemoveFacet
()
{
$fq1
=
new
Solarium_Query_Select_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_query
->
addFacets
(
$facets
);
$this
->
_query
->
removeFacet
(
'f1'
);
$this
->
assertEquals
(
array
(
'f2'
=>
$fq2
),
$this
->
_query
->
getFacets
()
);
}
public
function
testRemoveInvalidFacet
()
{
$fq1
=
new
Solarium_Query_Select_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_query
->
addFacets
(
$facets
);
$this
->
_query
->
removeFacet
(
'f3'
);
//continue silently
$this
->
assertEquals
(
$facets
,
$this
->
_query
->
getFacets
()
);
}
public
function
testClearFacets
()
{
$fq1
=
new
Solarium_Query_Select_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_query
->
addFacets
(
$facets
);
$this
->
_query
->
clearFacets
();
$this
->
assertEquals
(
array
(),
$this
->
_query
->
getFacets
()
);
}
public
function
testSetFacets
()
{
$fq1
=
new
Solarium_Query_Select_Facet_Query
;
$fq1
->
setKey
(
'f1'
)
->
setQuery
(
'category:1'
);
$fq2
=
new
Solarium_Query_Select_Facet_Query
;
$fq2
->
setKey
(
'f2'
)
->
setQuery
(
'category:2'
);
$facets
=
array
(
'f1'
=>
$fq1
,
'f2'
=>
$fq2
);
$this
->
_query
->
addFacets
(
$facets
);
$fq3
=
new
Solarium_Query_Select_Facet_Query
;
$fq3
->
setKey
(
'f3'
)
->
setQuery
(
'category:3'
);
$fq4
=
new
Solarium_Query_Select_Facet_Query
;
$fq4
->
setKey
(
'f4'
)
->
setQuery
(
'category:4'
);
$facets
=
array
(
'f3'
=>
$fq3
,
'f4'
=>
$fq4
);
$this
->
_query
->
setFacets
(
$facets
);
$this
->
assertEquals
(
$facets
,
$this
->
_query
->
getFacets
()
);
}
public
function
testConstructorWithConfig
()
{
$config
=
array
(
...
...
@@ -493,10 +352,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
array
(
'key'
=>
'pub'
,
'tag'
=>
array
(
'pub'
),
'query'
=>
'published:true'
),
'online'
=>
array
(
'tag'
=>
'onl'
,
'query'
=>
'online:true'
)
),
'facet'
=>
array
(
array
(
'type'
=>
'field'
,
'key'
=>
'categories'
,
'field'
=>
'category'
),
'category13'
=>
array
(
'type'
=>
'query'
,
'query'
=>
'category:13'
)
),
'component'
=>
array
(
'facetset'
=>
array
(
'facet'
=>
array
(
array
(
'type'
=>
'field'
,
'key'
=>
'categories'
,
'field'
=>
'category'
),
'category13'
=>
array
(
'type'
=>
'query'
,
'query'
=>
'category:13'
)
)
),
)
);
$query
=
new
Solarium_Query_Select
(
$config
);
...
...
@@ -531,7 +394,7 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
$fq
->
getQuery
()
);
$facets
=
$query
->
getFacets
();
$facets
=
$query
->
getFacet
Set
()
->
getFacet
s
();
$this
->
assertEquals
(
'category'
,
$facets
[
'categories'
]
->
getField
()
...
...
@@ -572,6 +435,12 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
);
}
public
function
testGetInvalidComponentAutoload
()
{
$this
->
setExpectedException
(
'Solarium_Exception'
);
$this
->
_query
->
getComponent
(
'invalid'
,
true
);
}
public
function
testRemoveComponent
()
{
$mlt
=
new
Solarium_Query_Select_Component_MoreLikeThis
;
...
...
@@ -599,4 +468,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
get_class
(
$mlt
)
);
}
public
function
testGetDisMax
()
{
$dismax
=
$this
->
_query
->
getDisMax
();
$this
->
assertEquals
(
'Solarium_Query_Select_Component_DisMax'
,
get_class
(
$dismax
)
);
}
}
\ No newline at end of file
tests/Solarium/Result/Select/Facet/MultiQueryTest.php
0 → 100644
View file @
aca37f29
<?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_Facet_MultiQueryTest
extends
PHPUnit_Framework_TestCase
{
protected
$_values
,
$_facet
;
public
function
setUp
()
{
$this
->
_values
=
array
(
'a'
=>
12
,
'b'
=>
5
,
'c'
=>
3
,
);
$this
->
_facet
=
new
Solarium_Result_Select_Facet_MultiQuery
(
$this
->
_values
);
}
public
function
testGetValues
()
{
$this
->
assertEquals
(
$this
->
_values
,
$this
->
_facet
->
getValues
());
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_values
),
count
(
$this
->
_facet
));
}
public
function
testIterator
()
{
$values
=
array
();
foreach
(
$this
->
_facet
AS
$key
=>
$value
)
{
$values
[
$key
]
=
$value
;
}
$this
->
assertEquals
(
$this
->
_values
,
$values
);
}
}
tests/Solarium/Result/Select/Facet/RangeTest.php
0 → 100644
View file @
aca37f29
<?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_Facet_RangeTest
extends
PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Facet_Range
*/
protected
$_facet
;
protected
$_values
,
$_before
,
$_after
,
$_between
;
public
function
setUp
()
{
$this
->
_values
=
array
(
'10.0'
=>
12
,
'20.0'
=>
5
,
'30.0'
=>
3
,
);
$this
->
_before
=
2
;
$this
->
_after
=
4
;
$this
->
_between
=
3
;
$this
->
_facet
=
new
Solarium_Result_Select_Facet_Range
(
$this
->
_values
,
$this
->
_before
,
$this
->
_after
,
$this
->
_between
);
}
public
function
testGetValues
()
{
$this
->
assertEquals
(
$this
->
_values
,
$this
->
_facet
->
getValues
());
}
public
function
testCount
()
{
$this
->
assertEquals
(
count
(
$this
->
_values
),
count
(
$this
->
_facet
));
}
public
function
testIterator
()
{
$values
=
array
();
foreach
(
$this
->
_facet
AS
$key
=>
$value
)
{
$values
[
$key
]
=
$value
;
}
$this
->
assertEquals
(
$this
->
_values
,
$values
);
}
public
function
testGetBefore
()
{
$this
->
assertEquals
(
$this
->
_before
,
$this
->
_facet
->
getBefore
());
}
public
function
testGetAfter
()
{
$this
->
assertEquals
(
$this
->
_after
,
$this
->
_facet
->
getAfter
());
}
public
function
testGetBetween
()
{
$this
->
assertEquals
(
$this
->
_between
,
$this
->
_facet
->
getBetween
());
}
}
tests/bootstrap.php
View file @
aca37f29
...
...
@@ -29,6 +29,9 @@
* policies, either expressed or implied, of the copyright holder.
*/
error_reporting
(
E_ALL
|
E_STRICT
);
ini_set
(
'display_errors'
,
true
);
// Define path to application directory
$basePath
=
realpath
(
dirname
(
__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