1 search.extender.inc public SearchQuery::executeFirstPass()

Executes the first pass query.

This can either be done explicitly, so that additional scores and conditions can be applied to the second pass query, or implicitly by addScore() or execute().

Return value

TRUE if search items exist, FALSE if not.:


core/modules/search/search.extender.inc, line 342
Search query extender and helper functions.


Do a query on the full-text search index for a word or words.


public function executeFirstPass() {
  $search_settings_config = config('search.settings');

  if (count($this->words) == 0) {
    form_set_error('keys', format_plural($search_settings_config->get('search_minimum_word_size'), 'You must include at least one keyword to match in the content. Keyword must be at least 1 character, and punctuation is ignored.', 'You must include at least one keyword to match in the content. Keywords must be at least @count characters, and punctuation is ignored.'));
    return FALSE;
  if ($this->expressionsIgnored) {
    backdrop_set_message(t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', array('@count' => $search_settings_config->get('search_and_or_limit'))), 'warning');
  $this->executedFirstPass = TRUE;

  if (!empty($this->words)) {
    $or = db_or();
    foreach ($this->words as $word) {
      $or->condition('i.word', $word);
  // Build query for keyword normalization.
  $this->join('search_total', 't', 'i.word = t.word');
  ->condition('i.type', $this->type)
    ->having('COUNT(*) >= :matches', array(':matches' => $this->matches));

  // Clone the query object to do the firstPass query;
  $first = clone $this->query;

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

  // Calculate maximum keyword relevance, to normalize it.
  $first->addExpression('SUM(i.score * t.count)', 'calculated_score');
  $this->normalize = $first
  ->range(0, 1)
    ->orderBy('calculated_score', 'DESC')

  if ($this->normalize) {
    return TRUE;
  return FALSE;