makasi 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/makasi.rb +1 -0
- data/lib/makasi/asari_patch.rb +69 -0
- data/lib/makasi/version.rb +1 -1
- data/makasi.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5526f72e030783699186fd2b99ee0a9a9eb4ee5
|
4
|
+
data.tar.gz: 3c20ffec77ebc98474facacb2fbeee196efc2ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e70a7df63169995ce69f380aa573dca3394df8d2a081f5c7b1c4ca7cc72d3bce5560acbc48dc75c4e8c4a1a9b898fc1fb5f934a97bcb97b336f3462811c95245
|
7
|
+
data.tar.gz: f7370894bf1e9d7af162a6818f99bc42621e037cb08f0b22c85734e611e77449d91c07e54420219767c584862723df630ead21d95b76b16df4a75e28c02b27b0
|
data/lib/makasi.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Allow the new api syntax of version 2013-01-01
|
2
|
+
|
3
|
+
class Asari
|
4
|
+
class Collection
|
5
|
+
def initialize(httparty_response, page_size)
|
6
|
+
resp = httparty_response.parsed_response
|
7
|
+
@total_entries = resp["hits"]["found"]
|
8
|
+
@page_size = page_size
|
9
|
+
|
10
|
+
complete_pages = (@total_entries / @page_size)
|
11
|
+
@total_pages = (@total_entries % @page_size > 0) ? complete_pages + 1 : complete_pages
|
12
|
+
# There's always one page, even for no results
|
13
|
+
@total_pages = 1 if @total_pages == 0
|
14
|
+
|
15
|
+
start = resp["hits"]["start"]
|
16
|
+
@current_page = (start / page_size) + 1
|
17
|
+
if resp["hits"]["hit"].first && resp["hits"]["hit"].first["fields"]
|
18
|
+
@data = {}
|
19
|
+
resp["hits"]["hit"].each { |hit| @data[hit["id"]] = hit["fields"]}
|
20
|
+
else
|
21
|
+
@data = resp["hits"]["hit"].map { |hit| hit["id"] }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def search(term, options = {})
|
27
|
+
return Asari::Collection.sandbox_fake if self.class.mode == :sandbox
|
28
|
+
term,options = "",term if term.is_a?(Hash) and options.empty?
|
29
|
+
|
30
|
+
if options[:filter]
|
31
|
+
bq = boolean_query(options[:filter])
|
32
|
+
bq = "(and '#{term.to_s.gsub("'", " ")}' #{bq})" if term.present?
|
33
|
+
end
|
34
|
+
page_size = options[:page_size].nil? ? 10 : options[:page_size].to_i
|
35
|
+
|
36
|
+
url = "http://search-#{search_domain}.#{aws_region}.cloudsearch.amazonaws.com/#{api_version}/search"
|
37
|
+
if options[:filter]
|
38
|
+
url += "?q.parser=structured&q=#{CGI.escape(bq)}"
|
39
|
+
else
|
40
|
+
url += "?q=#{CGI.escape(term.to_s)}"
|
41
|
+
end
|
42
|
+
url += "&size=#{page_size}"
|
43
|
+
url += "&return-fields=#{options[:return_fields].join ','}" if options[:return_fields]
|
44
|
+
|
45
|
+
if options[:page]
|
46
|
+
start = (options[:page].to_i - 1) * page_size
|
47
|
+
url << "&start=#{start}"
|
48
|
+
end
|
49
|
+
|
50
|
+
if options[:rank]
|
51
|
+
rank = normalize_rank(options[:rank])
|
52
|
+
url << "&rank=#{rank}"
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
response = HTTParty.get(url)
|
57
|
+
rescue Exception => e
|
58
|
+
ae = Asari::SearchException.new("#{e.class}: #{e.message} (#{url})")
|
59
|
+
ae.set_backtrace e.backtrace
|
60
|
+
raise ae
|
61
|
+
end
|
62
|
+
|
63
|
+
unless response.response.code == "200"
|
64
|
+
raise Asari::SearchException.new("#{response.response.code}: #{response.response.msg} (#{url})")
|
65
|
+
end
|
66
|
+
|
67
|
+
Asari::Collection.new(response, page_size)
|
68
|
+
end
|
69
|
+
end
|
data/lib/makasi/version.rb
CHANGED
data/makasi.gemspec
CHANGED
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.8"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
spec.add_dependency "asari"
|
23
|
+
spec.add_dependency "asari", "0.10.4"
|
24
24
|
spec.add_dependency "sitemap_generator"
|
25
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: makasi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nataliia Kumeiko
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: asari
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.10.4
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.10.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sitemap_generator
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- bin/setup
|
85
85
|
- lib/makasi.rb
|
86
86
|
- lib/makasi/asari_client.rb
|
87
|
+
- lib/makasi/asari_patch.rb
|
87
88
|
- lib/makasi/asari_result.rb
|
88
89
|
- lib/makasi/config.rb
|
89
90
|
- lib/makasi/railtie.rb
|