Class: Dataset::Adaptors::Iqvoc::SearchAdaptor
- Inherits:
-
HttpAdaptor
- Object
- HttpAdaptor
- Dataset::Adaptors::Iqvoc::SearchAdaptor
show all
- Defined in:
- app/models/dataset/adaptors/iqvoc/search_adaptor.rb
Instance Method Summary
collapse
Instance Method Details
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/models/dataset/adaptors/iqvoc/search_adaptor.rb', line 34
def (html)
@doc = Nokogiri::HTML(html)
@doc.css('.search-result').map do |element|
link = element.at_css('.search-result-link')
label, path = link.text, link['data-resource-path']
result = SearchResultRemote.new(url, path, label)
if (meta = element.css('.search-result-meta > .search-result-value')) && meta.any?
meta.each do |element|
result.add_meta_information(element['data-key'], element.text)
end
end
if body = element.at_css('.search-result-body')
result.body = body.text
end
result.rdf_namespace = element['data-rdf-namespace']
result.rdf_predicate = element['data-rdf-predicate']
result.language = element['data-rdf-language']
result
end
end
|
#fetch_results(path, params = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/models/dataset/adaptors/iqvoc/search_adaptor.rb', line 19
def fetch_results(path, params = {})
begin
response = @conn.get(path, params)
@results ||= []
@results += (response.body)
while more = @doc.at_css('a[rel=next]')
fetch_results(more[:href], {})
end
rescue Faraday::ConnectionFailed,
Faraday::ResourceNotFound => e
Rails.logger.warn("HTTP error while querying remote source #{path}: #{e.message}")
return nil
end
end
|
#search(raw_params = {}) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'app/models/dataset/adaptors/iqvoc/search_adaptor.rb', line 2
def search(raw_params = {})
languages = raw_params.fetch(:languages, I18n.locale)
languages = Array.wrap(languages).flatten.join(',')
params = {
q: raw_params[:q],
t: raw_params[:t],
l: languages,
c: raw_params[:c],
qt: raw_params[:qt],
page: 1 }
fetch_results('search.html', params)
@results
end
|