Commit 24dca837 authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1760748 by dawehner, aspilicious: Move ViewsSearchQuery.

parent 336e2e10
<?php
/**
* @file
* Definition of Drupal\views\Search\ViewsSearchQuery.
*/
namespace Drupal\search;
/**
* Extends the core SearchQuery.
*
* @todo: Make this class PSR-0 compatible.
* Extends the core SearchQuery to be able to gets it's protected values.
*/
class ViewsSearchQuery extends SearchQuery {
/**
* Returns the conditions property.
*
* @return array
*/
public function &conditions() {
return $this->conditions;
}
/**
* Returns the words property.
*
* @return array
*/
public function words() {
return $this->words;
}
/**
* Returns the simple property.
*
* @return bool
*/
public function simple() {
return $this->simple;
}
/**
* Returns the matches property.
*
* @return int
*/
public function matches() {
return $this->matches;
}
/**
* Executes and returns the protected parseSearchExpression method.
*/
public function publicParseSearchExpression() {
return $this->parseSearchExpression();
}
/**
* Replaces the original condition with a custom one from views recursively.
*
* @param string $search
* The searched value.
* @param string $replace
* The value which replaces the search value.
* @param Drupal\Core\Database\Query\Condition $condition
* The query condition in which the string is replaced.
*/
function condition_replace_string($search, $replace, &$condition) {
if ($condition['field'] instanceof DatabaseCondition) {
$conditions =& $condition['field']->conditions();
foreach ($conditions as $key => &$subcondition) {
if (is_numeric($key)) {
// As conditions can have subconditions, for example db_or(), the
// function has to be called recursively.
$this->condition_replace_string($search, $replace, $subcondition);
}
}
......@@ -40,4 +80,5 @@ function condition_replace_string($search, $replace, &$condition) {
$condition['field'] = str_replace($search, $replace, $condition['field']);
}
}
}
......@@ -30,7 +30,7 @@ class Search extends ArgumentPluginBase {
*/
function query_parse_search_expression($input) {
if (!isset($this->search_query)) {
$this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('viewsSearchQuery');
$this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('Drupal\views\Search\ViewsSearchQuery');
$this->search_query->searchExpression($input, $this->view->base_table);
$this->search_query->publicParseSearchExpression();
}
......
......@@ -26,9 +26,12 @@ class Search extends FilterPluginBase {
var $always_multiple = TRUE;
/**
* Stores a viewsSearchQuery object to be able to use the search.module "api".
* Stores an extended query extender from the search module.
*
* @var viewsSearchQuery
* This value extends the query extender to be able to provide methods
* which returns the protected values.
*
* @var Drupal\views\Search\ViewsSearchQuery
*/
var $search_query = NULL;
......@@ -99,7 +102,7 @@ function exposed_validate(&$form, &$form_state) {
function query_parse_search_expression($input) {
if (!isset($this->search_query)) {
$this->parsed = TRUE;
$this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('Drupal\search\ViewsSearchQuery');
$this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('Drupal\views\Search\ViewsSearchQuery');
$this->search_query->searchExpression($input, $this->view->base_table);
$this->search_query->publicParseSearchExpression();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment