jruby-elasticsearch 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require "java"
2
2
  require "jruby-elasticsearch/namespace"
3
3
  require "jruby-elasticsearch/indexrequest"
4
+ require "jruby-elasticsearch/searchrequest"
4
5
 
5
6
  class ElasticSearch::Client
6
7
  def initialize
@@ -43,6 +44,25 @@ class ElasticSearch::Client
43
44
  return indexreq
44
45
  end # def index
45
46
 
47
+ # Search for data.
48
+ # If a block is given, it is passed to SearchRequest#with so you can
49
+ # more easily configure the search, like so:
50
+ #
51
+ # search = client.search("foo") do
52
+ # query("*")
53
+ # histogram("field", 1000)
54
+ # end
55
+ #
56
+ # The context of the block is of the SearchRequest object.
57
+ public
58
+ def search(&block)
59
+ searchreq = ElasticSearch::SearchRequest.new(@client)
60
+ if block_given?
61
+ searchreq.with(&block)
62
+ end
63
+ return searchreq
64
+ end # def search
65
+
46
66
  def cluster
47
67
  return @client.admin.cluster
48
68
  end
@@ -3,7 +3,7 @@ require "jruby-elasticsearch/actionlistener"
3
3
 
4
4
  class ElasticSearch::Request
5
5
  # Create a new index request.
6
- def initialize()
6
+ def initialize
7
7
  @handler = ElasticSearch::ActionListener.new
8
8
  end
9
9
 
@@ -0,0 +1,96 @@
1
+ require "jruby-elasticsearch/namespace"
2
+ require "jruby-elasticsearch/request"
3
+
4
+ class ElasticSearch::SearchRequest < ElasticSearch::Request
5
+ # Create a new index request.
6
+ public
7
+ def initialize(client)
8
+ @client = client
9
+ @prep = org.elasticsearch.client.action.search.SearchRequestBuilder.new(@client)
10
+ @indeces = []
11
+ super()
12
+ end # def initialize
13
+
14
+ public
15
+ def with(&block)
16
+ instance_eval(&block)
17
+ return self
18
+ end # def with
19
+
20
+ public
21
+ def index(index_name)
22
+ @indeces << index_name
23
+ end
24
+
25
+ # Execute this search request.
26
+ # This call is asynchronous.
27
+ #
28
+ # If a block is given, register it for both failure and success.
29
+ #
30
+ # On success, callback will receive a
31
+ # org.elasticsearch.action.search.SearchResponse
32
+ public
33
+ def execute(&block)
34
+ use_callback(&block) if block_given?
35
+ @prep.setIndices(@indeces) if !@indeces.empty?
36
+
37
+ action = @prep.execute(@handler)
38
+ return action
39
+ end # def execute
40
+
41
+ # Execute this index request synchronously
42
+ # Returns an org.elasticsearch.action.search.SearchResponse
43
+ public
44
+ def execute!
45
+ return @prep.execute.actionGet()
46
+ end # def execute!
47
+
48
+ public
49
+ def sort(field, order)
50
+ case order
51
+ when :asc
52
+ order_val = org.elasticsearch.search.sort.SortOrder::ASC
53
+ when :desc
54
+ order_val = org.elasticsearch.search.sort.SortOrder::DESC
55
+ else
56
+ raise "Invalid sort order '#{order.inspect}'"
57
+ end
58
+ @prep.addSort(field, order_val)
59
+ return self
60
+ end # def sort
61
+
62
+ public
63
+ def query(query_string)
64
+ # TODO(sissel): allow doing other queries and such.
65
+ qbuilder = org.elasticsearch.index.query.xcontent.QueryStringQueryBuilder.new(query_string)
66
+ @prep.setQuery(qbuilder)
67
+ return self
68
+ end # def query
69
+
70
+ # Add a histogram facet to this query. Can be invoked multiple times.
71
+ public
72
+ def histogram(field, interval, name=nil)
73
+ if name.nil?
74
+ # TODO(sissel): How do we expose the name of the histogram?
75
+ name = "#{field}_#{interval}"
76
+ end
77
+ # TODO(sissel): Support 'global' ?
78
+ builder = org.elasticsearch.search.facet.histogram.HistogramFacetBuilder.new(name)
79
+ builder.field(field)
80
+ builder.interval(interval)
81
+ @prep.addFacet(builder)
82
+ return self
83
+ end # def histogram
84
+
85
+ public
86
+ def limit(size)
87
+ @prep.setSize(size)
88
+ return self
89
+ end
90
+
91
+ public
92
+ def offset(from)
93
+ @prep.setFrom(from)
94
+ return self
95
+ end
96
+ end # class ElasticSearch::SearchRequest
metadata CHANGED
@@ -1,26 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 3
9
- version: 0.0.3
4
+ prerelease:
5
+ version: 0.0.5
10
6
  platform: ruby
11
7
  authors:
12
- - Jordan Sissel
8
+ - Jordan Sissel
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-27 00:00:00 -08:00
13
+ date: 2011-03-26 00:00:00 -07:00
18
14
  default_executable:
19
15
  dependencies: []
20
16
 
21
17
  description: ...
22
18
  email:
23
- - jls@semicomplete.com
19
+ - jls@semicomplete.com
24
20
  executables: []
25
21
 
26
22
  extensions: []
@@ -28,44 +24,41 @@ extensions: []
28
24
  extra_rdoc_files: []
29
25
 
30
26
  files:
31
- - lib/jruby-elasticsearch.rb
32
- - lib/jruby-elasticsearch/namespace.rb
33
- - lib/jruby-elasticsearch/bulkrequest.rb
34
- - lib/jruby-elasticsearch/actionlistener.rb
35
- - lib/jruby-elasticsearch/request.rb
36
- - lib/jruby-elasticsearch/indexrequest.rb
37
- - lib/jruby-elasticsearch/client.rb
38
- - lib/jruby-elasticsearch/bulkstream.rb
27
+ - lib/jruby-elasticsearch.rb
28
+ - lib/jruby-elasticsearch/searchrequest.rb
29
+ - lib/jruby-elasticsearch/namespace.rb
30
+ - lib/jruby-elasticsearch/bulkrequest.rb
31
+ - lib/jruby-elasticsearch/actionlistener.rb
32
+ - lib/jruby-elasticsearch/request.rb
33
+ - lib/jruby-elasticsearch/indexrequest.rb
34
+ - lib/jruby-elasticsearch/client.rb
35
+ - lib/jruby-elasticsearch/bulkstream.rb
39
36
  has_rdoc: true
40
37
  homepage: https://github.com/jordansissel/jruby-elasticsearch
41
38
  licenses:
42
- - Apache License (2.0)
39
+ - Apache License (2.0)
43
40
  post_install_message:
44
41
  rdoc_options: []
45
42
 
46
43
  require_paths:
47
- - lib
48
- - lib
44
+ - lib
45
+ - lib
49
46
  required_ruby_version: !ruby/object:Gem::Requirement
50
47
  none: false
51
48
  requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- version: "0"
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
57
52
  required_rubygems_version: !ruby/object:Gem::Requirement
58
53
  none: false
59
54
  requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- segments:
63
- - 0
64
- version: "0"
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
65
58
  requirements: []
66
59
 
67
60
  rubyforge_project:
68
- rubygems_version: 1.3.7
61
+ rubygems_version: 1.6.0
69
62
  signing_key:
70
63
  specification_version: 3
71
64
  summary: JRuby API for ElasticSearch using the native ES Java API