stretcher 1.3.0 → 1.3.1
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.
- data/lib/stretcher/index.rb +11 -1
- data/lib/stretcher/index_type.rb +1 -0
- data/lib/stretcher/server.rb +12 -1
- data/lib/stretcher/version.rb +1 -1
- data/spec/lib/stretcher_index_spec.rb +5 -0
- data/spec/lib/stretcher_server_spec.rb +5 -0
- metadata +2 -2
data/lib/stretcher/index.rb
CHANGED
@@ -75,7 +75,7 @@ module Stretcher
|
|
75
75
|
|
76
76
|
# Issues a search with the given query opts and body, both should be hashes
|
77
77
|
#
|
78
|
-
# res = server.index('foo').search(
|
78
|
+
# res = server.index('foo').search(size: 12, {query: {match_all: {}}})
|
79
79
|
# es.class # Stretcher::SearchResults
|
80
80
|
# res.total # => 1
|
81
81
|
# res.facets # => nil
|
@@ -115,6 +115,16 @@ module Stretcher
|
|
115
115
|
@server.msearch req_body
|
116
116
|
end
|
117
117
|
|
118
|
+
# Implements the Analyze API
|
119
|
+
# EX:
|
120
|
+
# index.analyze("Candles", analyzer: :snowball)
|
121
|
+
# # => #<Hashie::Mash tokens=[#<Hashie::Mash end_offset=7 position=1 start_offset=0 token="candl" type="<ALPHANUM>">]>
|
122
|
+
def analyze(text, analysis_params)
|
123
|
+
@server.request(:get, path_uri("/_analyze"), analysis_params) do |req|
|
124
|
+
req.body = text
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
118
128
|
# Full path to this index
|
119
129
|
def path_uri(path="/")
|
120
130
|
@server.path_uri("/#{name}") + path.to_s
|
data/lib/stretcher/index_type.rb
CHANGED
data/lib/stretcher/server.rb
CHANGED
@@ -108,12 +108,23 @@ module Stretcher
|
|
108
108
|
req.body = body
|
109
109
|
}
|
110
110
|
end
|
111
|
+
|
112
|
+
# Implements the Analyze API
|
113
|
+
# EX:
|
114
|
+
# server.analyze("Candles", analyzer: :snowball)
|
115
|
+
# # => #<Hashie::Mash tokens=[#<Hashie::Mash end_offset=7 position=1 start_offset=0 token="candl" type="<ALPHANUM>">]>
|
116
|
+
# as per: http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze.html
|
117
|
+
def analyze(text, analysis_params)
|
118
|
+
request(:get, path_uri("/_analyze"), analysis_params) do |req|
|
119
|
+
req.body = text
|
120
|
+
end
|
121
|
+
end
|
111
122
|
|
112
123
|
# Full path to the server root dir
|
113
124
|
def path_uri(path="/")
|
114
125
|
@uri.to_s + path.to_s
|
115
126
|
end
|
116
|
-
|
127
|
+
|
117
128
|
# Handy way to query the server, returning *only* the body
|
118
129
|
# Will raise an exception when the status is not in the 2xx range
|
119
130
|
def request(method, *args, &block)
|
data/lib/stretcher/version.rb
CHANGED
@@ -77,6 +77,11 @@ describe Stretcher::Index do
|
|
77
77
|
res[0].class.should == Stretcher::SearchResults
|
78
78
|
end
|
79
79
|
|
80
|
+
it "execute the analysis API and return an expected result" do
|
81
|
+
analyzed = index.analyze("Candles", analyzer: :snowball)
|
82
|
+
analyzed.tokens.first.token.should == 'candl'
|
83
|
+
end
|
84
|
+
|
80
85
|
it "should raise an exception when msearching a non-existant index" do
|
81
86
|
lambda {
|
82
87
|
res = server.index(:does_not_exist).msearch([{query: {match_all: {}}}])
|
@@ -42,4 +42,9 @@ describe Stretcher::Server do
|
|
42
42
|
res.should == :retval
|
43
43
|
exposed.class.should == Stretcher::Index
|
44
44
|
end
|
45
|
+
|
46
|
+
it "execute the analysis API and return an expected result" do
|
47
|
+
analyzed = server.analyze("Candles", analyzer: :snowball)
|
48
|
+
analyzed.tokens.first.token.should == 'candl'
|
49
|
+
end
|
45
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|