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
cc91f30d
Commit
cc91f30d
authored
Apr 19, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- moved facets into component structure
- updated unittests for new structure
parent
7ec23137
Changes
18
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
529 additions
and
345 deletions
+529
-345
library/Solarium/Client/Request/Select.php
library/Solarium/Client/Request/Select.php
+15
-9
library/Solarium/Client/Response/Select.php
library/Solarium/Client/Response/Select.php
+27
-21
library/Solarium/Query/Select.php
library/Solarium/Query/Select.php
+47
-127
library/Solarium/Query/Select/Component.php
library/Solarium/Query/Select/Component.php
+1
-0
library/Solarium/Query/Select/Component/Facet.php
library/Solarium/Query/Select/Component/Facet.php
+5
-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
+13
-13
library/Solarium/Query/Select/Component/Facet/Query.php
library/Solarium/Query/Select/Component/Facet/Query.php
+1
-1
library/Solarium/Query/Select/Component/FacetSet.php
library/Solarium/Query/Select/Component/FacetSet.php
+204
-0
library/Solarium/Query/Select/Component/MoreLikeThis.php
library/Solarium/Query/Select/Component/MoreLikeThis.php
+1
-2
tests/Solarium/Client/Request/SelectTest.php
tests/Solarium/Client/Request/SelectTest.php
+4
-4
tests/Solarium/Query/Select/Component/Facet/FieldTest.php
tests/Solarium/Query/Select/Component/Facet/FieldTest.php
+3
-3
tests/Solarium/Query/Select/Component/Facet/QueryTest.php
tests/Solarium/Query/Select/Component/Facet/QueryTest.php
+3
-3
tests/Solarium/Query/Select/Component/FacetSetTest.php
tests/Solarium/Query/Select/Component/FacetSetTest.php
+184
-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
+1
-1
tests/Solarium/Query/SelectTest.php
tests/Solarium/Query/SelectTest.php
+7
-146
tests/bootstrap.php
tests/bootstrap.php
+3
-0
No files found.
library/Solarium/Client/Request/Select.php
View file @
cc91f30d
...
...
@@ -87,12 +87,20 @@ 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
;
default
:
throw
new
Solarium_Exception
(
'Unknown component type'
);
}
}
$facets
=
$this
->
_query
->
getFacets
();
return
$this
->
buildUri
();
}
public
function
addFacetSet
(
$facetSet
)
{
$facets
=
$facetSet
->
getFacets
();
if
(
count
(
$facets
)
!==
0
)
{
// enable faceting
...
...
@@ -101,13 +109,13 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
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_Facet
::
MULTIQUERY
:
case
Solarium_Query_Select_
Component_
Facet
::
MULTIQUERY
:
$this
->
addFacetMultiQuery
(
$facet
);
break
;
default
:
...
...
@@ -115,14 +123,12 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
}
}
}
return
$this
->
buildUri
();
}
/**
* Add params for a field facet to request
*
* @param Solarium_Query_Select_Facet_Field $facet
* @param Solarium_Query_Select_
Component_
Facet_Field $facet
* @return void
*/
public
function
addFacetField
(
$facet
)
...
...
@@ -149,7 +155,7 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
/**
* Add params for a facet query to request
*
* @param Solarium_Query_Select_Facet_Query $facet
* @param Solarium_Query_Select_
Component_
Facet_Query $facet
* @return void
*/
public
function
addFacetQuery
(
$facet
)
...
...
@@ -166,7 +172,7 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
/**
* Add params for a multiquery facet to request
*
* @param Solarium_Query_Select_Facet_MultiQuery $facet
* @param Solarium_Query_Select_
Component_
Facet_MultiQuery $facet
* @return void
*/
public
function
addFacetMultiQuery
(
$facet
)
...
...
library/Solarium/Client/Response/Select.php
View file @
cc91f30d
...
...
@@ -89,44 +89,50 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
case
Solarium_Query_Select_Component
::
MORELIKETHIS
:
$this
->
_addMoreLikeThis
(
$component
);
break
;
case
Solarium_Query_Select_Component
::
FACETSET
:
$this
->
_addFacetSet
(
$component
);
break
;
default
:
throw
new
Solarium_Exception
(
'Unknown component type'
);
}
}
// add general data
$status
=
$this
->
_data
[
'responseHeader'
][
'status'
];
$queryTime
=
$this
->
_data
[
'responseHeader'
][
'QTime'
];
$numFound
=
$this
->
_data
[
'response'
][
'numFound'
];
// create the result instance that combines all data
$resultClass
=
$this
->
_query
->
getOption
(
'resultclass'
);
return
new
$resultClass
(
$status
,
$queryTime
,
$numFound
,
$documents
,
$this
->
_facets
,
$this
->
_components
);
}
protected
function
_addFacetSet
(
$facetSet
)
{
// create facet results
foreach
(
$
this
->
_query
->
getFacets
()
AS
$facet
)
{
foreach
(
$
facetSet
->
getFacets
()
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_Facet
::
MULTIQUERY
:
case
Solarium_Query_Select_
Component_
Facet
::
MULTIQUERY
:
$this
->
_addFacetMultiQuery
(
$facet
);
break
;
default
:
throw
new
Solarium_Exception
(
'Unknown facet type'
);
}
}
// add general data
$status
=
$this
->
_data
[
'responseHeader'
][
'status'
];
$queryTime
=
$this
->
_data
[
'responseHeader'
][
'QTime'
];
$numFound
=
$this
->
_data
[
'response'
][
'numFound'
];
// create the result instance that combines all data
$resultClass
=
$this
->
_query
->
getOption
(
'resultclass'
);
return
new
$resultClass
(
$status
,
$queryTime
,
$numFound
,
$documents
,
$this
->
_facets
,
$this
->
_components
);
}
/**
* Add a facet result for a field facet
*
* @param Solarium_Query_Select_Facet_Field $facet
* @param Solarium_Query_Select_
Component_
Facet_Field $facet
* @return void
*/
protected
function
_addFacetField
(
$facet
)
...
...
@@ -145,14 +151,14 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
}
$this
->
_facets
[
$key
]
=
new
Solarium_Result_Select_Facet_Field
(
$facetValues
);
new
Solarium_Result_Select_
Component_
Facet_Field
(
$facetValues
);
}
}
/**
* Add a facet result for a facet query
*
* @param Solarium_Query_Select_Facet_Query $facet
* @param Solarium_Query_Select_
Component_
Facet_Query $facet
* @return void
*/
protected
function
_addFacetQuery
(
$facet
)
...
...
@@ -162,14 +168,14 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
$value
=
$this
->
_data
[
'facet_counts'
][
'facet_queries'
][
$key
];
$this
->
_facets
[
$key
]
=
new
Solarium_Result_Select_Facet_Query
(
$value
);
new
Solarium_Result_Select_
Component_
Facet_Query
(
$value
);
}
}
/**
* Add a facet result for a multiquery facet
*
* @param Solarium_Query_Select_Facet_MultiQuery $facet
* @param Solarium_Query_Select_
Component_
Facet_MultiQuery $facet
* @return void
*/
protected
function
_addFacetMultiQuery
(
$facet
)
...
...
@@ -184,7 +190,7 @@ class Solarium_Client_Response_Select extends Solarium_Client_Response
}
$this
->
_facets
[
$facet
->
getKey
()]
=
new
Solarium_Result_Select_Facet_MultiQuery
(
$values
);
new
Solarium_Result_Select_
Component_
Facet_MultiQuery
(
$values
);
}
/**
...
...
library/Solarium/Query/Select.php
View file @
cc91f30d
...
...
@@ -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,28 @@ 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
;
default
:
throw
new
Solarium_Exception
(
'Cannot autoload unknown component: '
.
$key
);
}
$component
=
new
$className
(
$config
);
$this
->
setComponent
(
$key
,
$component
);
return
$this
->
_components
[
$key
];
}
...
...
@@ -713,6 +606,21 @@ 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 +630,19 @@ 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
);
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component.php
View file @
cc91f30d
...
...
@@ -48,6 +48,7 @@ class Solarium_Query_Select_Component extends Solarium_Configurable
* Component types
*/
const
MORELIKETHIS
=
'morelikethis'
;
const
FACETSET
=
'facetset'
;
/**
* Component type
...
...
library/Solarium/Query/Select/Facet.php
→
library/Solarium/Query/Select/
Component/
Facet.php
View file @
cc91f30d
...
...
@@ -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
{
/**
...
...
@@ -102,7 +102,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
)
{
...
...
@@ -113,7 +113,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
)
{
...
...
@@ -125,7 +125,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
)
{
...
...
@@ -150,7 +150,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 @
cc91f30d
...
...
@@ -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/Facet/MultiQuery.php
→
library/Solarium/Query/Select/
Component/
Facet/MultiQuery.php
View file @
cc91f30d
...
...
@@ -44,7 +44,7 @@
* @package Solarium
* @subpackage Query
*/
class
Solarium_Query_Select_
Facet_MultiQuery
extends
Solarium_Query_Selec
t_Facet
class
Solarium_Query_Select_
Component_Facet_MultiQuery
extends
Solarium_Query_Select_Componen
t_Facet
{
/**
...
...
@@ -93,14 +93,14 @@ class Solarium_Query_Select_Facet_MultiQuery extends Solarium_Query_Select_Facet
* @param string $key
* @param string $query
* @param array $excludes
* @return Solarium_Query_Select_Facet_MultiQuery Provides fluent interface
* @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
->
_excludes
,
$excludes
);
$facetQuery
=
new
Solarium_Query_Select_Facet_Query
;
$facetQuery
=
new
Solarium_Query_Select_
Component_
Facet_Query
;
$facetQuery
->
setKey
(
$key
);
$facetQuery
->
setQuery
(
$query
);
$facetQuery
->
setExcludes
(
$excludes
);
...
...
@@ -114,13 +114,13 @@ class Solarium_Query_Select_Facet_MultiQuery extends Solarium_Query_Select_Facet
* 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_Facet_Query|array $facetQuery
* @return Solarium_Query_Select_Facet_MultiQuery Provides fluent interface
* @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_Facet_Query
(
$facetQuery
);
$facetQuery
=
new
Solarium_Query_Select_
Component_
Facet_Query
(
$facetQuery
);
}
$key
=
$facetQuery
->
getKey
();
...
...
@@ -145,7 +145,7 @@ class Solarium_Query_Select_Facet_MultiQuery extends Solarium_Query_Select_Facet
* Add multiple facetqueries
*
* @param array $facetQueries Instances or config array
* @return Solarium_Query_Select_Facet_MultiQuery Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_MultiQuery Provides fluent interface
*/
public
function
addQueries
(
array
$facetQueries
)
{
...
...
@@ -191,7 +191,7 @@ class Solarium_Query_Select_Facet_MultiQuery extends Solarium_Query_Select_Facet
* Remove a single facetquery by key
*
* @param string $key
* @return Solarium_Query_Select_Facet_MultiQuery Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_MultiQuery Provides fluent interface
*/
public
function
removeQuery
(
$key
)
{
...
...
@@ -205,7 +205,7 @@ class Solarium_Query_Select_Facet_MultiQuery extends Solarium_Query_Select_Facet
/**
* Remove all facetqueries
*
* @return Solarium_Query_Select_Facet_MultiQuery Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_MultiQuery Provides fluent interface
*/
public
function
clearQueries
()
{
...
...
@@ -219,7 +219,7 @@ class Solarium_Query_Select_Facet_MultiQuery extends Solarium_Query_Select_Facet
* This overwrites any existing facetqueries
*
* @param array $facetQueries
* @return Solarium_Query_Select_Facet_MultiQuery Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_MultiQuery Provides fluent interface
*/
public
function
setFacetQueries
(
$facetQueries
)
{
...
...
@@ -237,7 +237,7 @@ class Solarium_Query_Select_Facet_MultiQuery extends Solarium_Query_Select_Facet
* specific FacetQuery instance instead.
*
* @param string $tag
* @return Solarium_Query_Select_Facet Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet Provides fluent interface
*/
public
function
addExclude
(
$exclude
)
{
...
...
@@ -258,7 +258,7 @@ class Solarium_Query_Select_Facet_MultiQuery extends Solarium_Query_Select_Facet
* specific FacetQuery instance instead.
*
* @param string $exclude
* @return Solarium_Query_Select_Facet_MultiQuery Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_MultiQuery Provides fluent interface
*/
public
function
removeExclude
(
$exclude
)
{
...
...
@@ -278,7 +278,7 @@ class Solarium_Query_Select_Facet_MultiQuery extends Solarium_Query_Select_Facet
* If you don't want this use the clearExcludes method of a
* specific FacetQuery instance instead.
*
* @return Solarium_Query_Select_Facet_MultiQuery Provides fluent interface
* @return Solarium_Query_Select_
Component_
Facet_MultiQuery Provides fluent interface
*/
public
function
clearExcludes
()
{
...
...
library/Solarium/Query/Select/Facet/Query.php
→
library/Solarium/Query/Select/
Component/
Facet/Query.php
View file @
cc91f30d
...
...
@@ -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/FacetSet.php
0 → 100644
View file @
cc91f30d
<?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
(
//TODO global options: prefix, sort, limit, mincount, missing,
);
/**
* 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
()
{
foreach
(
$this
->
_options
AS
$key
=>
$config
)
{
if
(
!
isset
(
$config
[
'key'
]))
{
$config
[
'key'
]
=
$key
;
}
$this
->
addFacet
(
$config
);
}
}
/**
* 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 @
cc91f30d
...
...
@@ -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
{
/**
...
...
tests/Solarium/Client/Request/SelectTest.php
View file @
cc91f30d
...
...
@@ -111,8 +111,8 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
public
function
testSelectUrlWithFacets
()
{
$this
->
_query
->
addFacet
(
new
Solarium_Query_Selec
t_Facet_Field
(
array
(
'key'
=>
'f1'
,
'field'
=>
'owner'
)));
$this
->
_query
->
addFacet
(
new
Solarium_Query_Selec
t_Facet_Query
(
array
(
'key'
=>
'f2'
,
'query'
=>
'category:23'
)));
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
Solarium_Query_Select_Componen
t_Facet_Field
(
array
(
'key'
=>
'f1'
,
'field'
=>
'owner'
)));
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
Solarium_Query_Select_Componen
t_Facet_Query
(
array
(
'key'
=>
'f2'
,
'query'
=>
'category:23'
)));
$request
=
new
Solarium_Client_Request_Select
(
$this
->
_options
,
$this
->
_query
);
$this
->
assertEquals
(
...
...
@@ -128,7 +128,7 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
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 +163,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/Facet/FieldTest.php
→
tests/Solarium/Query/Select/
Component/
Facet/FieldTest.php
View file @
cc91f30d
...
...
@@ -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/Facet/QueryTest.php
→
tests/Solarium/Query/Select/
Component/
Facet/QueryTest.php
View file @
cc91f30d
...
...
@@ -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/FacetSetTest.php
0 → 100644
View file @
cc91f30d
<?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
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
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 @
cc91f30d
...
...
@@ -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 @
cc91f30d
...
...
@@ -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
;
...
...
tests/Solarium/Query/SelectTest.php
View file @
cc91f30d
...
...
@@ -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,12 @@ 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
(
'component'
=>
array
(
'facetset'
=>
array
(
array
(
'type'
=>
'field'
,
'key'
=>
'categories'
,
'field'
=>
'category'
),
'category13'
=>
array
(
'type'
=>
'query'
,
'query'
=>
'category:13'
)
),
)
);
$query
=
new
Solarium_Query_Select
(
$config
);
...
...
@@ -531,7 +392,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
()
...
...
tests/bootstrap.php
View file @
cc91f30d
...
...
@@ -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