Page MenuHomePhabricator

Skip search tests when the search API is disabled.
Closed, ResolvedPublic

Description

Search on the Wikia website appears to work fine

http://www.wikia.com/Special:Search?search=foo&fulltext=Search
http://www.wikia.com/Special:Search?search=Seuss&fulltext=Search

But errors result from calling the api, search on text or title

http://www.wikia.com/api.php?format=jsonfm&action=query&generator=search&gsrwhat=text&gsrsearch=foo
http://www.wikia.com/api.php?format=jsonfm&action=query&generator=search&gsrwhat=title&gsrsearch=foo

But a near match search does appear to be working.

http://www.wikia.com/api.php?format=jsonfm&action=query&generator=search&gsrwhat=nearmatch&gsrsearch=wikia

but not returning results which do appear on the search page.

http://www.wikia.com/api.php?format=jsonfm&action=query&generator=search&gsrwhat=nearmatch&gsrsearch=Dr.%20Seuss%20Wiki

This is causing a test error in site_tests.SiteUserTestCase.testSearch

Traceback (most recent call last):
  File "./tests/site_tests.py", line 887, in testSearch
    se = list(mysite.search("wiki", total=100))
  File "./pywikibot/data/api.py", line 1452, in __iter__
    self.data = self.request.submit()
  File "./pywikibot/data/api.py", line 1071, in submit
    raise APIError(code, info, **result["error"])
pywikibot.data.api.APIError: gsrsearch-text-disabled: text search is disabled

The simplest fix for the test suite is to catch and detect 'gsrsearch-text-disabled' - when the API returns that error, use unittest.SkipTest to skip the test without causing a test failure.

A slightly better approach is to detect that search is disabled, like we detect whether upload is enabled in APISite.is_uploaddisabled.

Long term, if we encounter may sites which disable search, we might want to build a webpage scrapper to do the search using http://www.wikia.com/Special:Search

Event Timeline

jayvdb assigned this task to Omegat.
jayvdb raised the priority of this task from to Needs Triage.
jayvdb updated the task description. (Show Details)
jayvdb changed Security from none to None.
jayvdb added subscribers: Unknown Object (MLST), jayvdb, XZise, Grunny.
jayvdb renamed this task from Skip to Skip search tests when the search API is disabled..Dec 9 2014, 9:04 AM
jayvdb updated the task description. (Show Details)

As noted on the code review, we need to first analyse this 'what' parameter, in the MediaWiki php code, and understand how what = text or title are disabled.
http://git.wikimedia.org/blob/mediawiki%2Fcore.git/ed646ee688057e6022a00e2965f3ca7095cc9ec8/includes%2Fapi%2FApiQuerySearch.php

We done a bit of analysis and cant find the appropriate way to use feature detection. We could do dummy requests and check the response, which is what the previous changeset attempted to do, but ... a simpler approach is for the test method to use has_extension to detect extension 'WikiaSearch' and skip the test if the extension is found. We dont know for sure if that extension ( https://github.com/Wikia/app/tree/dev/extensions/wikia/Search ?) is causing the problem, but it is a decent way to detect 'wikia' without depending on the name of the family file.

To get the exact name of the extension according to the API, use the API query called 'siteinfo', and prop called 'extensions'

https://www.mediawiki.org/wiki/API:Meta#siteinfo_.2F_si

http://www.wikia.com/api.php?format=jsonfm&action=query&meta=siteinfo&siprop=extensions

Change 182359 had a related patch set uploaded (by Maverick):
Skip search test for wikia

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

Patch-For-Review

Change 182359 merged by jenkins-bot:
Skip search test for sites using Wikia Search

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

Change 180409 abandoned by Multichill:
Bug:T77968 Skip search tests if search is disabled

Reason:
No response. This can always be re-opened if you plan to work on it again.

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