Executes the search.
If not already done, this executes the first pass query. Then the complex conditions are applied to the query including score expressions and ordering.
FALSE if the first pass query returned no results, and a database result set if there were results.
Overrides SelectExtender::execute
public function execute() {
if (!$this->executedFirstPass) {
$this
->executeFirstPass();
}
if (!$this->normalize) {
return new StatementEmpty();
}
// Add conditions to query.
$this
->join('search_dataset', 'd', 'i.sid = d.sid AND i.type = d.type');
$this
->condition($this->conditions);
if (empty($this->scores)) {
// Add default score.
$this
->addScore('i.relevance');
}
if (count($this->multiply)) {
// Add the total multiplicator as many times as requested to maintain
// normalization as far as possible.
$i = 0;
$sum = array_sum($this->multiply);
foreach ($this->multiply as $total) {
$this->scoresArguments[':total_' . $i] = $sum;
$i++;
}
}
// Replace i.relevance pseudo-field with the actual, normalized value.
$this->scores = str_replace('i.relevance', '(' . 1.0 / $this->normalize . ' * i.score * t.count)', $this->scores);
// Convert scores to an expression.
$this
->addExpression('SUM(' . implode(' + ', $this->scores) . ')', 'calculated_score', $this->scoresArguments);
if (count($this
->getOrderBy()) == 0) {
// Add default order after adding the expression.
$this
->orderBy('calculated_score', 'DESC');
}
// Add tag and useful metadata.
$this
->addTag('search_' . $this->type)
->addMetaData('normalize', $this->normalize)
->fields('i', array(
'type',
'sid',
));
return $this->query
->execute();
}