Commit bb2efca8 authored by xjm's avatar xjm

Revert "Issue #2664530 by Lendude: Views Combined fields filter with "Contains...

Revert "Issue #2664530 by Lendude: Views Combined fields filter with "Contains any word"  or "Contains all words" operator results in an incorrect SQL query and a fatal error"

This reverts commit a64ea9d3.
parent 68649cf8
......@@ -138,38 +138,6 @@ protected function opContains($expression) {
$this->query->addWhereExpression($this->options['group'], "$expression LIKE $placeholder", array($placeholder => '%' . db_like($this->value) . '%'));
}
/**
* Filters by one or more words.
*
* By default opContainsWord uses add_where, that doesn't support complex
* expressions.
*
* @param string $expression
*/
protected function opContainsWord($expression) {
$placeholder = $this->placeholder();
// Don't filter on empty strings.
if (empty($this->value)) {
return;
}
// Match all words separated by spaces or sentences when encapsulated by
// double quotes.
preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $this->value, $matches, PREG_SET_ORDER);
// Switch between the 'word' and 'allwords' operator.
$type = $this->operator == 'word' ? 'OR' : 'AND';
$group = $this->query->setWhereGroup($type);
foreach ($matches as $match_key => $match) {
$temp_placeholder = $placeholder . '_' . $match_key;
// Clean up the user input and remove the sentence delimiters.
$word = trim($match[2], ',?!();:-"');
$this->query->addWhereExpression($group, "$expression LIKE $temp_placeholder", array($temp_placeholder => '%' . db_like($word) . '%'));
}
}
protected function opStartsWith($expression) {
$placeholder = $this->placeholder();
$this->query->addWhereExpression($this->options['group'], "$expression LIKE $placeholder", array($placeholder => db_like($this->value) . '%'));
......
......@@ -95,101 +95,6 @@ public function testFilterCombineContains() {
$this->assertIdenticalResultset($view, $resultset, $this->columnMap);
}
/**
* Tests the Combine field filter with the 'word' operator.
*/
public function testFilterCombineWord() {
$view = Views::getView('test_view');
$view->setDisplay();
$fields = $view->displayHandlers->get('default')->getOption('fields');
$view->displayHandlers->get('default')->overrideOption('fields', $fields + array(
'job' => array(
'id' => 'job',
'table' => 'views_test_data',
'field' => 'job',
'relationship' => 'none',
),
));
// Change the filtering.
$view->displayHandlers->get('default')->overrideOption('filters', array(
'age' => array(
'id' => 'combine',
'table' => 'views',
'field' => 'combine',
'relationship' => 'none',
'operator' => 'word',
'fields' => array(
'name',
'job',
),
'value' => 'singer ringo',
),
));
$this->executeView($view);
$resultset = array(
array(
'name' => 'John',
'job' => 'Singer',
),
array(
'name' => 'George',
'job' => 'Singer',
),
array(
'name' => 'Ringo',
'job' => 'Drummer',
),
);
$this->assertIdenticalResultset($view, $resultset, $this->columnMap);
}
/**
* Tests the Combine field filter with the 'allwords' operator.
*/
public function testFilterCombineAllWords() {
$view = Views::getView('test_view');
$view->setDisplay();
$fields = $view->displayHandlers->get('default')->getOption('fields');
$view->displayHandlers->get('default')->overrideOption('fields', $fields + array(
'job' => array(
'id' => 'job',
'table' => 'views_test_data',
'field' => 'job',
'relationship' => 'none',
),
));
// Set the filtering to allwords and simulate searching for a phrase.
$view->displayHandlers->get('default')->overrideOption('filters', array(
'age' => array(
'id' => 'combine',
'table' => 'views',
'field' => 'combine',
'relationship' => 'none',
'operator' => 'allwords',
'fields' => array(
'name',
'job',
'age',
),
'value' => '25 "john singer"',
),
));
$this->executeView($view);
$resultset = array(
array(
'name' => 'John',
'job' => 'Singer',
),
);
$this->assertIdenticalResultset($view, $resultset, $this->columnMap);
}
/**
* Tests if the filter can handle removed fields.
*
......
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