sewell 0.0.3 → 0.1.0
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/README.md +4 -4
- data/lib/sewell/version.rb +1 -1
- data/lib/sewell.rb +17 -5
- data/spec/sewell/sewell_spec.rb +4 -4
- metadata +1 -1
data/README.md
CHANGED
@@ -19,14 +19,14 @@ Or install it yourself as:
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
``` ruby
|
22
|
-
query = Sewell.generate 'sena:airi OR mashiro AND nuko:buta', %w{sena uryu nuko} #=> ( sena:@airi ) OR ( sena:@mashiro OR uryu:@mashiro OR nuko:@mashiro )
|
22
|
+
query = Sewell.generate 'sena:airi OR mashiro AND nuko:buta', %w{sena uryu nuko} #=> ( sena:@airi ) OR ( sena:@mashiro OR uryu:@mashiro OR nuko:@mashiro ) + ( nuko:@buta )
|
23
23
|
Groonga['SenaAiri'].select(query)
|
24
24
|
|
25
|
-
Sewell.generate({sena: 'airi OR huro', nuko: 'trape'}, 'AND') #=> ( sena:@airi OR sena:@huro )
|
25
|
+
Sewell.generate({sena: 'airi OR huro', nuko: 'trape'}, 'AND') #=> ( sena:@airi OR sena:@huro ) + ( nuko:@trape )
|
26
26
|
Sewell.generate({sena: 'airi OR huro', nuko: 'trape'}, 'OR') #=> ( sena:@airi OR sena:@huro ) OR ( nuko:@trape )
|
27
27
|
|
28
|
-
Sewell.generate({mashiro: '-inui airi'}) #=> ( mashiro:!inui
|
29
|
-
Sewell.generate('-inui airi', ['mashiro']) #=> ( mashiro:!inui
|
28
|
+
Sewell.generate({mashiro: '-inui airi'}) #=> ( mashiro:!inui + mashiro:@airi )
|
29
|
+
Sewell.generate('-inui airi', ['mashiro']) #=> ( mashiro:!inui + mashiro:@airi )
|
30
30
|
```
|
31
31
|
|
32
32
|
## Contributing
|
data/lib/sewell/version.rb
CHANGED
data/lib/sewell.rb
CHANGED
@@ -17,7 +17,12 @@ module Sewell
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
def self.from_hash hash,
|
20
|
+
def self.from_hash hash, s
|
21
|
+
if s == 'OR'
|
22
|
+
sep = 'OR'
|
23
|
+
else
|
24
|
+
sep = '+'
|
25
|
+
end
|
21
26
|
hash.map{|k,v|
|
22
27
|
'( ' + build(v.split(' ').map{|x|
|
23
28
|
if x == 'OR' or x == 'AND'
|
@@ -59,14 +64,21 @@ module Sewell
|
|
59
64
|
build q
|
60
65
|
end
|
61
66
|
|
62
|
-
def self.build q
|
67
|
+
def self.build q, *s
|
68
|
+
if s.first == 'OR'
|
69
|
+
sep = 'OR'
|
70
|
+
else
|
71
|
+
sep = '+'
|
72
|
+
end
|
63
73
|
query = ''
|
64
74
|
q.each_with_index{|x,i|
|
65
75
|
next if x == 'OR' or x == 'AND'
|
66
|
-
if q[i+1] == 'OR'
|
67
|
-
query += "#{x}
|
76
|
+
if q[i+1] == 'OR'
|
77
|
+
query += "#{x} OR "
|
78
|
+
elsif q[i+1] == 'AND'
|
79
|
+
query += "#{x} + "
|
68
80
|
elsif q[i+1] != nil
|
69
|
-
query += "#{x}
|
81
|
+
query += "#{x} #{sep} "
|
70
82
|
else
|
71
83
|
if x != 'AND' and x != 'OR'
|
72
84
|
query += x
|
data/spec/sewell/sewell_spec.rb
CHANGED
@@ -7,12 +7,12 @@ describe Sewell do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'can generate from string' do
|
10
|
-
Sewell.generate('sena:airi OR mashiro AND nuko:buta', %w{sena uryu nuko}).should == '( sena:@airi ) OR ( sena:@mashiro OR uryu:@mashiro OR nuko:@mashiro )
|
11
|
-
Sewell.generate('-inui airi', ['mashiro']).should == '( mashiro:!inui )
|
10
|
+
Sewell.generate('sena:airi OR mashiro AND nuko:buta', %w{sena uryu nuko}).should == '( sena:@airi ) OR ( sena:@mashiro OR uryu:@mashiro OR nuko:@mashiro ) + ( nuko:@buta )'
|
11
|
+
Sewell.generate('-inui airi', ['mashiro']).should == '( mashiro:!inui ) + ( mashiro:@airi )'
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'can generate from hash' do
|
15
|
-
Sewell.generate({sena: 'airi OR huro', nuko: 'trape'}, 'AND').should == '( sena:@airi OR sena:@huro )
|
16
|
-
Sewell.generate({mashiro: '-inui airi'}, 'AND').should == '( mashiro:!inui
|
15
|
+
Sewell.generate({sena: 'airi OR huro', nuko: 'trape'}, 'AND').should == '( sena:@airi OR sena:@huro ) + ( nuko:@trape )'
|
16
|
+
Sewell.generate({mashiro: '-inui airi'}, 'AND').should == '( mashiro:!inui + mashiro:@airi )'
|
17
17
|
end
|
18
18
|
end
|