You are here

class FacetapiQuery in Faceted Navigation for Search 7

Extension of the SearchQuery class.

Hierarchy

Expanded class hierarchy of FacetapiQuery

1 string reference to 'FacetapiQuery'
SearchFacetapiAdapter::getFacetQueryExtender in plugins/facetapi/adapter.inc
Sets the facet query object.

File

./search_facetapi.extender.inc, line 11
Facet query builder, strips all scoring from the SearchQuery class.

View source
class FacetapiQuery extends SearchQuery {

  /**
   * Stores joined tables.
   */
  protected $joinedTables = array();

  /**
   * Adds the facet join, but only does so once.
   *
   * @param array $query_info
   *   An associative array of query information.
   * @param $table_alias
   *   The alias of the table being joined.
   *
   *  @return FacetapiQuery
   *    An instance of this class.
   */
  public function addFacetJoin(array $query_info, $table_alias) {
    if (isset($query_info['joins'][$table_alias])) {
      if (!isset($this->joinedTables[$table_alias])) {
        $this->joinedTables[$table_alias] = TRUE;
        $join_info = $query_info['joins'][$table_alias];
        $this
          ->join($join_info['table'], $join_info['alias'], $join_info['condition']);
      }
    }
  }

  /**
   * Adds the facet field, ensures the alias is "value".
   *
   * @param array $query_info
   *   An associative array of query information.
   *
   *  @return FacetapiQuery
   *    An instance of this class.
   */
  public function addFacetField(array $query_info) {
    foreach ($query_info['fields'] as $field_info) {
      $this
        ->addField($field_info['table_alias'], $field_info['field'], 'value');
    }
    return $this;
  }

  /**
   * Executes a facet query.
   */
  public function execute() {
    $this
      ->parseSearchExpression();

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

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

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

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

    // Add tag and useful metadata.
    $this
      ->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(
      'value',
    ))
      ->groupBy('r.value')
      ->orderBy('count', 'DESC');

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

    // Executes the subquery.
    return $subquery
      ->execute();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FacetapiQuery::$joinedTables protected property Stores joined tables.
FacetapiQuery::addFacetField public function Adds the facet field, ensures the alias is "value".
FacetapiQuery::addFacetJoin public function Adds the facet join, but only does so once.
FacetapiQuery::execute public function Executes a facet query. Overrides SearchQuery::execute
SearchQuery::$conditions protected property Conditions that are used for exact searches.
SearchQuery::$executedFirstPass protected property Indicates whether the first pass query has been executed.
SearchQuery::$expressionsIgnored protected property Whether or not search expressions were ignored.
SearchQuery::$keys protected property Positive and negative search keys.
SearchQuery::$matches protected property Indicates how many matches for a search query are necessary.
SearchQuery::$multiply protected property Stores multipliers for score expressions.
SearchQuery::$normalize protected property Multiplier for the normalized search score.
SearchQuery::$scores protected property Stores score expressions.
SearchQuery::$scoresArguments protected property Stores arguments for score expressions.
SearchQuery::$searchExpression protected property The search query that is used for searching.
SearchQuery::$simple protected property Indicates whether the first pass query requires complex conditions (LIKE).
SearchQuery::$type protected property Type of search (search module).
SearchQuery::$words protected property Array of search words.
SearchQuery::addScore public function Adds a custom score expression to the search query.
SearchQuery::countQuery public function Builds the default count query for SearchQuery. Overrides SelectQueryExtender::countQuery
SearchQuery::executeFirstPass public function Executes the first pass query.
SearchQuery::parseSearchExpression protected function Parses the search query into SQL conditions.
SearchQuery::parseWord protected function Helper function for parseQuery().
SearchQuery::searchExpression public function Sets up the search query expression.
SearchQuery::setOption public function Applies a search option and removes it from the search query string.
SelectQueryExtender::$connection protected property The connection object on which to run this query.
SelectQueryExtender::$placeholder protected property The placeholder counter.
SelectQueryExtender::$query protected property The SelectQuery object we are extending/decorating.
SelectQueryExtender::$uniqueIdentifier protected property A unique identifier for this query object.
SelectQueryExtender::addExpression public function Adds an expression to the list of "fields" to be SELECTed. Overrides SelectQueryInterface::addExpression
SelectQueryExtender::addField public function Adds a field to the list to be SELECTed. Overrides SelectQueryInterface::addField
SelectQueryExtender::addJoin public function Join against another table in the database. Overrides SelectQueryInterface::addJoin
SelectQueryExtender::addMetaData public function Adds additional metadata to the query. Overrides QueryAlterableInterface::addMetaData
SelectQueryExtender::addTag public function Adds a tag to a query. Overrides QueryAlterableInterface::addTag
SelectQueryExtender::arguments public function Gets a complete list of all values to insert into the prepared statement. Overrides QueryConditionInterface::arguments
SelectQueryExtender::compile public function Compiles the saved conditions for later retrieval. Overrides QueryConditionInterface::compile
SelectQueryExtender::compiled public function Check whether a condition has been previously compiled. Overrides QueryConditionInterface::compiled
SelectQueryExtender::condition public function Helper function: builds the most common conditional clauses. Overrides QueryConditionInterface::condition
SelectQueryExtender::conditions public function Gets a complete list of all conditions in this conditional clause. Overrides QueryConditionInterface::conditions
SelectQueryExtender::distinct public function Sets this query to be DISTINCT. Overrides SelectQueryInterface::distinct
SelectQueryExtender::exists public function Sets a condition that the specified subquery returns values. Overrides QueryConditionInterface::exists
SelectQueryExtender::extend public function Enhance this object by wrapping it in an extender object. Overrides QueryExtendableInterface::extend
SelectQueryExtender::fields public function Add multiple fields from the same table to be SELECTed. Overrides SelectQueryInterface::fields
SelectQueryExtender::forUpdate public function Add FOR UPDATE to the query. Overrides SelectQueryInterface::forUpdate
SelectQueryExtender::getArguments public function Compiles and returns an associative array of the arguments for this prepared statement. Overrides SelectQueryInterface::getArguments
SelectQueryExtender::getExpressions public function Returns a reference to the expressions array for this query. Overrides SelectQueryInterface::getExpressions
SelectQueryExtender::getFields public function Returns a reference to the fields array for this query. Overrides SelectQueryInterface::getFields
SelectQueryExtender::getGroupBy public function Returns a reference to the group-by array for this query. Overrides SelectQueryInterface::getGroupBy
SelectQueryExtender::getMetaData public function Retrieves a given piece of metadata. Overrides QueryAlterableInterface::getMetaData
SelectQueryExtender::getOrderBy public function Returns a reference to the order by array for this query. Overrides SelectQueryInterface::getOrderBy
SelectQueryExtender::getTables public function Returns a reference to the tables array for this query. Overrides SelectQueryInterface::getTables
SelectQueryExtender::getUnion public function Returns a reference to the union queries for this query. This include queries for UNION, UNION ALL, and UNION DISTINCT. Overrides SelectQueryInterface::getUnion
SelectQueryExtender::groupBy public function Groups the result set by the specified field. Overrides SelectQueryInterface::groupBy
SelectQueryExtender::hasAllTags public function Determines if a given query has all specified tags. Overrides QueryAlterableInterface::hasAllTags
SelectQueryExtender::hasAnyTag public function Determines if a given query has any specified tag. Overrides QueryAlterableInterface::hasAnyTag
SelectQueryExtender::hasTag public function Determines if a given query has a given tag. Overrides QueryAlterableInterface::hasTag
SelectQueryExtender::having public function
SelectQueryExtender::havingArguments public function
SelectQueryExtender::havingCompile public function
SelectQueryExtender::havingCondition public function Helper function to build most common HAVING conditional clauses. Overrides SelectQueryInterface::havingCondition
SelectQueryExtender::havingConditions public function
SelectQueryExtender::innerJoin public function Inner Join against another table in the database. Overrides SelectQueryInterface::innerJoin
SelectQueryExtender::isNotNull function Sets a condition that the specified field be NOT NULL. Overrides QueryConditionInterface::isNotNull
SelectQueryExtender::isNull function Sets a condition that the specified field be NULL. Overrides QueryConditionInterface::isNull
SelectQueryExtender::isPrepared public function Indicates if preExecute() has already been called on that object. Overrides SelectQueryInterface::isPrepared
SelectQueryExtender::join public function Default Join against another table in the database. Overrides SelectQueryInterface::join
SelectQueryExtender::leftJoin public function Left Outer Join against another table in the database. Overrides SelectQueryInterface::leftJoin
SelectQueryExtender::nextPlaceholder public function Implements QueryPlaceholderInterface::nextPlaceholder(). Overrides QueryPlaceholderInterface::nextPlaceholder
SelectQueryExtender::notExists public function Sets a condition that the specified subquery returns no values. Overrides QueryConditionInterface::notExists
SelectQueryExtender::orderBy public function Orders the result set by a given field. Overrides SelectQueryInterface::orderBy
SelectQueryExtender::orderRandom public function Orders the result set by a random value. Overrides SelectQueryInterface::orderRandom
SelectQueryExtender::preExecute public function Generic preparation and validation for a SELECT query. Overrides SelectQueryInterface::preExecute
SelectQueryExtender::range public function Restricts a query to a given range in the result set. Overrides SelectQueryInterface::range
SelectQueryExtender::rightJoin public function Right Outer Join against another table in the database. Overrides SelectQueryInterface::rightJoin
SelectQueryExtender::union public function Add another Select query to UNION to this one. Overrides SelectQueryInterface::union
SelectQueryExtender::uniqueIdentifier public function Implements QueryPlaceholderInterface::uniqueIdentifier(). Overrides QueryPlaceholderInterface::uniqueIdentifier
SelectQueryExtender::where public function Adds an arbitrary WHERE clause to the query. Overrides QueryConditionInterface::where
SelectQueryExtender::__call public function Magic override for undefined methods.
SelectQueryExtender::__clone public function Clone magic method. Overrides SelectQueryInterface::__clone
SelectQueryExtender::__construct public function 2
SelectQueryExtender::__toString public function