module MediaWiki::Query::Lists::Search

Public Instance Methods

get_search_result_amount(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN']) click to toggle source

Gets the amount of results for the search value. @param search_value [String] The thing to search for. @param namespace [Integer] The namespace to search in. Defaults to 0 (the main namespace). @see www.mediawiki.org/wiki/API:Search MediaWiki Search API Docs @since 0.4.0 @return [Fixnum] The number of pages that matched the search.

# File lib/mediawiki/query/lists/search.rb, line 11
def get_search_result_amount(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN'])
  params = {
    action: 'query',
    list: 'search',
    srsearch: search_value,
    srnamespace: validate_namespace(namespace)
  }

  response = post(params)
  response['query']['searchinfo']['totalhits']
end
get_search_results(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN']) click to toggle source

Gets an array containing page titles that matched the search. @param search_value [String] The thing to search for. @param namespace [Integer] The namespace to search in. Defaults to 0 (the main namespace). @see www.mediawiki.org/wiki/API:Search MediaWiki Search API Docs @since 0.4.0 @return [Array<String>] The page titles that matched the search.

# File lib/mediawiki/query/lists/search.rb, line 29
def get_search_results(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN'])
  params = {
    list: 'search',
    srsearch: search_value,
    srnamespace: validate_namespace(namespace)
  }

  query_ary(params, 'search', 'title')
end
get_search_text_results(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN'], limit = @query_limit_default) click to toggle source

Gets an array containing page titles that matched the search. @param search_value [String] The thing to search for. @param namespace [Integer] The namespace to search in. Defaults to 0 (the main namespace). @see www.mediawiki.org/wiki/API:Search MediaWiki Search API Docs @return [Array<String>] The page titles that matched the search.

# File lib/mediawiki/query/lists/search.rb, line 44
def get_search_text_results(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN'], limit = @query_limit_default)
  params = {
    list: 'search',
    srsearch: search_value,
    srwhat: 'text',
    srlimit: get_limited(limit),
    srnamespace: validate_namespace(namespace)
  }

  query_ary(params, 'search', 'title')
end