command_search 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/command_search/aliaser.rb +2 -2
- data/lib/command_search/memory.rb +17 -5
- data/lib/command_search/mongoer.rb +12 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ff69a298e109d79d1cf70f7bc0d1470129d447d
|
4
|
+
data.tar.gz: 37bfc67ff6702e307087611b5e75db52ce6334c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b53dbc26c9a8db5cd13c48b4def9065f29031fab0ed1336cefbb94f6e197ce7172db18e5b81937a4ee68d08a0ec700cd90145bf0996f1d5af32d70423b6f10ec
|
7
|
+
data.tar.gz: 5f5a24aed587abe88c7408c3855360826b7fedcc00ab7f242e161717a8858465f82196aacb5d046ed9b98b985e6e88f843aeeb97b2b47dfcb4da00038cd6b318
|
@@ -3,8 +3,8 @@ module CommandSearch
|
|
3
3
|
module_function
|
4
4
|
|
5
5
|
def build_regex(str)
|
6
|
-
head_border = '(
|
7
|
-
tail_border = '(?=$|\
|
6
|
+
head_border = '(?<=^|[^:\w])'
|
7
|
+
tail_border = '(?=$|\W)'
|
8
8
|
Regexp.new(head_border + Regexp.escape(str) + tail_border, 'i')
|
9
9
|
end
|
10
10
|
|
@@ -26,11 +26,17 @@ module CommandSearch
|
|
26
26
|
elsif !item.key?(cmd)
|
27
27
|
return false
|
28
28
|
elsif val[1][:type] == :str
|
29
|
-
item[cmd][/#{Regexp.escape(cmd_search)}/
|
29
|
+
item[cmd][/#{Regexp.escape(cmd_search)}/i]
|
30
30
|
elsif val[1][:type] == :quoted_str
|
31
|
-
|
31
|
+
regex = /\b#{Regexp.escape(cmd_search)}\b/
|
32
|
+
if cmd_search.first[/\W/] || cmd_search.last[/\W/]
|
33
|
+
head_border = '(?<=^|[^:+\w])'
|
34
|
+
tail_border = '(?=$|[^:+\w])'
|
35
|
+
regex = Regexp.new(head_border + Regexp.escape(cmd_search) + tail_border)
|
36
|
+
end
|
37
|
+
item[cmd][regex]
|
32
38
|
else
|
33
|
-
item[cmd].to_s[/#{Regexp.escape(cmd_search)}/
|
39
|
+
item[cmd].to_s[/#{Regexp.escape(cmd_search)}/i]
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
@@ -77,9 +83,15 @@ module CommandSearch
|
|
77
83
|
case node[:nest_type]
|
78
84
|
when nil
|
79
85
|
if node[:type] == :quoted_str
|
80
|
-
|
86
|
+
regex = /\b#{Regexp.escape(val)}\b/
|
87
|
+
if val.first[/\W/] || val.last[/\W/]
|
88
|
+
head_border = '(?<=^|[^:+\w])'
|
89
|
+
tail_border = '(?=$|[^:+\w])'
|
90
|
+
regex = Regexp.new(head_border + Regexp.escape(val) + tail_border)
|
91
|
+
end
|
92
|
+
field_vals.any? { |x| x.to_s[regex] }
|
81
93
|
else
|
82
|
-
field_vals.any? { |x| x.to_s[/#{Regexp.escape(val)}/
|
94
|
+
field_vals.any? { |x| x.to_s[/#{Regexp.escape(val)}/i] }
|
83
95
|
end
|
84
96
|
when :colon
|
85
97
|
command_check(item, val, command_types)
|
@@ -9,8 +9,13 @@ module CommandSearch
|
|
9
9
|
fields = [fields] unless fields.is_a?(Array)
|
10
10
|
if ast_node[:type] == :quoted_str
|
11
11
|
regex = /\b#{Regexp.escape(str)}\b/
|
12
|
+
if str.first[/\W/] || str.last[/\W/]
|
13
|
+
head_border = '(?<=^|[^:+\w])'
|
14
|
+
tail_border = '(?=$|[^:+\w])'
|
15
|
+
regex = Regexp.new(head_border + Regexp.escape(str) + tail_border)
|
16
|
+
end
|
12
17
|
else
|
13
|
-
regex = /#{Regexp.escape(str)}/
|
18
|
+
regex = /#{Regexp.escape(str)}/i
|
14
19
|
end
|
15
20
|
if ast_node[:negate]
|
16
21
|
forms = fields.map { |f| { f => { '$not' => regex } } }
|
@@ -82,8 +87,13 @@ module CommandSearch
|
|
82
87
|
elsif type == String
|
83
88
|
if search_type == :quoted_str
|
84
89
|
val = /\b#{Regexp.escape(raw_val)}\b/
|
90
|
+
if raw_val.first[/\W/] || raw_val.last[/\W/]
|
91
|
+
head_border = '(?<=^|[^:+\w])'
|
92
|
+
tail_border = '(?=$|[^:+\w])'
|
93
|
+
val = Regexp.new(head_border + Regexp.escape(raw_val) + tail_border)
|
94
|
+
end
|
85
95
|
else
|
86
|
-
val = /#{Regexp.escape(raw_val)}/
|
96
|
+
val = /#{Regexp.escape(raw_val)}/i
|
87
97
|
end
|
88
98
|
elsif [Numeric, Integer].include?(type)
|
89
99
|
if raw_val == raw_val.to_i.to_s
|
@@ -111,10 +121,6 @@ module CommandSearch
|
|
111
121
|
end
|
112
122
|
end
|
113
123
|
|
114
|
-
# regex (case insensitive probably best default, and let
|
115
|
-
# proper regex and alias support allow developers to have
|
116
|
-
# case sensitive if they want maybe.)
|
117
|
-
|
118
124
|
if field_node[:negate] && (type == Numeric || type == String)
|
119
125
|
{ key => { '$not' => val } }
|
120
126
|
else
|