plunk 0.3.3 → 0.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9783fb61da735628ac2266ff16fd4234d146bed
4
- data.tar.gz: 8fa8d01bffed0cc5351afef868a2e22caa3ddf88
3
+ metadata.gz: f86c017a01538aeca399e39459d80f8939fe394c
4
+ data.tar.gz: 1b238425837d802c816c9184b2a5e7b050182d0b
5
5
  SHA512:
6
- metadata.gz: aaf0493c53bfee8441676b7e72697fb72d47e32b5e6abd8e505e6ef89483a7976bc6ec3a5fb5b34b5959fff0a4d5074cb836b9acde565417737589c704c0fb54
7
- data.tar.gz: 3767a5c241aa94a9c55faef62742f6e57862377cb2e662cc0c58cd7a952dd1ac5716f3ddea6a894adf73f806c0db5481c95e4f99c1804033a59d9f1875a7a2bf
6
+ metadata.gz: d51573bbf2390d9c28ad3a8108fde498ebef50dcff3e494e5f2b4020dabc4fd7cc49ab973575c0a4c7ed658f20a62f57c3eb44e4a90a1386a415251e3215fe2a
7
+ data.tar.gz: a934a1a3eab5fbf5e86884fa5b386619caf6e069e44225622ea5cb8faf5df4598f4556b1e998239f4b115426ad67e3c67bafc87e6495255d01c3afd0c337bed8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plunk (0.3.2)
4
+ plunk (0.3.4)
5
5
  activesupport (~> 4.0, >= 4.0.0)
6
6
  chronic (~> 0.10, >= 0.10.0)
7
7
  elasticsearch (~> 0.4, >= 0.4.3)
data/bin/plunk ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << './lib'
3
+ require './lib/plunk'
4
+
5
+ host = ARGV[ARGV.index('-h')+1]
6
+
7
+ Plunk.configure do |c|
8
+ c.elasticsearch_client = Elasticsearch::Client.new(
9
+ host: host,
10
+ randomize_hosts: true
11
+ )
12
+ end
13
+
14
+ puts Plunk.search($stdin.read)
data/lib/plunk/helper.rb CHANGED
@@ -52,8 +52,18 @@ module Plunk
52
52
  def self.regexp_builder(field, regexp, flags=nil)
53
53
  {
54
54
  regexp: {
55
- field => regexp,
56
- flags: flags || 'ALL'
55
+ field => {
56
+ value: regexp,
57
+ flags: flags || 'ALL'
58
+ }
59
+ }
60
+ }
61
+ end
62
+
63
+ def self.indices_builder(list)
64
+ {
65
+ indices: {
66
+ indices: list
57
67
  }
58
68
  }
59
69
  end
data/lib/plunk/parser.rb CHANGED
@@ -54,6 +54,9 @@ module Plunk
54
54
  # COMMANDS
55
55
 
56
56
  # Command parts
57
+ rule(:enclosed_string) {
58
+ string | match('[^\s]').repeat
59
+ }
57
60
  rule(:identifier) { match('[^=\s)(|]').repeat(1) >> match('[^=\s]').repeat }
58
61
  rule(:wildcard) {
59
62
  (lparen >> wildcard >> rparen) |
@@ -64,15 +67,12 @@ module Plunk
64
67
  rule(:rhs) {
65
68
  regexp | query_value
66
69
  }
67
- rule(:chronic_time) {
68
- string | match('[^\s]').repeat
69
- }
70
70
  rule(:relative_time) {
71
71
  integer.as(:quantity) >>
72
72
  match('s|m|h|d|w').as(:quantifier)
73
73
  }
74
74
  rule(:absolute_time) {
75
- datetime.as(:datetime) | chronic_time.as(:chronic_time)
75
+ datetime.as(:datetime) | enclosed_string.as(:chronic_time)
76
76
  }
77
77
 
78
78
  # Field = Value
@@ -96,6 +96,17 @@ module Plunk
96
96
  (relative_time | absolute_time).as(:window_end)
97
97
  }
98
98
 
99
+ # Indices
100
+ rule(:indices) {
101
+ str('indices') >>
102
+ space >>
103
+ (enclosed_string >>
104
+ (space? >>
105
+ str(',') >>
106
+ space? >>
107
+ enclosed_string).repeat).as(:indices)
108
+ }
109
+
99
110
  # Limit
100
111
  rule(:limit) {
101
112
  str('limit') >> space >> positive_integer.as(:limit)
@@ -124,10 +135,11 @@ module Plunk
124
135
  # NOTE: order matters!
125
136
  rule(:command) {
126
137
  (
138
+ field_value |
127
139
  window |
128
140
  last |
129
141
  limit |
130
- field_value |
142
+ indices |
131
143
  value_only
132
144
  ).as(:command) >> space?
133
145
  }
@@ -141,6 +153,7 @@ module Plunk
141
153
  }
142
154
  rule(:primary) { lparen >> or_operation >> rparen | negated_command }
143
155
 
156
+ # borrowed from Parslet's boolean algebra example
144
157
  rule(:negated_and) {
145
158
  (not_operator >> and_operation.as(:not)) |
146
159
  and_operation
@@ -38,6 +38,12 @@ module Plunk
38
38
  Helper.query_builder(String(value))
39
39
  end
40
40
 
41
+ # Indices
42
+ rule(indices: simple(:indices)) do
43
+ list = String(indices).split(',').collect { |s| s.strip }
44
+ Helper.indices_builder(list)
45
+ end
46
+
41
47
  # Last
42
48
  rule(last: subtree(:last)) do
43
49
  start_time = last
data/lib/plunk.rb CHANGED
@@ -9,7 +9,7 @@ require 'plunk/result_set'
9
9
  module Plunk
10
10
  class << self
11
11
  attr_accessor :elasticsearch_options, :elasticsearch_client,
12
- :parser, :transformer, :max_number_of_hits, :timestamp_field
12
+ :parser, :transformer, :max_number_of_hits, :timestamp_field, :logger
13
13
  end
14
14
 
15
15
  def self.configure(&block)
@@ -33,10 +33,14 @@ module Plunk
33
33
  end
34
34
 
35
35
  def self.search(query_string)
36
- ResultSet.new(
37
- transformer.apply(
38
- parser.parse(query_string)
39
- )
40
- ).eval
36
+ parsed = parser.parse query_string
37
+ transformed = transformer.apply parsed
38
+
39
+ if self.logger
40
+ self.logger.debug "Query String: #{query_string}"
41
+ self.logger.debug "Parsed Output: #{transformed}"
42
+ end
43
+
44
+ ResultSet.new(transformed).eval
41
45
  end
42
46
  end
data/plunk.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "plunk"
3
- s.version = "0.3.3"
3
+ s.version = "0.3.5"
4
4
  s.add_runtime_dependency "json", "~> 1.8", ">= 1.8.0"
5
5
  s.add_runtime_dependency "parslet", "~> 1.5", ">= 1.5.0"
6
6
  s.add_runtime_dependency "elasticsearch", "~> 0.4", ">= 0.4.3"
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'the indices command' do
4
+ it 'should parse indices foo,bar,baz' do
5
+ result = Plunk.search 'indices foo,bar,baz'
6
+ expected = Plunk::Helper.filter_builder(
7
+ Plunk::Helper.indices_builder(%w(foo bar baz))
8
+ )
9
+ expect(result).to eq(expected)
10
+ end
11
+
12
+ it 'should parse indices foo , bar , baz' do
13
+ result = Plunk.search 'indices foo , bar , baz'
14
+ expected = Plunk::Helper.filter_builder(
15
+ Plunk::Helper.indices_builder(%w(foo bar baz))
16
+ )
17
+ expect(result).to eq(expected)
18
+ end
19
+
20
+ it 'should parse indices foo , bar , baz & key = value' do
21
+ result = Plunk.search 'indices foo , bar , baz & key = value'
22
+ expected = Plunk::Helper.filter_builder(
23
+ and: [
24
+ Plunk::Helper.indices_builder(%w(foo bar baz)),
25
+ Plunk::Helper.query_builder('key:value')
26
+ ]
27
+ )
28
+ expect(result).to eq(expected)
29
+ end
30
+
31
+ it 'should parse key = value & indices foo , bar , baz' do
32
+ result = Plunk.search 'key = value & indices foo , bar , baz'
33
+ expected = Plunk::Helper.filter_builder(
34
+ and: [
35
+ Plunk::Helper.query_builder('key:value'),
36
+ Plunk::Helper.indices_builder(%w(foo bar baz))
37
+ ]
38
+ )
39
+ expect(result).to eq(expected)
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ram Mehta
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-03-21 00:00:00.000000000 Z
13
+ date: 2014-03-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -169,6 +169,7 @@ files:
169
169
  - LICENSE
170
170
  - README.md
171
171
  - Rakefile
172
+ - bin/plunk
172
173
  - lib/plunk.rb
173
174
  - lib/plunk/helper.rb
174
175
  - lib/plunk/parser.rb
@@ -180,6 +181,7 @@ files:
180
181
  - spec/boolean_spec.rb
181
182
  - spec/chained_search_spec.rb
182
183
  - spec/field_value_spec.rb
184
+ - spec/indices_spec.rb
183
185
  - spec/last_spec.rb
184
186
  - spec/limit_spec.rb
185
187
  - spec/nested_search_spec.rb