Commit 6cdc4983 authored by Bas de Nooijer's avatar Bas de Nooijer

Maximumscore filtering for groups improved to support different types of sorting

parent 7236f732
......@@ -48,6 +48,21 @@ class QueryGroupResult extends StandardQueryGroupResult
*/
static protected $overallMaximumScore;
/**
* @var string
*/
protected $filterMode;
/**
* @var float
*/
protected $filterRatio;
/**
* @var boolean
*/
protected $filtered = false;
/**
* Constructor
*
......@@ -60,17 +75,31 @@ class QueryGroupResult extends StandardQueryGroupResult
*/
public function __construct($matches, $numFound, $start, $maximumScore, $documents, $query)
{
$this->filterMode = $query->getFilterMode();
$this->filterRatio = $query->getFilterRatio();
// Use the maximumScore of the first group as maximum for all groups
if (self::$overallMaximumScore == null) {
self::$overallMaximumScore = $maximumScore;
}
parent::__construct($matches, $numFound, $start, $maximumScore, $documents, $query);
}
/**
* Get all documents, apply filter at first use
*
* @return array
*/
public function getDocuments()
{
if (!$this->filtered) {
$filter = new Filter;
$mode = $query->getFilterMode();
$ratio = $query->getFilterRatio();
$documents = $filter->filterDocuments($documents, self::$overallMaximumScore, $ratio, $mode);
$this->documents = $filter->filterDocuments($this->documents, self::$overallMaximumScore, $this->filterRatio, $this->filterMode);
$this->filtered = true;
}
parent::__construct($matches, $numFound, $start, $maximumScore, $documents, $query);
return $this->documents;
}
}
......@@ -48,6 +48,21 @@ class ValueGroupResult extends StandardValueGroup
*/
static protected $overallMaximumScore;
/**
* @var string
*/
protected $filterMode;
/**
* @var float
*/
protected $filterRatio;
/**
* @var boolean
*/
protected $filtered = false;
/**
* Constructor
*
......@@ -59,18 +74,31 @@ class ValueGroupResult extends StandardValueGroup
*/
public function __construct($value, $numFound, $start, $documents, $maximumScore, $query)
{
$this->filterMode = $query->getFilterMode();
$this->filterRatio = $query->getFilterRatio();
// Use the maximumScore of the first group as maximum for all groups
if (self::$overallMaximumScore == null) {
if ($maximumScore > self::$overallMaximumScore) {
self::$overallMaximumScore = $maximumScore;
}
$filter = new Filter;
$mode = $query->getFilterMode();
$ratio = $query->getFilterRatio();
$documents = $filter->filterDocuments($documents, self::$overallMaximumScore, $ratio, $mode);
parent::__construct($value, $numFound, $start, $documents);
}
/**
* Get all documents, apply filter at first use
*
* @return array
*/
public function getDocuments()
{
if (!$this->filtered) {
$filter = new Filter;
$this->documents = $filter->filterDocuments($this->documents, self::$overallMaximumScore, $this->filterRatio, $this->filterMode);
$this->filtered = true;
}
return $this->documents;
}
}
......@@ -166,7 +166,7 @@ class QueryGroup implements \IteratorAggregate, \Countable
*/
public function getIterator()
{
return new \ArrayIterator($this->documents);
return new \ArrayIterator($this->getDocuments());
}
/**
......@@ -176,6 +176,6 @@ class QueryGroup implements \IteratorAggregate, \Countable
*/
public function count()
{
return count($this->documents);
return count($this->getDocuments());
}
}
......@@ -164,7 +164,7 @@ class ValueGroup implements \IteratorAggregate, \Countable
*/
public function getIterator()
{
return new \ArrayIterator($this->documents);
return new \ArrayIterator($this->getDocuments());
}
/**
......@@ -174,6 +174,6 @@ class ValueGroup implements \IteratorAggregate, \Countable
*/
public function count()
{
return count($this->documents);
return count($this->getDocuments());
}
}
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