boogex 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9474689b9e61cffbef211549d9e942254c1d0e8
4
- data.tar.gz: f56c73ade74210ca6aa2a82e69936e7bedeb678a
3
+ metadata.gz: de3fe706280ac098115350c77c0420f36ca96af9
4
+ data.tar.gz: e9f87414d4bfd2d1ee3d617eabbd919f3e5fb777
5
5
  SHA512:
6
- metadata.gz: 19d9416eb7d615dee24a748f0405f81eb188264e168576ff66cba4e0086d790149605a3f3b09b1696e33cba81ec39c8ecf7c71587e4e838db68a3831d19b6c6f
7
- data.tar.gz: 41d95f425232c4ee624570d6121606cb65ef134919302f18aa458d278fec408963afdd80744b13fce032aabf72e0ebca5e8d62fa137e5c888b2573208aab8e9a
6
+ metadata.gz: bf3676878d21a6342639ca8f57671d80932442c4c266ce478be5a5a5320d45b23b721fe9a419c4739fbd3f8a456f9916e118a94ccc465cf876f36e9839c075ab
7
+ data.tar.gz: 0dab88ba6541a518550808c7cf6ae1a64b5c537adc5b4f056a7369243a274f9f7747e440d318b627179a69c940039f605aa22f8c39d5e4aec3ad5851181f710c
@@ -0,0 +1,3 @@
1
+ **.DS_Store
2
+ **.gem
3
+
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'boogex'
3
- s.version = '0.0.1'
3
+ s.version = '0.1.0'
4
4
  s.date = '2016-02-14'
5
5
  s.homepage = 'https://github.com/lexerdev/boogex.gem'
6
6
  s.license = 'MIT'
@@ -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
- '#{andify["' + array.join('", "') + '"]}'
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)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Boogex
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -8,28 +8,30 @@ describe Boogex do
8
8
  assert_equal expecting, result
9
9
  end
10
10
 
11
- it 'turns AND into andify array string' do
11
+ it 'turns boolean AND into AND array string' do
12
12
  string = 'This AND That'
13
- expecting = '#{andify["(?:This)", "(?:That)"]}'
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 = '#{andify["(?:This|That)", "(?:My self)"]}'
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 = '#{andify["#{andify["(?:asd|dd)", "(?:that)"]}", "(?:this)"]}|What?'
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.1
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