EBernhardson has uploaded a new change for review.

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

Change subject: Remove support for float fuzziness
......................................................................

Remove support for float fuzziness

Float fuzziness was removed in lucene 5, so we can no longer support it
in elasticsearch 2.x.

Bug: T133750
Change-Id: I05aa297465451bcbc6564845fb4cd1eb9c0c0cad
---
M includes/Search/Escaper.php
M tests/browser/features/fuzzy_api.feature
M tests/unit/Search/EscaperTest.php
3 files changed, 27 insertions(+), 8 deletions(-)


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

diff --git a/includes/Search/Escaper.php b/includes/Search/Escaper.php
index 2d20fd3..e02ac9c 100644
--- a/includes/Search/Escaper.php
+++ b/includes/Search/Escaper.php
@@ -123,7 +123,7 @@
                $fuzzyQuery = false;
                $string = preg_replace_callback( 
'/(?<leading>\w)~(?<trailing>\S*)/u',
                        function ( $matches ) use ( &$fuzzyQuery ) {
-                               if ( preg_match( 
'/^(?:|0|0?\.\d+|1(?:\.0)?)$/', $matches[ 'trailing' ] ) ) {
+                               if ( preg_match( '/^(?:|0|1(?:\.0)?)$/', 
$matches[ 'trailing' ] ) ) {
                                        $fuzzyQuery = true;
                                        return $matches[ 0 ];
                                } else {
diff --git a/tests/browser/features/fuzzy_api.feature 
b/tests/browser/features/fuzzy_api.feature
index e488899..ab5aeca 100644
--- a/tests/browser/features/fuzzy_api.feature
+++ b/tests/browser/features/fuzzy_api.feature
@@ -16,12 +16,7 @@
     When I api search for ffnonesensewor~
     Then Two Words is the first api search result
 
-  Scenario Outline: Searching for <text>~<number between 0 and 1> activates 
fuzzy search
-    When I api search for ffnonesensewor~<number>
+  Scenario Outline: Searching for <text>~1 activates fuzzy search
+    When I api search for ffnonesensewor~1
     Then Two Words is the first api search result
-  Examples:
-    | number |
-    | .8     |
-    | 0.8    |
-    | 1      |
 
diff --git a/tests/unit/Search/EscaperTest.php 
b/tests/unit/Search/EscaperTest.php
index c4690a4..efe6b66 100644
--- a/tests/unit/Search/EscaperTest.php
+++ b/tests/unit/Search/EscaperTest.php
@@ -23,6 +23,30 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 class EscaperTest extends PHPUnit_Framework_TestCase {
+
+       /**
+        * @dataProvider fuzzyEscapeTestCases
+        */
+       public function testFuzzyEscape( $input, $expected, $isFuzzy ) {
+               $escaper = new Escaper( 'unittest' );
+               $actual = $escaper->fixupWholeQueryString( $input );
+               $this->assertEquals( array( $expected, $isFuzzy), $actual );
+       }
+
+       public static function fuzzyEscapeTestCases() {
+               return array(
+                       'No fuzziness is allowed' => array( 'fuzzy~0', 
'fuzzy~0', true ),
+                       'One char edit distance is allowed' => array( 
'fuzzy~1', 'fuzzy~1', true ),
+                       'Two char edit distance is disallowed' => array( 
'fuzzy~2', 'fuzzy\\~2', false ),
+                       // why? Seems like it might be a bug in Escaper
+                       'Proximity searches are disallowed' => array( 
'fuzzy~10', 'fuzzy\\~10', false ),
+                       // removed in lucene 5
+                       'Float fuzziness with leading 0 is disallowed' => 
array( 'fuzzy~0.8', 'fuzzy\\~0.8', false ),
+                       // removed in lucene 5
+                       'Float fuzziness is disallowed' => array( 'fuzzy~.8', 
'fuzzy\\~.8', false ),
+               );
+       }
+
        /**
         * @dataProvider quoteEscapeTestCases
         */

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I05aa297465451bcbc6564845fb4cd1eb9c0c0cad
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: es2.x
Gerrit-Owner: EBernhardson <[email protected]>

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

Reply via email to