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.
@@ -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({size: 12}, {query: {match_all: {}}})
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
@@ -71,6 +71,7 @@ module Stretcher
71
71
  end
72
72
 
73
73
  # Issues an Index#search scoped to this type
74
+ # See Index#search for more details
74
75
  def search(generic_opts={}, body=nil)
75
76
  @index.search(generic_opts.merge(type: name), body)
76
77
  end
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Stretcher
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
@@ -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.0
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-23 00:00:00.000000000 Z
12
+ date: 2013-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday