Commit 7ba16cad authored by Bas de Nooijer's avatar Bas de Nooijer

Added support for new term qparser and filterquery cachecontrol to query helper

parent 96917f2e
...@@ -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;
}
} }
...@@ -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)
);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment