Manybubbles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/210403

Change subject: Fix errors that look like OR OR OR OR
......................................................................

Fix errors that look like OR OR OR OR

These are caused by us pulling phrase prefix queries into a, well, phrase
prefix query so they don't get to participate in OR and AND. They didn't
work before so its not _that_ bad that they don't work now. But they shouldn't
throw an error.

T94814

Change-Id: I5a77bc602469eef4c3595f448c22ce4d542da13d
---
M includes/Search/Escaper.php
M tests/browser/features/bad_syntax_api.feature
M tests/browser/features/step_definitions/search_steps.rb
3 files changed, 13 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/03/210403/1

diff --git a/includes/Search/Escaper.php b/includes/Search/Escaper.php
index 50c1a4c..9f89ca0 100644
--- a/includes/Search/Escaper.php
+++ b/includes/Search/Escaper.php
@@ -130,7 +130,7 @@
 
                // Lowercase AND and OR when not surrounded on both sides by a 
term.
                // Lowercase NOT when it doesn't have a term after it.
-               $string = preg_replace_callback( '/^\s*(?:AND|OR)/u',
+               $string = preg_replace_callback( 
'/^|(AND|OR|NOT)\s*(?:AND|OR)/u',
                        'CirrusSearch\Search\Escaper::lowercaseMatched', 
$string );
                $string = preg_replace_callback( '/(?:AND|OR|NOT)\s*$/u',
                        'CirrusSearch\Search\Escaper::lowercaseMatched', 
$string );
diff --git a/tests/browser/features/bad_syntax_api.feature 
b/tests/browser/features/bad_syntax_api.feature
index 12fa54e..98bf057 100644
--- a/tests/browser/features/bad_syntax_api.feature
+++ b/tests/browser/features/bad_syntax_api.feature
@@ -83,3 +83,12 @@
   Scenario: Searching for "<word> <word>"~<not a numer> treats the ~ as a space
     When I api search for "ffnonesenseword catapult"~anotherword
       And Two Words is the first api search result
+
+  @boolean_operators
+  Scenario Outline: ORs and ANDs around phrase prefixes finds the search terms
+    When I api search for "test catapul*" <operator> "test catapul*" 
<operator> "test catapul*"
+    Then there are no errors reported by the api
+  Examples:
+    | operator |
+    | AND      |
+    | OR       |
diff --git a/tests/browser/features/step_definitions/search_steps.rb 
b/tests/browser/features/step_definitions/search_steps.rb
index c02dd99..e6393a3 100644
--- a/tests/browser/features/step_definitions/search_steps.rb
+++ b/tests/browser/features/step_definitions/search_steps.rb
@@ -365,6 +365,9 @@
 Then(/this error is reported: (.+)$/) do |expected_error|
   on(SearchResultsPage).error_report_element.text.strip.should == 
expected_error.strip
 end
+Then(/there are no errors reported by the api$/) do
+  @api_error.should be nil
+end
 Then(/this error is reported by api: (.+)$/) do |expected_error|
   @api_error.code.should be == "srsearch-error"
   CGI.unescapeHTML(@api_error.info).should == expected_error.strip

-- 
To view, visit https://gerrit.wikimedia.org/r/210403
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5a77bc602469eef4c3595f448c22ce4d542da13d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <never...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to