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
01ed9f94
Commit
01ed9f94
authored
Aug 15, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for tagging the main query
parent
724c482a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
152 additions
and
5 deletions
+152
-5
library/Solarium/QueryType/Select/Query/FilterQuery.php
library/Solarium/QueryType/Select/Query/FilterQuery.php
+2
-4
library/Solarium/QueryType/Select/Query/Query.php
library/Solarium/QueryType/Select/Query/Query.php
+92
-0
library/Solarium/QueryType/Select/RequestBuilder/RequestBuilder.php
...larium/QueryType/Select/RequestBuilder/RequestBuilder.php
+4
-1
tests/Solarium/Tests/QueryType/Select/Query/QueryTest.php
tests/Solarium/Tests/QueryType/Select/Query/QueryTest.php
+42
-0
tests/Solarium/Tests/QueryType/Select/RequestBuilder/RequestBuilderTest.php
...ts/QueryType/Select/RequestBuilder/RequestBuilderTest.php
+12
-0
No files found.
library/Solarium/QueryType/Select/Query/FilterQuery.php
View file @
01ed9f94
...
@@ -200,7 +200,6 @@ class FilterQuery extends Configurable
...
@@ -200,7 +200,6 @@ class FilterQuery extends Configurable
public
function
clearTags
()
public
function
clearTags
()
{
{
$this
->
tags
=
array
();
$this
->
tags
=
array
();
return
$this
;
return
$this
;
}
}
...
@@ -212,11 +211,10 @@ class FilterQuery extends Configurable
...
@@ -212,11 +211,10 @@ class FilterQuery extends Configurable
* @param array $filterQueries
* @param array $filterQueries
* @return self Provides fluent interface
* @return self Provides fluent interface
*/
*/
public
function
setTags
(
$
filterQuerie
s
)
public
function
setTags
(
$
tag
s
)
{
{
$this
->
clearTags
();
$this
->
clearTags
();
return
$this
->
addTags
(
$tags
);
return
$this
->
addTags
(
$filterQueries
);
}
}
}
}
library/Solarium/QueryType/Select/Query/Query.php
View file @
01ed9f94
...
@@ -140,6 +140,13 @@ class Query extends BaseQuery
...
@@ -140,6 +140,13 @@ class Query extends BaseQuery
'omitheader'
=>
true
,
'omitheader'
=>
true
,
);
);
/**
* Tags for this query
*
* @var array
*/
protected
$tags
=
array
();
/**
/**
* Default select query component types
* Default select query component types
*
*
...
@@ -249,6 +256,12 @@ class Query extends BaseQuery
...
@@ -249,6 +256,12 @@ class Query extends BaseQuery
case
'component'
:
case
'component'
:
$this
->
createComponents
(
$value
);
$this
->
createComponents
(
$value
);
break
;
break
;
case
'tag'
:
if
(
!
is_array
(
$value
))
{
$value
=
array
(
$value
);
}
$this
->
addTags
(
$value
);
break
;
}
}
}
}
}
}
...
@@ -987,4 +1000,83 @@ class Query extends BaseQuery
...
@@ -987,4 +1000,83 @@ class Query extends BaseQuery
return
$this
->
getComponent
(
self
::
COMPONENT_DEBUG
,
true
);
return
$this
->
getComponent
(
self
::
COMPONENT_DEBUG
,
true
);
}
}
/**
* Add a tag
*
* @param string $tag
* @return self Provides fluent interface
*/
public
function
addTag
(
$tag
)
{
$this
->
tags
[
$tag
]
=
true
;
return
$this
;
}
/**
* Add tags
*
* @param array $tags
* @return self Provides fluent interface
*/
public
function
addTags
(
$tags
)
{
foreach
(
$tags
as
$tag
)
{
$this
->
addTag
(
$tag
);
}
return
$this
;
}
/**
* Get all tagss
*
* @return array
*/
public
function
getTags
()
{
return
array_keys
(
$this
->
tags
);
}
/**
* Remove a tag
*
* @param string $tag
* @return self Provides fluent interface
*/
public
function
removeTag
(
$tag
)
{
if
(
isset
(
$this
->
tags
[
$tag
]))
{
unset
(
$this
->
tags
[
$tag
]);
}
return
$this
;
}
/**
* Remove all tags
*
* @return self Provides fluent interface
*/
public
function
clearTags
()
{
$this
->
tags
=
array
();
return
$this
;
}
/**
* Set multiple tags
*
* This overwrites any existing tags
*
* @param array $tags
* @return self Provides fluent interface
*/
public
function
setTags
(
$tags
)
{
$this
->
clearTags
();
return
$this
->
addTags
(
$tags
);
}
}
}
library/Solarium/QueryType/Select/RequestBuilder/RequestBuilder.php
View file @
01ed9f94
...
@@ -59,7 +59,10 @@ class RequestBuilder extends BaseRequestBuilder
...
@@ -59,7 +59,10 @@ class RequestBuilder extends BaseRequestBuilder
$request
=
parent
::
build
(
$query
);
$request
=
parent
::
build
(
$query
);
// add basic params to request
// add basic params to request
$request
->
addParam
(
'q'
,
$query
->
getQuery
());
$request
->
addParam
(
'q'
,
$this
->
renderLocalParams
(
$query
->
getQuery
(),
array
(
'tag'
=>
$query
->
getTags
())
));
$request
->
addParam
(
'start'
,
$query
->
getStart
());
$request
->
addParam
(
'start'
,
$query
->
getStart
());
$request
->
addParam
(
'rows'
,
$query
->
getRows
());
$request
->
addParam
(
'rows'
,
$query
->
getRows
());
$request
->
addParam
(
'fl'
,
implode
(
','
,
$query
->
getFields
()));
$request
->
addParam
(
'fl'
,
implode
(
','
,
$query
->
getFields
()));
...
...
tests/Solarium/Tests/QueryType/Select/Query/QueryTest.php
View file @
01ed9f94
...
@@ -444,6 +444,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
...
@@ -444,6 +444,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
),
),
'resultclass'
=>
'MyResultClass'
,
'resultclass'
=>
'MyResultClass'
,
'documentclass'
=>
'MyDocumentClass'
,
'documentclass'
=>
'MyDocumentClass'
,
'tag'
=>
array
(
't1'
,
't2'
),
);
);
$query
=
new
Query
(
$config
);
$query
=
new
Query
(
$config
);
...
@@ -470,6 +471,13 @@ class QueryTest extends \PHPUnit_Framework_TestCase
...
@@ -470,6 +471,13 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$components
=
$query
->
getComponents
();
$components
=
$query
->
getComponents
();
$this
->
assertEquals
(
1
,
count
(
$components
));
$this
->
assertEquals
(
1
,
count
(
$components
));
$this
->
assertThat
(
array_pop
(
$components
),
$this
->
isInstanceOf
(
'Solarium\QueryType\Select\Query\Component\FacetSet'
));
$this
->
assertThat
(
array_pop
(
$components
),
$this
->
isInstanceOf
(
'Solarium\QueryType\Select\Query\Component\FacetSet'
));
$this
->
assertEquals
(
array
(
't1'
,
't2'
),
$query
->
getTags
());
}
public
function
testConfigModeWithSingleValueTag
()
{
$query
=
$query
=
new
Query
(
array
(
'tag'
=>
't1'
));
$this
->
assertEquals
(
array
(
't1'
),
$query
->
getTags
());
}
}
public
function
testSetAndGetComponents
()
public
function
testSetAndGetComponents
()
...
@@ -663,4 +671,38 @@ class QueryTest extends \PHPUnit_Framework_TestCase
...
@@ -663,4 +671,38 @@ class QueryTest extends \PHPUnit_Framework_TestCase
get_class
(
$stats
)
get_class
(
$stats
)
);
);
}
}
public
function
testAddTag
()
{
$this
->
query
->
addTag
(
'testtag'
);
$this
->
assertEquals
(
array
(
'testtag'
),
$this
->
query
->
getTags
());
}
public
function
testAddTags
()
{
$this
->
query
->
addTags
(
array
(
't1'
,
't2'
));
$this
->
assertEquals
(
array
(
't1'
,
't2'
),
$this
->
query
->
getTags
());
}
public
function
testRemoveTag
()
{
$this
->
query
->
addTags
(
array
(
't1'
,
't2'
));
$this
->
query
->
removeTag
(
't1'
);
$this
->
assertEquals
(
array
(
't2'
),
$this
->
query
->
getTags
());
}
public
function
testClearTags
()
{
$this
->
query
->
addTags
(
array
(
't1'
,
't2'
));
$this
->
query
->
clearTags
();
$this
->
assertEquals
(
array
(),
$this
->
query
->
getTags
());
}
public
function
testSetTags
()
{
$this
->
query
->
addTags
(
array
(
't1'
,
't2'
));
$this
->
query
->
setTags
(
array
(
't3'
,
't4'
));
$this
->
assertEquals
(
array
(
't3'
,
't4'
),
$this
->
query
->
getTags
());
}
}
}
tests/Solarium/Tests/QueryType/Select/RequestBuilder/RequestBuilderTest.php
View file @
01ed9f94
...
@@ -169,6 +169,18 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
...
@@ -169,6 +169,18 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
);
);
}
}
public
function
testWithTags
()
{
$this
->
query
->
setTags
(
array
(
't1'
,
't2'
));
$this
->
query
->
setQuery
(
'cat:1'
);
$request
=
$this
->
builder
->
build
(
$this
->
query
);
$this
->
assertEquals
(
'{!tag=t1,t2}cat:1'
,
$request
->
getParam
(
'query'
)
);
}
}
}
class
TestDummyComponent
extends
Component
class
TestDummyComponent
extends
Component
...
...
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