scoped_search 2.3.4 → 2.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.
data/lib/scoped_search.rb
CHANGED
@@ -14,7 +14,7 @@ module ScopedSearch
|
|
14
14
|
|
15
15
|
# The current scoped_search version. Do not change thisvalue by hand,
|
16
16
|
# because it will be updated automatically by the gem release script.
|
17
|
-
VERSION = "2.3.
|
17
|
+
VERSION = "2.3.5"
|
18
18
|
|
19
19
|
# The ClassMethods module will be included into the ActiveRecord::Base class
|
20
20
|
# to add the <tt>ActiveRecord::Base.scoped_search</tt> method and the
|
@@ -89,7 +89,7 @@ module ScopedSearch
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def is_left_hand(node)
|
92
|
-
field = definition.field_by_name(node.value)
|
92
|
+
field = definition.field_by_name(node.value) if node.respond_to?(:value)
|
93
93
|
lh = field.nil? || field.key_field && !(query.end_with?(' '))
|
94
94
|
lh = lh || last_token_is(NULL_PREFIX_OPERATORS, 2)
|
95
95
|
lh = lh && !is_right_hand
|
@@ -132,8 +132,8 @@ module ScopedSearch
|
|
132
132
|
q=query
|
133
133
|
unless q =~ /(\s|\)|,)$/
|
134
134
|
val = Regexp.escape(tokens.last.to_s).gsub('\*', '.*')
|
135
|
-
suggestions = suggestions.map {|s| s if s.to_s =~
|
136
|
-
q.chomp!(tokens.last.to_s)
|
135
|
+
suggestions = suggestions.map {|s| s if s.to_s =~ /^"?#{val}"?/i}.compact
|
136
|
+
q.chomp!(/("?#{Regexp.escape(tokens.last.to_s)}"?)$/.match(q)[1])
|
137
137
|
end
|
138
138
|
|
139
139
|
# for doted field names compact the suggestions list to be one suggestion
|
@@ -167,10 +167,11 @@ module ScopedSearch
|
|
167
167
|
return ["#{name}."] if !val || !val.is_a?(String) || !(val.include?('.'))
|
168
168
|
val = val.sub(/.*\./,'')
|
169
169
|
|
170
|
-
|
171
|
-
|
170
|
+
table = field.key_klass.connection.quote_table_name(field.key_klass.table_name)
|
171
|
+
field_name = "#{table}.#{field.key_field}"
|
172
|
+
opts = value_conditions(field_name, val).merge(:limit => 20, :select => field_name, :group => field_name )
|
172
173
|
|
173
|
-
field.key_klass.all(opts).map(&
|
174
|
+
field.key_klass.all(opts).map(&field.key_field).compact.map{ |f| "#{name}.#{f} "}
|
174
175
|
end
|
175
176
|
|
176
177
|
# this method auto-completes values of fields that have a :complete_value marker
|
@@ -190,8 +191,8 @@ module ScopedSearch
|
|
190
191
|
return complete_date_value if field.temporal?
|
191
192
|
return complete_key_value(field, token, val) if field.key_field
|
192
193
|
|
193
|
-
opts = value_conditions(field.field, val)
|
194
194
|
table = field.klass.connection.quote_table_name(field.klass.table_name)
|
195
|
+
opts = value_conditions("#{table}.#{field.field}", val)
|
195
196
|
opts.merge!(:limit => 20, :select => "DISTINCT #{table}.#{field.field}")
|
196
197
|
|
197
198
|
return completer_scope(field.klass).all(opts).map(&field.field).compact.map{|v| v.to_s =~ /\s+/ ? "\"#{v}\"" : v}
|
@@ -243,7 +244,7 @@ module ScopedSearch
|
|
243
244
|
|
244
245
|
#this method returns conditions for selecting completion from partial value
|
245
246
|
def value_conditions(field_name, val)
|
246
|
-
return val.blank? ? {} : {:conditions => "#{field_name} LIKE '#{val}%'".tr_s('%*', '%')}
|
247
|
+
return val.blank? ? {} : {:conditions => "#{field_name} LIKE '#{val.gsub("'","''")}%'".tr_s('%*', '%')}
|
247
248
|
end
|
248
249
|
|
249
250
|
# This method complete infix operators by field type
|
@@ -164,7 +164,7 @@ module ScopedSearch
|
|
164
164
|
|
165
165
|
# this method return definitions::field object from string
|
166
166
|
def field_by_name(name)
|
167
|
-
field = fields[name.to_sym]
|
167
|
+
field = fields[name.to_sym] unless name.blank?
|
168
168
|
if field.nil?
|
169
169
|
dotted = name.to_s.split('.')[0]
|
170
170
|
field = fields[dotted.to_sym] unless dotted.nil?
|
data/scoped_search.gemspec
CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
3
3
|
|
4
4
|
# Do not change the version and date fields by hand. This will be done
|
5
5
|
# automatically by the gem release script.
|
6
|
-
s.version = "2.3.
|
7
|
-
s.date = "2011-10-
|
6
|
+
s.version = "2.3.5"
|
7
|
+
s.date = "2011-10-18"
|
8
8
|
|
9
9
|
s.summary = "Easily search you ActiveRecord models with a simple query language using a named scope."
|
10
10
|
s.description = <<-EOS
|
@@ -135,5 +135,24 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
135
135
|
Foo.complete_for('has string ').should_not contain('has string = ')
|
136
136
|
end
|
137
137
|
end
|
138
|
+
|
139
|
+
context 'exceptional search strings' do
|
140
|
+
|
141
|
+
it "query that starts with 'or'" do
|
142
|
+
Foo.complete_for('or ').should have(9).items
|
143
|
+
end
|
144
|
+
|
145
|
+
it "value completion with quotes" do
|
146
|
+
Foo.complete_for('string = "').should eql([])
|
147
|
+
end
|
148
|
+
|
149
|
+
it "value completion with single quote" do
|
150
|
+
Foo.complete_for("string = this is a 'valid' query").should eql([])
|
151
|
+
end
|
152
|
+
|
153
|
+
it "value auto completer for related tables" do
|
154
|
+
Foo.complete_for('bars.related = ').should eql([])
|
155
|
+
end
|
156
|
+
end
|
138
157
|
end
|
139
158
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 2.3.
|
9
|
+
- 5
|
10
|
+
version: 2.3.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Willem van Bergen
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-10-
|
19
|
+
date: 2011-10-18 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|