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
80ac9643
Commit
80ac9643
authored
Apr 20, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added facetset params (global facet params)
- added unittests for facetset params
parent
f3a0db64
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
200 additions
and
10 deletions
+200
-10
library/Solarium/Client/Request/Select.php
library/Solarium/Client/Request/Select.php
+12
-0
library/Solarium/Query/Select/Component/FacetSet.php
library/Solarium/Query/Select/Component/FacetSet.php
+135
-8
tests/Solarium/Client/Request/SelectTest.php
tests/Solarium/Client/Request/SelectTest.php
+20
-0
tests/Solarium/Query/Select/Component/FacetSetTest.php
tests/Solarium/Query/Select/Component/FacetSetTest.php
+29
-0
tests/Solarium/Query/SelectTest.php
tests/Solarium/Query/SelectTest.php
+4
-2
No files found.
library/Solarium/Client/Request/Select.php
View file @
80ac9643
...
@@ -98,6 +98,11 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
...
@@ -98,6 +98,11 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
return
$this
->
buildUri
();
return
$this
->
buildUri
();
}
}
/**
* @throws Solarium_Exception
* @param Solarium_Query_Select_Component_FacetSet $facetSet
* @return void
*/
public
function
addFacetSet
(
$facetSet
)
public
function
addFacetSet
(
$facetSet
)
{
{
$facets
=
$facetSet
->
getFacets
();
$facets
=
$facetSet
->
getFacets
();
...
@@ -106,6 +111,13 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
...
@@ -106,6 +111,13 @@ class Solarium_Client_Request_Select extends Solarium_Client_Request
// enable faceting
// enable faceting
$this
->
_params
[
'facet'
]
=
'true'
;
$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
)
{
foreach
(
$facets
AS
$facet
)
{
switch
(
$facet
->
getType
())
switch
(
$facet
->
getType
())
{
{
...
...
library/Solarium/Query/Select/Component/FacetSet.php
View file @
80ac9643
...
@@ -58,9 +58,7 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
...
@@ -58,9 +58,7 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
*
*
* @var array
* @var array
*/
*/
protected
$_options
=
array
(
protected
$_options
=
array
();
//TODO global options: prefix, sort, limit, mincount, missing,
);
/**
/**
* Facets
* Facets
...
@@ -79,7 +77,8 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
...
@@ -79,7 +77,8 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
*/
*/
protected
function
_init
()
protected
function
_init
()
{
{
foreach
(
$this
->
_options
AS
$key
=>
$config
)
{
if
(
isset
(
$this
->
_options
[
'facet'
]))
{
foreach
(
$this
->
_options
[
'facet'
]
AS
$key
=>
$config
)
{
if
(
!
isset
(
$config
[
'key'
]))
{
if
(
!
isset
(
$config
[
'key'
]))
{
$config
[
'key'
]
=
$key
;
$config
[
'key'
]
=
$key
;
}
}
...
@@ -87,6 +86,134 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
...
@@ -87,6 +86,134 @@ class Solarium_Query_Select_Component_FacetSet extends Solarium_Query_Select_Com
$this
->
addFacet
(
$config
);
$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
* Add a facet
...
...
tests/Solarium/Client/Request/SelectTest.php
View file @
80ac9643
...
@@ -127,6 +127,26 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -127,6 +127,26 @@ class Solarium_Client_Request_SelectTest extends PHPUnit_Framework_TestCase
);
);
}
}
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
()
public
function
testUnknownFacetType
()
{
{
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
UnknownFacet
(
array
(
'key'
=>
'f1'
,
'field'
=>
'owner'
)));
$this
->
_query
->
getFacetSet
()
->
addFacet
(
new
UnknownFacet
(
array
(
'key'
=>
'f1'
,
'field'
=>
'owner'
)));
...
...
tests/Solarium/Query/Select/Component/FacetSetTest.php
View file @
80ac9643
...
@@ -39,6 +39,35 @@ class Solarium_Query_Select_Component_FacetSetTest extends PHPUnit_Framework_Tes
...
@@ -39,6 +39,35 @@ class Solarium_Query_Select_Component_FacetSetTest extends PHPUnit_Framework_Tes
$this
->
_facetSet
=
new
Solarium_Query_Select_Component_FacetSet
;
$this
->
_facetSet
=
new
Solarium_Query_Select_Component_FacetSet
;
}
}
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
()
public
function
testAddAndGetFacet
()
{
{
...
...
tests/Solarium/Query/SelectTest.php
View file @
80ac9643
...
@@ -354,8 +354,10 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
...
@@ -354,8 +354,10 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
),
),
'component'
=>
array
(
'component'
=>
array
(
'facetset'
=>
array
(
'facetset'
=>
array
(
'facet'
=>
array
(
array
(
'type'
=>
'field'
,
'key'
=>
'categories'
,
'field'
=>
'category'
),
array
(
'type'
=>
'field'
,
'key'
=>
'categories'
,
'field'
=>
'category'
),
'category13'
=>
array
(
'type'
=>
'query'
,
'query'
=>
'category:13'
)
'category13'
=>
array
(
'type'
=>
'query'
,
'query'
=>
'category:13'
)
)
),
),
)
)
);
);
...
...
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