You are here

public function FacetapiQuery::execute in Faceted Navigation for Search 7

Executes a facet query.

Overrides SearchQuery::execute


./, line 58
Facet query builder, strips all scoring from the SearchQuery class.


Extension of the SearchQuery class.


public function execute() {

  // Adds OR conditions.
  if (!empty($this->words)) {
    $or = db_or();
    foreach ($this->words as $word) {
        ->condition('i.word', $word);

  // Build query for keyword normalization.
    ->join('search_total', 't', 'i.word = t.word');
    ->condition('i.type', $this->type)
    ->having('COUNT(*) >= :matches', array(
    ':matches' => $this->matches,

  // For complex search queries, add the LIKE conditions.
  if (!$this->simple) {
      ->join('search_dataset', 'd', 'i.sid = d.sid AND i.type = d.type');

  // Add conditions to query.
    ->join('search_dataset', 'd', 'i.sid = d.sid AND i.type = d.type');

  // Add tag and useful metadata.
    ->addTag('search_' . $this->type)
    ->addMetaData('normalize', $this->normalize);

  // Adds subquery to group the results in the r table.
  $subquery = db_select($this->query, 'r')
    ->fields('r', array(
    ->orderBy('count', 'DESC');

  // Adds COUNT() expression to get facet counts.
    ->addExpression('COUNT(r.value)', 'count');

  // Executes the subquery.
  return $subquery