EBernhardson has uploaded a new change for review.

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

Change subject: Update did_you_mean features to run against api
......................................................................

Update did_you_mean features to run against api

This on also required a few tweaks to ApiQuerySearch in mw core, to
provide the highlighted suggestions.  Ibf189057 needs to be merged
before these tests will pass.

Change-Id: Ia3a945f76a6fd2bb472246b6a7c0b57f2b42b2df
---
M tests/browser/features/did_you_mean_api.feature
D tests/browser/features/did_you_mean_browser.feature
M tests/browser/features/step_definitions/search_steps.rb
M tests/browser/features/support/cirrus_search_api_helper.rb
4 files changed, 41 insertions(+), 42 deletions(-)


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

diff --git a/tests/browser/features/did_you_mean_api.feature 
b/tests/browser/features/did_you_mean_api.feature
index 1dcccd9..8b5e51c 100644
--- a/tests/browser/features/did_you_mean_api.feature
+++ b/tests/browser/features/did_you_mean_api.feature
@@ -4,6 +4,10 @@
     When I api search for nobel prize
     Then there is no api suggestion
 
+  Scenario: No suggestions on pages that are not the first
+    When I api search with offset 20 for popular cultur
+    Then there is no api suggestion
+
   @stemming
   Scenario: Suggestions do not show up when a full title matches but with 
stemming
     When I api search for stemmingsingleword
@@ -22,3 +26,31 @@
   Scenario: Suggestions don't come from redirect titles when it matches an 
actual title
     When I api search for Noble Gasses
     Then there is no api suggestion
+
+  Scenario: Common phrases spelled incorrectly get suggestions
+    When I api search for popular cultur
+    Then popular *culture* is suggested by api
+
+  Scenario: Uncommon phrases spelled incorrectly get suggestions even if they 
contain words that are spelled correctly on their own
+    When I api search for noble prize
+    Then *nobel* prize is suggested by api
+
+  Scenario: Suggestions can come from redirect titles when redirects are 
included in search
+    When I api search for Rrr Worrd
+    Then rrr *word* is suggested by api
+
+  Scenario Outline: Special search syntax is preserved in suggestions (though 
sometimes moved around)
+    When I api search for <term>
+    Then <suggested> is suggested by api
+  Examples:
+    |                    term                   |                  suggested   
               |
+    | prefer-recent:noble prize                 | prefer-recent:*nobel* prize  
               |
+    | Template:nobel piep                       | Template:*noble pipe*        
               |
+    | prefer-recent:noble prize                 | prefer-recent:*nobel* prize  
               |
+    | incategory:prize noble prize              | incategory:prize *nobel* 
prize              |
+    | noble incategory:prize prize              | incategory:prize *nobel* 
prize              |
+    | hastemplate:prize noble prize             | hastemplate:prize *nobel* 
prize             |
+    | -hastemplate:prize noble prize            | -hastemplate:prize *nobel* 
prize            |
+    | boost-templates:"prize\|150%" noble prize | 
boost-templates:"prize\|150%" *nobel* prize |
+    | noble prize prefix:n                      | *nobel* prize prefix:n       
               |
+
diff --git a/tests/browser/features/did_you_mean_browser.feature 
b/tests/browser/features/did_you_mean_browser.feature
deleted file mode 100644
index a0c03a5..0000000
--- a/tests/browser/features/did_you_mean_browser.feature
+++ /dev/null
@@ -1,36 +0,0 @@
-@clean @phantomjs @suggestions
-Feature: Did you mean
-  Background:
-    Given I am at a random page
-
-  Scenario: Common phrases spelled incorrectly get suggestions
-    When I search for popular cultur
-    Then popular *culture* is suggested
-
-  Scenario: No suggestions on pages that are not the first
-    When I search for popular cultur
-    And I jump to offset 20 then
-    Then there is no suggestion
-
-  Scenario: Uncommon phrases spelled incorrectly get suggestions even if they 
contain words that are spelled correctly on their own
-    When I search for noble prize
-    Then *nobel* prize is suggested
-
-  Scenario: Suggestions can come from redirect titles when redirects are 
included in search
-    When I search for Rrr Worrd
-    Then rrr *word* is suggested
-
-  Scenario Outline: Special search syntax is preserved in suggestions (though 
sometimes moved around)
-    When I search for <term>
-    Then <suggested> is suggested
-  Examples:
-    |                    term                   |                  suggested   
               |
-    | prefer-recent:noble prize                 | prefer-recent:*nobel* prize  
               |
-    | Template:nobel piep                       | Template:*noble pipe*        
               |
-    | prefer-recent:noble prize                 | prefer-recent:*nobel* prize  
               |
-    | incategory:prize noble prize              | incategory:prize *nobel* 
prize              |
-    | noble incategory:prize prize              | incategory:prize *nobel* 
prize              |
-    | hastemplate:prize noble prize             | hastemplate:prize *nobel* 
prize             |
-    | -hastemplate:prize noble prize            | -hastemplate:prize *nobel* 
prize            |
-    | boost-templates:"prize\|150%" noble prize | 
boost-templates:"prize\|150%" *nobel* prize |
-    | noble prize prefix:n                      | *nobel* prize prefix:n       
               |
diff --git a/tests/browser/features/step_definitions/search_steps.rb 
b/tests/browser/features/step_definitions/search_steps.rb
index 268468c..7da9ccf 100644
--- a/tests/browser/features/step_definitions/search_steps.rb
+++ b/tests/browser/features/step_definitions/search_steps.rb
@@ -1,12 +1,14 @@
+require "cgi"
+
 Given(/^I am at the search results page(?: with the search (.+?)(?: and the 
prefix (.+))?)?$/) do |search, prefix|
   visit(SearchResultsPage, using_params: { search: search, prefix: prefix })
 end
 When(/^I go search for (.*)$/) do |search|
   visit(SearchResultsPage, using_params: { search: search })
 end
-When(/^I api search for (.*)$/) do |search|
+When(/^I api search(?: with offset (\d+))? for (.*)?$/) do |offset, search|
   begin
-    @api_result = search_for(search)
+    @api_result = search_for(search, sroffset: offset)
   rescue MediawikiApi::ApiError => e
     @api_error = e
   end
@@ -307,7 +309,8 @@
   end
 end
 Then(/^(.*) is suggested by api$/) do |text|
-  @api_result["searchinfo"]["suggestion"].should == text
+  fixed = 
@api_result["searchinfo"]["suggestionsnippet"].gsub(/<em>(.*?)<\/em>/, '*\1*')
+  fixed.should == CGI.escapeHTML(text)
 end
 Then(/^(.*) is suggested$/) do |text|
   on(SearchResultsPage).highlighted_suggestion.should == text
diff --git a/tests/browser/features/support/cirrus_search_api_helper.rb 
b/tests/browser/features/support/cirrus_search_api_helper.rb
index fd7e2bc..8e0061c 100644
--- a/tests/browser/features/support/cirrus_search_api_helper.rb
+++ b/tests/browser/features/support/cirrus_search_api_helper.rb
@@ -25,13 +25,13 @@
   end
 
   # Search for a particular string using the api
-  def search_for(search)
-    data = api.query(
+  def search_for(search, options)
+    data = api.query(options.merge(
       list: "search",
       srsearch: search,
       srprop: 
"snippet|titlesnippet|redirectsnippet|sectionsnippet|categorysnippet|isfilematch",
       formatversion: 2
-    )
+    ))
     data["query"]
   end
 

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

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

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

Reply via email to