Class: QuickSearch::WikipediaSearcher
- Inherits:
-
Searcher
- Object
- Searcher
- QuickSearch::WikipediaSearcher
- Defined in:
- app/searchers/quick_search/wikipedia_searcher.rb
Instance Method Summary collapse
- #base_url ⇒ Object
- #build_link(value) ⇒ Object
- #loaded_link ⇒ Object
- #parameters ⇒ Object
- #results ⇒ Object
- #search ⇒ Object
- #spelling_suggestion ⇒ Object
- #total ⇒ Object
Instance Method Details
#base_url ⇒ Object
29 30 31 |
# File 'app/searchers/quick_search/wikipedia_searcher.rb', line 29 def base_url "https://en.wikipedia.org/w/api.php" end |
#build_link(value) ⇒ Object
57 58 59 |
# File 'app/searchers/quick_search/wikipedia_searcher.rb', line 57 def build_link(value) "https://en.wikipedia.org/wiki/" + value['title'] end |
#loaded_link ⇒ Object
53 54 55 |
# File 'app/searchers/quick_search/wikipedia_searcher.rb', line 53 def loaded_link "https://en.wikipedia.org/wiki/Special:Search?fulltext=Search&search=" + http_request_queries['uri_escaped'] end |
#parameters ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/searchers/quick_search/wikipedia_searcher.rb', line 33 def parameters { 'action' => 'query', 'list' => 'search', 'srsearch' => http_request_queries['not_escaped'], 'sroffset' => @offset, 'srlimit' => @per_page, 'utf8' => true, 'format' => 'json' } end |
#results ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/searchers/quick_search/wikipedia_searcher.rb', line 9 def results if results_list results_list else @results_list = [] @response['query']['search'].each do |value| result = OpenStruct.new result.title = value['title'] result.link = build_link(value) result.description = value['snippet'] @results_list << result end @results_list end end |
#search ⇒ Object
4 5 6 7 |
# File 'app/searchers/quick_search/wikipedia_searcher.rb', line 4 def search resp = @http.get(base_url, parameters) @response = JSON.parse(resp.body) end |
#spelling_suggestion ⇒ Object
49 50 51 |
# File 'app/searchers/quick_search/wikipedia_searcher.rb', line 49 def spelling_suggestion @response['query']['searchinfo']['suggestion'] end |
#total ⇒ Object
45 46 47 |
# File 'app/searchers/quick_search/wikipedia_searcher.rb', line 45 def total @response['query']['searchinfo']['totalhits'] end |