/** * {@inheritdoc} */ public function query($group_by = FALSE) { $required = FALSE; $this->queryParseSearchExpression($this->argument); if (!isset($this->searchQuery)) { $required = TRUE; } else { $words = $this->searchQuery->words(); if (empty($words)) { $required = TRUE; } } if ($required) { if ($this->operator == 'required') { $this->query->addWhere(0, 'FALSE'); } } else { $search_index = $this->ensureMyTable(); $search_condition = db_and(); // Create a new join to relate the 'search_total' table to our current 'search_index' table. $definition = array('table' => 'search_total', 'field' => 'word', 'left_table' => $search_index, 'left_field' => 'word'); $join = Views::pluginManager('join')->createInstance('standard', $definition); $search_total = $this->query->addRelationship('search_total', $join, $search_index); // Add the search score field to the query. $this->search_score = $this->query->addField('', "{$search_index}.score * {$search_total}.count", 'score', array('function' => 'sum')); // Add the conditions set up by the search query to the views query. $search_condition->condition("{$search_index}.type", $this->searchType); $search_dataset = $this->query->addTable('node_search_dataset'); $conditions = $this->searchQuery->conditions(); $condition_conditions =& $conditions->conditions(); foreach ($condition_conditions as $key => &$condition) { // Make sure we just look at real conditions. if (is_numeric($key)) { // Replace the conditions with the table alias of views. $this->searchQuery->conditionReplaceString('d.', "{$search_dataset}.", $condition); } } $search_conditions =& $search_condition->conditions(); $search_conditions = array_merge($search_conditions, $condition_conditions); // Add the keyword conditions, as is done in // SearchQuery::prepareAndNormalize(), but simplified because we are // only concerned with relevance ranking so we do not need to normalize. $or = db_or(); foreach ($words as $word) { $or->condition("{$search_index}.word", $word); } $search_condition->condition($or); // Add the GROUP BY and HAVING expressions to the query. $this->query->addWhere(0, $search_condition); $this->query->addGroupBy("{$search_index}.sid"); $matches = $this->searchQuery->matches(); $placeholder = $this->placeholder(); $this->query->addHavingExpression(0, "COUNT(*) >= {$placeholder}", array($placeholder => $matches)); } // Set to NULL to prevent PDO exception when views object is cached // and to clear out memory. $this->searchQuery = NULL; }
/** * {@inheritdoc} */ public function query($group_by = FALSE) { $required = FALSE; $this->queryParseSearchExpression($this->argument); if (!isset($this->searchQuery)) { $required = TRUE; } else { $words = $this->searchQuery->words(); if (empty($words)) { $required = TRUE; } } if ($required) { if ($this->operator == 'required') { $this->query->addWhere(0, 'FALSE'); } } else { $search_index = $this->ensureMyTable(); $search_condition = db_and(); // Create a new join to relate the 'search_total' table to our current 'search_index' table. $definition = array('table' => 'search_total', 'field' => 'word', 'left_table' => $search_index, 'left_field' => 'word'); $join = Views::pluginManager('join')->createInstance('standard', $definition); $search_total = $this->query->addRelationship('search_total', $join, $search_index); $this->search_score = $this->query->addField('', "SUM({$search_index}.score * {$search_total}.count)", 'score', array('aggregate' => TRUE)); $search_condition->condition("{$search_index}.type", $this->searchType); if (!$this->searchQuery->simple()) { $search_dataset = $this->query->addTable('search_dataset'); $conditions = $this->searchQuery->conditions(); $condition_conditions =& $conditions->conditions(); foreach ($condition_conditions as $key => &$condition) { // Make sure we just look at real conditions. if (is_numeric($key)) { // Replace the conditions with the table alias of views. $this->searchQuery->conditionReplaceString('d.', "{$search_dataset}.", $condition); } } $search_conditions =& $search_condition->conditions(); $search_conditions = array_merge($search_conditions, $condition_conditions); } else { // Stores each condition, so and/or on the filter level will still work. $or = db_or(); foreach ($words as $word) { $or->condition("{$search_index}.word", $word); } $search_condition->condition($or); } $this->query->addWhere(0, $search_condition); $this->query->addGroupBy("{$search_index}.sid"); $matches = $this->searchQuery->matches(); $placeholder = $this->placeholder(); $this->query->addHavingExpression(0, "COUNT(*) >= {$placeholder}", array($placeholder => $matches)); } // Set to NULL to prevent PDO exception when views object is cached // and to clear out memory. $this->searchQuery = NULL; }
/** * {@inheritdoc} */ public function query() { // Since attachment views don't validate the exposed input, parse the search // expression if required. if (!$this->parsed) { $this->queryParseSearchExpression($this->value); } $required = FALSE; if (!isset($this->searchQuery)) { $required = TRUE; } else { $words = $this->searchQuery->words(); if (empty($words)) { $required = TRUE; } } if ($required) { if ($this->operator == 'required') { $this->query->addWhere($this->options['group'], 'FALSE'); } } else { $search_index = $this->ensureMyTable(); $search_condition = db_and(); // Create a new join to relate the 'search_total' table to our current // 'search_index' table. $definition = array('table' => 'search_total', 'field' => 'word', 'left_table' => $search_index, 'left_field' => 'word'); $join = Views::pluginManager('join')->createInstance('standard', $definition); $search_total = $this->query->addRelationship('search_total', $join, $search_index); $this->search_score = $this->query->addField('', "{$search_index}.score * {$search_total}.count", 'score', array('function' => 'sum')); $search_condition->condition("{$search_index}.type", $this->searchType); $search_dataset = $this->query->addTable('node_search_dataset'); $conditions = $this->searchQuery->conditions(); $condition_conditions =& $conditions->conditions(); foreach ($condition_conditions as $key => &$condition) { // Make sure we just look at real conditions. if (is_numeric($key)) { // Replace the conditions with the table alias of views. $this->searchQuery->conditionReplaceString('d.', "{$search_dataset}.", $condition); } } $search_conditions =& $search_condition->conditions(); $search_conditions = array_merge($search_conditions, $condition_conditions); $this->query->addWhere($this->options['group'], $search_condition); $this->query->addGroupBy("{$search_index}.sid"); $matches = $this->searchQuery->matches(); $placeholder = $this->placeholder(); $this->query->addHavingExpression($this->options['group'], "COUNT(*) >= {$placeholder}", array($placeholder => $matches)); } // Set to NULL to prevent PDO exception when views object is cached. $this->searchQuery = NULL; }