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
7ba16cad
Commit
7ba16cad
authored
Jan 04, 2013
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for new term qparser and filterquery cachecontrol to query helper
parent
96917f2e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
0 deletions
+71
-0
library/Solarium/Core/Query/Helper.php
library/Solarium/Core/Query/Helper.php
+47
-0
tests/Solarium/Tests/Core/Query/HelperTest.php
tests/Solarium/Tests/Core/Query/HelperTest.php
+24
-0
No files found.
library/Solarium/Core/Query/Helper.php
View file @
7ba16cad
...
@@ -432,4 +432,51 @@ class Helper
...
@@ -432,4 +432,51 @@ class Helper
return
$this
->
qparser
(
'join'
,
array
(
'from'
=>
$from
,
'to'
=>
$to
),
$dereferenced
,
$dereferenced
);
return
$this
->
qparser
(
'join'
,
array
(
'from'
=>
$from
,
'to'
=>
$to
),
$dereferenced
,
$dereferenced
);
}
}
/**
* Render term query
*
* Useful for avoiding query parser escaping madness when drilling into facets via fq parameters, example:
* {!term f=weight}1.5
*
* This is a Solr 3.2+ feature.
*
* @see http://wiki.apache.org/solr/SolrQuerySyntax#Other_built-in_useful_query_parsers
*
* @param string $field
* @param float $weight
* @return string
*/
public
function
qparserTerm
(
$field
,
$weight
)
{
return
$this
->
qparser
(
'term'
,
array
(
'f'
=>
$field
))
.
$weight
;
}
/**
* Render cache control param for use in filterquery
*
* This is a Solr 3.4+ feature.
*
* @see http://wiki.apache.org/solr/CommonQueryParameters#Caching_of_filters
*
* @param boolean $useCache
* @param float|null $weight
* @return string
*/
public
function
cacheControl
(
$useCache
,
$cost
=
null
)
{
if
(
$useCache
===
true
)
{
$cache
=
'true'
;
}
else
{
$cache
=
'false'
;
}
$result
=
'{!cache='
.
$cache
;
if
(
null
!==
$cost
)
{
$result
.=
' cost='
.
$cost
;
}
$result
.=
'}'
;
return
$result
;
}
}
}
tests/Solarium/Tests/Core/Query/HelperTest.php
View file @
7ba16cad
...
@@ -380,4 +380,28 @@ class HelperTest extends \PHPUnit_Framework_TestCase
...
@@ -380,4 +380,28 @@ class HelperTest extends \PHPUnit_Framework_TestCase
);
);
}
}
public
function
testQparserTerm
()
{
$this
->
assertEquals
(
'{!term f=weight}1.5'
,
$this
->
helper
->
qparserTerm
(
'weight'
,
1.5
)
);
}
public
function
testCacheControlWithCost
()
{
$this
->
assertEquals
(
'{!cache=false cost=6}'
,
$this
->
helper
->
cacheControl
(
false
,
6
)
);
}
public
function
testCacheControlWithoutCost
()
{
$this
->
assertEquals
(
'{!cache=true}'
,
$this
->
helper
->
cacheControl
(
true
)
);
}
}
}
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