summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoridebr2018-02-18 20:32:55 (GMT)
committerThomas Seidl2018-02-18 20:32:55 (GMT)
commit1a72199abeb4a2a4536b1571df9323dbbb5d1846 (patch)
tree4f4232c00c9c59834e01986067f9ae411927fa15
parentd4ea5b1290d72366914f0e34a11763390715d420 (diff)
Issue #2942846 by idebr, drunken monkey, borisson_: Added empty/not empty operators to Views fulltext field filters.
-rw-r--r--CHANGELOG.txt2
-rw-r--r--src/Plugin/views/filter/SearchApiText.php8
-rw-r--r--tests/search_api_test_views/config/install/views.view.search_api_test_view.yml25
-rw-r--r--tests/src/Functional/ViewsTest.php18
4 files changed, 52 insertions, 1 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 25f78d6..975aa04 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,5 +1,7 @@
Search API 1.x, dev (xxxx-xx-xx):
---------------------------------
+- #2942846 by idebr, drunken monkey, borisson_: Added empty/not empty operators
+ to Views fulltext field filters.
- #2940255 by drunken monkey: Updated the DB autocomplete implementation to the
stable API version.
- #2938646 by drunken monkey, Johnny vd Laar: Fixed item-boosts in database
diff --git a/src/Plugin/views/filter/SearchApiText.php b/src/Plugin/views/filter/SearchApiText.php
index a306990..aff9698 100644
--- a/src/Plugin/views/filter/SearchApiText.php
+++ b/src/Plugin/views/filter/SearchApiText.php
@@ -20,7 +20,13 @@ class SearchApiText extends SearchApiString {
$operators['=']['title'] = $this->t('contains');
$operators['!=']['title'] = $this->t("doesn't contain");
- $operators = array_intersect_key($operators, ['=' => 1, '!=' => 1]);
+ $supported_operators = [
+ '=' => 1,
+ '!=' => 1,
+ 'empty' => 1,
+ 'not empty' => 1,
+ ];
+ $operators = array_intersect_key($operators, $supported_operators);
return $operators;
}
diff --git a/tests/search_api_test_views/config/install/views.view.search_api_test_view.yml b/tests/search_api_test_views/config/install/views.view.search_api_test_view.yml
index 7823869..98df161 100644
--- a/tests/search_api_test_views/config/install/views.view.search_api_test_view.yml
+++ b/tests/search_api_test_views/config/install/views.view.search_api_test_view.yml
@@ -176,6 +176,31 @@ display:
anonymous: '0'
administrator: '0'
is_grouped: false
+ name:
+ plugin_id: search_api_text
+ id: name
+ table: search_api_index_database_search_index
+ field: name
+ relationship: none
+ admin_label: ''
+ operator: '='
+ group: 1
+ exposed: true
+ expose:
+ operator_id: name_op
+ label: ''
+ description: ''
+ use_operator: true
+ operator: name_op
+ identifier: name
+ required: false
+ remember: false
+ multiple: false
+ remember_roles:
+ authenticated: authenticated
+ anonymous: '0'
+ administrator: '0'
+ is_grouped: false
search_api_language:
plugin_id: search_api_language
id: search_api_language
diff --git a/tests/src/Functional/ViewsTest.php b/tests/src/Functional/ViewsTest.php
index 0048b90..4a1106f 100644
--- a/tests/src/Functional/ViewsTest.php
+++ b/tests/src/Functional/ViewsTest.php
@@ -198,6 +198,24 @@ class ViewsTest extends SearchApiBrowserTestBase {
$this->checkResults($query, [1, 2, 4, 5], 'Search with Keywords "not empty" filter');
$query = [
+ 'name[value]' => 'foo',
+ ];
+ $this->checkResults($query, [1, 2, 4], 'Search with Name "contains" filter');
+ $query = [
+ 'name[value]' => 'foo',
+ 'name_op' => '!=',
+ ];
+ $this->checkResults($query, [3, 5], 'Search with Name "doesn\'t contain" filter');
+ $query = [
+ 'name_op' => 'empty',
+ ];
+ $this->checkResults($query, [], 'Search with Name "empty" filter');
+ $query = [
+ 'name_op' => 'not empty',
+ ];
+ $this->checkResults($query, [1, 2, 3, 4, 5], 'Search with Name "not empty" filter');
+
+ $query = [
'language' => ['***LANGUAGE_site_default***'],
];
$this->checkResults($query, [1, 2, 3, 4, 5], 'Search with "Page content language" filter');