Module: MediaWiki::Query::Lists::Search

Included in:
MediaWiki::Query::Lists
Defined in:
lib/mediawiki/query/lists/search.rb

Instance Method Summary collapse

Instance Method Details

#get_prefix_search(prefix, limit = 100) ⇒ Array<String>

Searches the wiki by a prefix. one of the methods that does not use the query_limit_default attribute.

Parameters:

  • prefix (String)

    The prefix.

  • limit (Integer) (defaults to: 100)

    The maximum number of results to get, maximum of 100 for users and 200 for bots. This is

Returns:

  • (Array<String>)

    All of the page titles that match the search.

See Also:

Since:

  • 0.10.0



62
63
64
65
66
67
68
69
70
# File 'lib/mediawiki/query/lists/search.rb', line 62

def get_prefix_search(prefix, limit = 100)
  params = {
    list: 'prefixsearch',
    pssearch: prefix,
    pslimit: get_limited(limit, 100, 200)
  }

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

#get_search_result_amount(search_value, namespace = MediaWiki::Constants::NAMESPACES['MAIN']) ⇒ Integer

Gets the amount of results for the search value.

Parameters:

  • search_value (String)

    The thing to search for.

  • namespace (Integer) (defaults to: MediaWiki::Constants::NAMESPACES['MAIN'])

    The namespace to search in. Defaults to 0 (the main namespace).

Returns:

  • (Integer)

    The number of pages that matched the search.

See Also:

Since:

  • 0.4.0



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mediawiki/query/lists/search.rb', line 10

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']) ⇒ Array<String>

Gets an array containing page titles that matched the search.

Parameters:

  • search_value (String)

    The thing to search for.

  • namespace (Integer) (defaults to: MediaWiki::Constants::NAMESPACES['MAIN'])

    The namespace to search in. Defaults to 0 (the main namespace).

Returns:

  • (Array<String>)

    The page titles that matched the search.

See Also:

Since:

  • 0.4.0



28
29
30
31
32
33
34
35
36
# File 'lib/mediawiki/query/lists/search.rb', line 28

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) ⇒ Array<String>

Searches page contents, returns an array containing page titles whose content matched the search.

Parameters:

  • search_value (String)

    The thing to search for.

  • namespace (Integer) (defaults to: MediaWiki::Constants::NAMESPACES['MAIN'])

    The namespace to search in. Defaults to 0 (the main namespace).

Returns:

  • (Array<String>)

    The page titles that matched the search.

See Also:

Since:

  • 4.0.0



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mediawiki/query/lists/search.rb', line 43

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