scoped_search 2.7.0 → 2.7.1
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/LICENSE +1 -1
- data/lib/scoped_search/auto_complete_builder.rb +13 -12
- data/lib/scoped_search/definition.rb +6 -0
- data/lib/scoped_search/version.rb +1 -1
- data/spec/integration/auto_complete_spec.rb +26 -0
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1847a5debfd78493233e7bb02f6ab09e7f97716
|
4
|
+
data.tar.gz: 1956d02a802a331f3ee7b8e6a555b09d49104942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26c1ffaeb3af331ff878db933bebec8c7e56066801ba5c94fc2771c3d07f8c1da6699bf4ec14b932ef318b42ecfc576eb17c984f8f1bdae450658cb5adb2c720
|
7
|
+
data.tar.gz: 34a33ccb2d74cecc67ea7fca254f9d4ab05e3f00c355bca71772104128b6c7b0f625fe866623c8353b1e9e8dcbd09483a23e1f848d4ea20e5814880949bd449e
|
data/LICENSE
CHANGED
@@ -140,9 +140,10 @@ module ScopedSearch
|
|
140
140
|
# for dotted field names compact the suggestions list to be one suggestion
|
141
141
|
# unless the user has typed the relation name entirely or the suggestion list
|
142
142
|
# is short.
|
143
|
-
|
143
|
+
last_token = tokens.last.to_s
|
144
|
+
if (suggestions.size > 10 && (tokens.empty? || !last_token.include?('.')) && !is_value)
|
144
145
|
suggestions = suggestions.map do |s|
|
145
|
-
s.to_s.split('.')[0].end_with?(
|
146
|
+
!last_token.empty? && s.to_s.split('.')[0].end_with?(last_token) ? s.to_s : s.to_s.split('.')[0]
|
146
147
|
end
|
147
148
|
end
|
148
149
|
|
@@ -196,16 +197,16 @@ module ScopedSearch
|
|
196
197
|
return complete_date_value if field.temporal?
|
197
198
|
return complete_key_value(field, token, val) if field.key_field
|
198
199
|
|
199
|
-
|
200
|
-
opts
|
201
|
-
opts.merge!(:limit => 20, :select => "DISTINCT #{table}.#{field.field}")
|
200
|
+
opts = value_conditions(field.quoted_field, val)
|
201
|
+
opts.merge!(:limit => 20, :select => "DISTINCT #{field.quoted_field}")
|
202
202
|
|
203
|
-
return completer_scope(field
|
203
|
+
return completer_scope(field).all(opts).map(&field.field).compact.map{|v| v.to_s =~ /\s+/ ? "\"#{v}\"" : v}
|
204
204
|
end
|
205
205
|
|
206
|
-
def completer_scope(
|
207
|
-
|
208
|
-
klass.completer_scope(@options)
|
206
|
+
def completer_scope(field)
|
207
|
+
klass = field.klass
|
208
|
+
scope = klass.respond_to?(:completer_scope) ? klass.completer_scope(@options) : klass
|
209
|
+
scope.respond_to?(:reorder) ? scope.reorder(field.quoted_field) : scope.scoped(:order => field.quoted_field)
|
209
210
|
end
|
210
211
|
|
211
212
|
# set value completer
|
@@ -232,11 +233,11 @@ module ScopedSearch
|
|
232
233
|
# complete values in a key-value schema
|
233
234
|
def complete_key_value(field, token, val)
|
234
235
|
key_name = token.sub(/^.*\./,"")
|
235
|
-
key_opts = value_conditions(field.
|
236
|
+
key_opts = value_conditions(field.quoted_field,val).merge(:conditions => {field.key_field => key_name})
|
236
237
|
key_klass = field.key_klass.first(key_opts)
|
237
238
|
raise ScopedSearch::QueryNotSupported, "Field '#{key_name}' not recognized for searching!" if key_klass.nil?
|
238
239
|
|
239
|
-
opts = {:select => "DISTINCT #{field.
|
240
|
+
opts = {:limit => 20, :select => "DISTINCT #{field.quoted_field}"}
|
240
241
|
if(field.key_klass != field.klass)
|
241
242
|
key = field.key_klass.to_s.gsub(/.*::/,'').underscore.to_sym
|
242
243
|
fk = field.klass.reflections[key].association_foreign_key.to_sym
|
@@ -244,7 +245,7 @@ module ScopedSearch
|
|
244
245
|
else
|
245
246
|
opts.merge!(key_opts)
|
246
247
|
end
|
247
|
-
return completer_scope(field
|
248
|
+
return completer_scope(field).all(opts).map(&field.field).compact.map{|v| v.to_s =~ /\s+/ ? "\"#{v}\"" : v}
|
248
249
|
end
|
249
250
|
|
250
251
|
#this method returns conditions for selecting completion from partial value
|
@@ -139,6 +139,12 @@ module ScopedSearch
|
|
139
139
|
order = (options[:default_order].to_s.downcase.include?('desc')) ? "DESC" : "ASC"
|
140
140
|
return "#{field_name} #{order}"
|
141
141
|
end
|
142
|
+
|
143
|
+
# Return 'table'.'column' with the correct database quotes
|
144
|
+
def quoted_field
|
145
|
+
c = klass.connection
|
146
|
+
"#{c.quote_table_name(klass.table_name)}.#{c.quote_column_name(field)}"
|
147
|
+
end
|
142
148
|
end
|
143
149
|
|
144
150
|
attr_reader :klass
|
@@ -12,6 +12,9 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
12
12
|
ActiveRecord::Migration.create_table(:bars, :force => true) do |t|
|
13
13
|
t.integer :foo_id
|
14
14
|
t.string :related
|
15
|
+
t.string :other_a
|
16
|
+
t.string :other_b
|
17
|
+
t.string :other_c
|
15
18
|
end
|
16
19
|
|
17
20
|
ActiveRecord::Migration.create_table(:foos, :force => true) do |t|
|
@@ -30,12 +33,16 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
30
33
|
|
31
34
|
class ::Foo < ActiveRecord::Base
|
32
35
|
has_many :bars
|
36
|
+
default_scope { order(:string) }
|
33
37
|
|
34
38
|
scoped_search :on => [:string, :int, :date]
|
35
39
|
scoped_search :on => :another, :default_operator => :eq, :alias => :alias
|
36
40
|
scoped_search :on => :explicit, :only_explicit => true, :complete_value => true
|
37
41
|
scoped_search :on => :deprecated, :complete_enabled => false
|
38
42
|
scoped_search :on => :related, :in => :bars, :rename => 'bars.related'.to_sym
|
43
|
+
scoped_search :on => :other_a, :in => :bars, :rename => 'bars.other_a'.to_sym
|
44
|
+
scoped_search :on => :other_b, :in => :bars, :rename => 'bars.other_b'.to_sym
|
45
|
+
scoped_search :on => :other_c, :in => :bars, :rename => 'bars.other_c'.to_sym
|
39
46
|
end
|
40
47
|
|
41
48
|
class ::Infoo < ::Foo
|
@@ -187,5 +194,24 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
187
194
|
Foo.complete_for('bars.related = ').should eql([])
|
188
195
|
end
|
189
196
|
end
|
197
|
+
|
198
|
+
# When options list is long (>10) and some of the options are in the format 'common.detail'
|
199
|
+
# the list should be shorten to include only 'common', the details part should be unfolded
|
200
|
+
# when the 'common.' part is typed or the options list size is reduced by typing part of
|
201
|
+
# the string.
|
202
|
+
context 'dotted options in the completion list' do
|
203
|
+
it "query that starts with space should not include the dotted options" do
|
204
|
+
Foo.complete_for(' ').should have(9).items
|
205
|
+
end
|
206
|
+
|
207
|
+
it "query that starts with the dotted string should include the dotted options" do
|
208
|
+
Foo.complete_for('bars.').should have(4).items
|
209
|
+
end
|
210
|
+
|
211
|
+
it "query that starts with part of the dotted string should include the dotted options" do
|
212
|
+
Foo.complete_for('b').should have(4).items
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
190
216
|
end
|
191
217
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amos Benari
|
@@ -10,48 +10,48 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-03-
|
13
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 2.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - '>='
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: 2.1.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rspec
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ~>
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '2.0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '2.0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rake
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - '>='
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - '>='
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
description: " Scoped search makes it easy to search your ActiveRecord-based models.\n
|
@@ -74,8 +74,8 @@ extensions: []
|
|
74
74
|
extra_rdoc_files:
|
75
75
|
- README.rdoc
|
76
76
|
files:
|
77
|
-
-
|
78
|
-
-
|
77
|
+
- .gitignore
|
78
|
+
- .travis.yml
|
79
79
|
- Gemfile
|
80
80
|
- Gemfile.activerecord2
|
81
81
|
- Gemfile.activerecord3
|
@@ -127,27 +127,27 @@ licenses: []
|
|
127
127
|
metadata: {}
|
128
128
|
post_install_message:
|
129
129
|
rdoc_options:
|
130
|
-
-
|
130
|
+
- --title
|
131
131
|
- scoped_search
|
132
|
-
-
|
132
|
+
- --main
|
133
133
|
- README.rdoc
|
134
|
-
-
|
135
|
-
-
|
134
|
+
- --line-numbers
|
135
|
+
- --inline-source
|
136
136
|
require_paths:
|
137
137
|
- lib
|
138
138
|
required_ruby_version: !ruby/object:Gem::Requirement
|
139
139
|
requirements:
|
140
|
-
- -
|
140
|
+
- - '>='
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0'
|
143
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- -
|
145
|
+
- - '>='
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
150
|
+
rubygems_version: 2.0.3
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: Easily search you ActiveRecord models with a simple query language using
|