boogex 0.0.1 → 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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/boogex.gemspec +1 -1
- data/lib/boogex/convertor.rb +18 -2
- data/lib/boogex/version.rb +1 -1
- data/test/convertor_test.rb +11 -9
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de3fe706280ac098115350c77c0420f36ca96af9
|
|
4
|
+
data.tar.gz: e9f87414d4bfd2d1ee3d617eabbd919f3e5fb777
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf3676878d21a6342639ca8f57671d80932442c4c266ce478be5a5a5320d45b23b721fe9a419c4739fbd3f8a456f9916e118a94ccc465cf876f36e9839c075ab
|
|
7
|
+
data.tar.gz: 0dab88ba6541a518550808c7cf6ae1a64b5c537adc5b4f056a7369243a274f9f7747e440d318b627179a69c940039f605aa22f8c39d5e4aec3ad5851181f710c
|
data/.gitignore
ADDED
data/boogex.gemspec
CHANGED
data/lib/boogex/convertor.rb
CHANGED
|
@@ -41,7 +41,7 @@ module Boogex
|
|
|
41
41
|
result << splits.last
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
|
-
end.uniq
|
|
44
|
+
end.uniq.compact
|
|
45
45
|
|
|
46
46
|
# This recursively converts any brackets in the text back into the array_struct function
|
|
47
47
|
# where the upper limit of recursion is 3 levels of bracketing. This is limitied by the regex
|
|
@@ -97,6 +97,16 @@ module Boogex
|
|
|
97
97
|
|
|
98
98
|
# if an all string array, then check if any of the elements of the array need bracket wrapped and return
|
|
99
99
|
if all_strings?(obj)
|
|
100
|
+
if obj.any? do |str|
|
|
101
|
+
contain_AND?(str)
|
|
102
|
+
end
|
|
103
|
+
result = obj.each_with_object(['AND']) do |str, arr|
|
|
104
|
+
str.split(' AND ').reject(&:empty?).collect do |str|
|
|
105
|
+
arr << regex_formatting(str)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
return result
|
|
109
|
+
end
|
|
100
110
|
needs_brackets = obj.any? do |text|
|
|
101
111
|
not_in_or?(text)
|
|
102
112
|
end
|
|
@@ -148,7 +158,13 @@ module Boogex
|
|
|
148
158
|
end
|
|
149
159
|
|
|
150
160
|
def self.construct_AND_array(array)
|
|
151
|
-
|
|
161
|
+
and_prefix = 'AND(['
|
|
162
|
+
and_suffix = "])"
|
|
163
|
+
internal_str = array.collect do |str|
|
|
164
|
+
next "'" + str + "'" unless str.include?(and_prefix)
|
|
165
|
+
str
|
|
166
|
+
end.join(',')
|
|
167
|
+
and_prefix + internal_str + and_suffix
|
|
152
168
|
end
|
|
153
169
|
|
|
154
170
|
def self.contain_AND?(obj)
|
data/lib/boogex/version.rb
CHANGED
data/test/convertor_test.rb
CHANGED
|
@@ -8,28 +8,30 @@ describe Boogex do
|
|
|
8
8
|
assert_equal expecting, result
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
it 'turns AND into
|
|
11
|
+
it 'turns boolean AND into AND array string' do
|
|
12
12
|
string = 'This AND That'
|
|
13
|
-
expecting =
|
|
13
|
+
expecting = "AND(['(?:This)','(?:That)'])"
|
|
14
14
|
result = Boogex.convert(string)
|
|
15
15
|
assert_equal expecting, result
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it 'understands bracketing' do
|
|
19
19
|
string = '(This OR That) AND My self'
|
|
20
|
-
expecting =
|
|
21
|
-
result = Boogex.convert(string)
|
|
22
|
-
assert_equal expecting, result
|
|
23
|
-
|
|
24
|
-
string = 'This AND (That OR (My self)'
|
|
25
|
-
expecting = '#{andify["(?:This|That)", "(?:My self)"]}'
|
|
20
|
+
expecting = "AND(['(?:This|That)','(?:My self)'])"
|
|
26
21
|
result = Boogex.convert(string)
|
|
27
22
|
assert_equal expecting, result
|
|
28
23
|
end
|
|
29
24
|
|
|
30
25
|
it 'correctly convert this Lucene boolean query string' do
|
|
31
26
|
string = '(((asd OR dd) AND that) AND this) OR What?'
|
|
32
|
-
expecting =
|
|
27
|
+
expecting = "AND([AND(['(?:asd|dd)','(?:that)']),'(?:this)'])|What?"
|
|
28
|
+
result = Boogex.convert(string)
|
|
29
|
+
assert_equal expecting, result
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'understands embedded AND' do
|
|
33
|
+
string = '((im AND researching) AND travelling)'
|
|
34
|
+
expecting = "AND([AND(['(?:im)','(?:researching)']),'(?:travelling)'])"
|
|
33
35
|
result = Boogex.convert(string)
|
|
34
36
|
assert_equal expecting, result
|
|
35
37
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: boogex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sam Crouch
|
|
@@ -16,6 +16,7 @@ executables: []
|
|
|
16
16
|
extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
|
18
18
|
files:
|
|
19
|
+
- ".gitignore"
|
|
19
20
|
- Gemfile
|
|
20
21
|
- Gemfile.lock
|
|
21
22
|
- LICENSE
|
|
@@ -55,6 +56,7 @@ signing_key:
|
|
|
55
56
|
specification_version: 4
|
|
56
57
|
summary: Boolean Lucene to Regex convertor.
|
|
57
58
|
test_files:
|
|
59
|
+
- ".gitignore"
|
|
58
60
|
- Gemfile
|
|
59
61
|
- Gemfile.lock
|
|
60
62
|
- LICENSE
|