scoped_search 3.1.0 → 3.2.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: f8f3158e1d95aa30c3129d1f93fd908c7a52c8d4
4
- data.tar.gz: db5a65eeebd58513c499ea3b6bbfb3a8723702d8
3
+ metadata.gz: fa5c8206f13488ac53e60199ef5a08fc825c8654
4
+ data.tar.gz: ad9258a231663b704d4bc28728059c19f1846fb5
5
5
  SHA512:
6
- metadata.gz: 34c8500136d8d3baf89313d09a9cfeb817798790ce27d16009745ed6af40dbc9ec47f3c2532dab44945c266cb491973179506b5e0a2950d02db5f64c337716f0
7
- data.tar.gz: bf5ea94257096ead71261964695ba7fed482cbca7c5b5acfd5afed3653884312e5fda2d9c8d11262f3c7f7b710c78ce9c75b060b3ba5391bfa182eefd738fcf4
6
+ metadata.gz: d9201e227813757d3fb3cba025d2692ab946f74206912c95b5b04db74932b2a350a7323085084a99ee7560afb584de91eb5cd931cad515403662170486121c53
7
+ data.tar.gz: 29db95daea73ad5e2f4fa789dec6029d685ae2360a36d2063d6c58004191e1e202e25ab16f38a98d6dce3d5eb1b8b1ca0e74838a91892927254a366f4f7fce1e
data/CHANGELOG.rdoc CHANGED
@@ -8,6 +8,13 @@ Please add an entry to the "Unreleased changes" section in your pull requests.
8
8
 
9
9
  *Nothing yet*
10
10
 
11
+ === Version 3.2.0
12
+
13
+ - In MySQL, case sensitivity is now determined by the collation of the column, and
14
+ is no longer enforced in the SQL query. This allows MySQL to use indices for
15
+ queries.
16
+ - Fix auto-completer for numeric fields.
17
+
11
18
  === Version 3.1.0
12
19
 
13
20
  - Add support for ActiveRecord 4.2.
@@ -128,7 +128,7 @@ module ScopedSearch
128
128
  def build_suggestions(suggestions, is_value)
129
129
  return [] if (suggestions.blank?)
130
130
 
131
- q=query
131
+ q = query
132
132
  unless q =~ /(\s|\)|,)$/ || last_token_is(COMPARISON_OPERATORS)
133
133
  val = Regexp.escape(tokens.last.to_s).gsub('\*', '.*')
134
134
  suggestions = suggestions.map {|s| s if s.to_s =~ /^"?#{val}"?/i}.compact
@@ -201,7 +201,7 @@ module ScopedSearch
201
201
  return complete_key_value(field, token, val) if field.key_field
202
202
 
203
203
  completer_scope(field)
204
- .where(value_conditions(field.quoted_field, val))
204
+ .where(value_conditions(field, val))
205
205
  .select("DISTINCT #{field.quoted_field}")
206
206
  .limit(20)
207
207
  .map(&field.field)
@@ -261,7 +261,7 @@ module ScopedSearch
261
261
 
262
262
  # This method returns conditions for selecting completion from partial value
263
263
  def value_conditions(field, val)
264
- val.blank? ? nil : "#{field.quoted_field} LIKE '#{val.gsub("'","''")}%'".tr_s('%*', '%')
264
+ val.blank? ? nil : "CAST(#{field.quoted_field} as CHAR(50)) LIKE '#{val.gsub("'","''")}%'".tr_s('%*', '%')
265
265
  end
266
266
 
267
267
  # This method complete infix operators by field type
@@ -478,24 +478,6 @@ module ScopedSearch
478
478
  end
479
479
  end
480
480
 
481
- # The MysqlAdapter makes sure that case sensitive comparisons are used
482
- # when using the (not) equals operator, regardless of the field's
483
- # collation setting.
484
- class Mysql2Adapter < ScopedSearch::QueryBuilder
485
- # Patches the default <tt>sql_operator</tt> method to add
486
- # <tt>BINARY</tt> after the equals and not equals operator to force
487
- # case-sensitive comparisons.
488
- def sql_operator(operator, field)
489
- if [:ne, :eq].include?(operator) && field.textual?
490
- "#{SQL_OPERATORS[operator]} BINARY"
491
- else
492
- super(operator, field)
493
- end
494
- end
495
- end
496
-
497
- MysqlAdapter = Mysql2Adapter
498
-
499
481
  # The PostgreSQLAdapter make sure that searches are case sensitive when
500
482
  # using the like/unlike operators, by using the PostrgeSQL-specific
501
483
  # <tt>ILIKE operator</tt> instead of <tt>LIKE</tt>.
@@ -505,7 +487,7 @@ module ScopedSearch
505
487
  # method if full text searching is enabled and a text search is being
506
488
  # performed.
507
489
  def sql_test(field, operator, value, lhs, &block)
508
- if [:like, :unlike].include?(operator) and field.full_text_search
490
+ if [:like, :unlike].include?(operator) && field.full_text_search
509
491
  yield(:parameter, value)
510
492
  negation = (operator == :unlike) ? "NOT " : ""
511
493
  locale = (field.full_text_search == true) ? 'english' : field.full_text_search
@@ -519,7 +501,7 @@ module ScopedSearch
519
501
  # method for ILIKE or @@ if full text searching is enabled.
520
502
  def sql_operator(operator, field)
521
503
  raise ScopedSearch::QueryNotSupported, "the operator '#{operator}' is not supported for field type '#{field.type}'" if [:like, :unlike].include?(operator) and !field.textual?
522
- return '@@' if [:like, :unlike].include?(operator) and field.full_text_search
504
+ return '@@' if [:like, :unlike].include?(operator) && field.full_text_search
523
505
  case operator
524
506
  when :like then 'ILIKE'
525
507
  when :unlike then 'NOT ILIKE'
@@ -1,3 +1,3 @@
1
1
  module ScopedSearch
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -9,6 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ['Amos Benari', 'Willem van Bergen', 'Wes Hays']
10
10
  gem.email = ['abenari@redhat.com', 'willem@railsdoctors.com', 'weshays@gbdev.com']
11
11
  gem.homepage = "https://github.com/wvanbergen/scoped_search/wiki"
12
+ gem.license = "MIT"
12
13
  gem.summary = %q{Easily search you ActiveRecord models with a simple query language using a named scope}
13
14
  gem.description = <<-EOS
14
15
  Scoped search makes it easy to search your ActiveRecord-based models.
@@ -35,7 +35,8 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
35
35
  has_many :bars
36
36
  default_scope { order(:string) }
37
37
 
38
- scoped_search :on => [:string, :int, :date]
38
+ scoped_search :on => [:string, :date]
39
+ scoped_search :on => [:int], :complete_value => true
39
40
  scoped_search :on => :another, :default_operator => :eq, :alias => :alias
40
41
  scoped_search :on => :explicit, :only_explicit => true, :complete_value => true
41
42
  scoped_search :on => :deprecated, :complete_enabled => false
@@ -49,7 +50,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
49
50
  end
50
51
 
51
52
  @foo_1 = Foo.create!(:string => 'foo', :another => 'temp 1', :explicit => 'baz', :int => 9 , :date => 'February 8, 2011' , :unindexed => 10)
52
- Foo.create!(:string => 'bar', :another => 'temp 2', :explicit => 'baz', :int => 9 , :date => 'February 10, 2011', :unindexed => 10)
53
+ Foo.create!(:string => 'bar', :another => 'temp 2', :explicit => 'baz', :int => 22 , :date => 'February 10, 2011', :unindexed => 10)
53
54
  Foo.create!(:string => 'baz', :another => nil, :explicit => nil , :int => nil, :date => nil , :unindexed => nil)
54
55
 
55
56
  Bar.create!(:related => 'lala', :foo => @foo_1)
@@ -176,6 +177,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
176
177
  end
177
178
  end
178
179
 
180
+
179
181
  context 'exceptional search strings' do
180
182
 
181
183
  it "query that starts with 'or'" do
@@ -213,5 +215,11 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
213
215
  end
214
216
 
215
217
  end
218
+
219
+ context 'autocompleting integer comparisons' do
220
+ it 'should autocomplete numerical fields' do
221
+ Foo.complete_for('int > 2').first.should match(/22/)
222
+ end
223
+ end
216
224
  end
217
225
  end
@@ -88,14 +88,6 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
88
88
  @class.search_for('string ~ FOO').length.should == 1
89
89
  end
90
90
 
91
- it "should not find records without case sensitivity when using the = operator" do
92
- @class.search_for('string = FOO').length.should == 0
93
- end
94
-
95
- it "should find records without case sensitivity when using the != operator" do
96
- @class.search_for('string != FOO').length.should == 3
97
- end
98
-
99
91
  it "should find records without case sensitivity when using the NOT LIKE operator" do
100
92
  @class.search_for('string !~ FOO').length.should == 2
101
93
  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: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amos Benari
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-01-15 00:00:00.000000000 Z
13
+ date: 2015-02-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -128,7 +128,8 @@ files:
128
128
  - spec/unit/rails_helper_spec.rb
129
129
  - spec/unit/tokenizer_spec.rb
130
130
  homepage: https://github.com/wvanbergen/scoped_search/wiki
131
- licenses: []
131
+ licenses:
132
+ - MIT
132
133
  metadata: {}
133
134
  post_install_message:
134
135
  rdoc_options: