Module: MediaWiktory::Wikipedia::Modules::Search

Defined in:
lib/mediawiktory/wikipedia/modules/search.rb

Overview

Perform a full text search.

The "submodule" (MediaWiki API term) is included in action after setting some param, providing additional tweaking for this param. Example (for Actions::Query and its submodules):

api.query             # returns Actions::Query
   .prop(:revisions)  # adds prop=revisions to action URL, and includes Modules::Revisions into action
   .limit(10)         # method of Modules::Revisions, adds rvlimit=10 to URL

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

Instance Method Summary collapse

Instance Method Details

#enablerewritesself

Enable internal query rewriting. Some search backends can rewrite the query into one its thinks gives better results, such as correcting spelling errors.

Returns:

  • (self)


120
121
122
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 120

def enablerewrites()
  merge(srenablerewrites: 'true')
end

#info(*values) ⇒ self

Which metadata to return.

Parameters:

  • values (Array<String>)

    Allowed values: "totalhits", "suggestion", "rewrittenquery".

Returns:

  • (self)


88
89
90
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 88

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

#interwikiself

Include interwiki results in the search, if available.

Returns:

  • (self)


113
114
115
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 113

def interwiki()
  merge(srinterwiki: 'true')
end

#limit(value) ⇒ self

How many total pages to return.

Parameters:

  • value (Integer, "max")

Returns:

  • (self)


46
47
48
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 46

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

#namespace(*values) ⇒ self

Search only within these namespaces.

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)


33
34
35
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 33

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

#offset(value) ⇒ self

When more results are available, use this to continue.

Parameters:

  • value (Integer)

Returns:

  • (self)


54
55
56
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 54

def offset(value)
  merge(sroffset: value.to_s)
end

#prop(*values) ⇒ self

Which properties to return:

Parameters:

  • values (Array<String>)

    Allowed values: "size" (Adds the size of the page in bytes), "wordcount" (Adds the word count of the page), "timestamp" (Adds the timestamp of when the page was last edited), "snippet" (Adds a parsed snippet of the page), "titlesnippet" (Adds a parsed snippet of the page title), "redirecttitle" (Adds the title of the matching redirect), "redirectsnippet" (Adds a parsed snippet of the redirect title), "sectiontitle" (Adds the title of the matching section), "sectionsnippet" (Adds a parsed snippet of the matching section title), "isfilematch" (Adds a boolean indicating if the search matched file content), "categorysnippet" (Adds a parsed snippet of the matching category), "score" (Deprecated and ignored), "hasrelated" (Deprecated and ignored).

Returns:

  • (self)


101
102
103
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 101

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

#qiprofile(value) ⇒ self

Query independent profile to use (affects ranking algorithm).

Parameters:

  • value (String)

    One of "classic" (Ranking based on the number of incoming links, some templates, article language and recency (templates/language/recency may not be activated on this wiki)), "classic_noboostlinks" (Ranking based on some templates, article language and recency when activated on this wiki), "empty" (Ranking based solely on query dependent features (for debug only)), "wsum_inclinks" (Weighted sum based on incoming links), "wsum_inclinks_pv" (Weighted sum based on incoming links and weekly pageviews), "popular_inclinks_pv" (Ranking based primarily on page views), "popular_inclinks" (Ranking based primarily on incoming link counts).

Returns:

  • (self)


62
63
64
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 62

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

#search(value) ⇒ self

Search for page titles or content matching this value. You can use the search string to invoke special search features, depending on what the wiki's search backend implements.

Parameters:

  • value (String)

Returns:

  • (self)


25
26
27
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 25

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

#what(value) ⇒ self

Which type of search to perform.

Parameters:

  • value (String)

    One of "title", "text", "nearmatch".

Returns:

  • (self)


75
76
77
# File 'lib/mediawiktory/wikipedia/modules/search.rb', line 75

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