Manybubbles has uploaded a new change for review.

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


Change subject: Allow old boolean operators.
......................................................................

Allow old boolean operators.

We have escape some of them anyway if they are used wrong, but that
isn't too bad.

Bug: 56026
Change-Id: Iaeedda690b321b1282d9a36505823fa9ab851796
---
M includes/CirrusSearchSearcher.php
1 file changed, 16 insertions(+), 10 deletions(-)


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

diff --git a/includes/CirrusSearchSearcher.php 
b/includes/CirrusSearchSearcher.php
index 86f2d93..2615de7 100644
--- a/includes/CirrusSearchSearcher.php
+++ b/includes/CirrusSearchSearcher.php
@@ -478,24 +478,20 @@
         * extra index for.
         * ": Perform a phrase search for the quoted term.  If the "s aren't 
balanced we insert one
         * at the end of the term to make sure elasticsearch doesn't barf at us.
+        * +/-/!/||/&&: Symbols meaning AND, NOT, NOT, OR, and AND 
respectively.  - was supported by
+        * LuceneSearch so we need to allow that one but there is no reason not 
to allow them all.
         */
        public static function fixupQueryString( $string ) {
                wfProfileIn( __METHOD__ );
                $string = preg_replace( '/(
-                               \+|
-                               -|
                                \/|             (?# no regex searches allowed)
-                               &&|
-                               \|\||
-                               !|
-                               \(|
+                               \(|     (?# no user supplied groupings)
                                \)|
-                               \{|
+                               \{|     (?# no exclusive range queries)
                                }|
-                               \[|
+                               \[|     (?# no inclusive range queries either)
                                ]|
-                               \^|
-                               \?|
+                               \^|     (?# no user supplied boosts at this 
point, though I cant think why)
                                :|              (?# no specifying your own 
fields)
                                \\\
                        )/x', '\\\$1', $string );
@@ -535,10 +531,20 @@
                                return '"\\~' . $matches[ 'trailing' ];
                        }
                }, $string );
+               // Escape +, -, and ! when not followed immediately by a term.
+               $string = preg_replace( '/(?:\\+|\\-|\\!)(?:\s|$)/', '\\\\$0', 
$string );
+               // 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( '/(?:AND|OR|NOT)\s*$/', 
'CirrusSearchSearcher::lowercaseMatched', $string );
+               $string = preg_replace_callback( '/^\s*(?:AND|OR)/', 
'CirrusSearchSearcher::lowercaseMatched', $string );
                wfProfileOut( __METHOD__ );
                return $string;
        }
 
+       private static function lowercaseMatched( $matches ) {
+               return strtolower( $matches[ 0 ] );
+       }
+
        /**
         * Wrap query in link based boosts.
         * @param $query null|Elastica\Query optional query to boost.  if null 
the match_all is assumed

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaeedda690b321b1282d9a36505823fa9ab851796
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to