Class: MediaWiktory::Wikipedia::Actions::Opensearch

Inherits:
Get
  • Object
show all
Defined in:
lib/mediawiktory/wikipedia/actions/opensearch.rb

Overview

Search the wiki using the OpenSearch protocol.

Usage:

api.opensearch.search(value).perform # returns string with raw output
# or
api.opensearch.search(value).response # returns output parsed and wrapped into Response object

See Base for generic explanation of working with MediaWiki actions and Response for working with action responses.

All action's parameters are documented as its public methods, see below.

Instance Method Summary collapse

Methods inherited from Get

#perform

Methods inherited from Base

#inspect, #merge, #name, #perform, #response, #to_h, #to_param, #to_url

Methods included from GlobalParams

#assert, #assertuser, #centralauthtoken, #curtimestamp, #errorformat, #errorlang, #errorsuselocal, #maxage, #maxlag, #origin, #requestid, #responselanginfo, #servedby, #smaxage, #uselang

Instance Method Details

#format(value) ⇒ self

The format of the output.

Parameters:

  • value (String)

    One of "json", "jsonfm", "xml", "xmlfm".

Returns:

  • (self)


88
89
90
# File 'lib/mediawiktory/wikipedia/actions/opensearch.rb', line 88

def format(value)
  _format(value) or fail ArgumentError, "Unknown value for format: #{value}"
end

#limit(value) ⇒ self

Maximum number of results to return.

Parameters:

  • value (Integer, "max")

Returns:

  • (self)


47
48
49
# File 'lib/mediawiktory/wikipedia/actions/opensearch.rb', line 47

def limit(value)
  merge(limit: value.to_s)
end

#namespace(*values) ⇒ self

Namespaces to search.

Parameters:

  • values (Array<String>)

    Allowed values: "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "100", "101", "108", "109", "118", "119", "446", "447", "710", "711", "828", "829", "2300", "2301", "2302", "2303".

Returns:

  • (self)


34
35
36
# File 'lib/mediawiktory/wikipedia/actions/opensearch.rb', line 34

def namespace(*values)
  values.inject(self) { |res, val| res._namespace(val) or fail ArgumentError, "Unknown value for namespace: #{val}" }
end

#profile(value) ⇒ self

Search profile to use.

Parameters:

  • value (String)

    One of "strict" (Strict profile with few punctuation characters removed but diacritics and stress marks are kept), "normal" (Few punctuation characters, some diacritics and stopwords removed), "fuzzy" (Similar to normal with typo correction (two typos supported)), "fast-fuzzy" (Experimental fuzzy profile (may be removed at any time)), "classic" (Classic prefix, few punctuation characters and some diacritics removed).

Returns:

  • (self)


55
56
57
# File 'lib/mediawiktory/wikipedia/actions/opensearch.rb', line 55

def profile(value)
  _profile(value) or fail ArgumentError, "Unknown value for profile: #{value}"
end

#redirects(value) ⇒ self

How to handle redirects:

Parameters:

  • value (String)

    One of "return" (Return the redirect itself), "resolve" (Return the target page. May return fewer than limit results).

Returns:

  • (self)


75
76
77
# File 'lib/mediawiktory/wikipedia/actions/opensearch.rb', line 75

def redirects(value)
  _redirects(value) or fail ArgumentError, "Unknown value for redirects: #{value}"
end

#search(value) ⇒ self

Search string.

Parameters:

  • value (String)

Returns:

  • (self)


26
27
28
# File 'lib/mediawiktory/wikipedia/actions/opensearch.rb', line 26

def search(value)
  merge(search: value.to_s)
end

#suggestself

Do nothing if $wgEnableOpenSearchSuggest is false.

Returns:

  • (self)


67
68
69
# File 'lib/mediawiktory/wikipedia/actions/opensearch.rb', line 67

def suggest()
  merge(suggest: 'true')
end

#warningsaserrorself

If warnings are raised with format=json, return an API error instead of ignoring them.

Returns:

  • (self)


100
101
102
# File 'lib/mediawiktory/wikipedia/actions/opensearch.rb', line 100

def warningsaserror()
  merge(warningsaserror: 'true')
end