has_searcher 0.0.5.1 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,10 +25,17 @@ class Search < ActiveRecord::Base
25
25
  klass.search do | search |
26
26
  search.keywords keywords if search_columns.delete("keywords")
27
27
  search_columns.each do | column |
28
+ value = normalize(column)
28
29
  if column_for_attribute(column).type == :text
29
- search.keywords normalize(column), :fields => column
30
+ if fuzzy?(value)
31
+ search.adjust_solr_params do |params|
32
+ p params[:q] = value.split(/ /).map{ |value| "#{column}_text:#{value}"}.join(' ')
33
+ end
34
+ else
35
+ search.keywords value, :fields => column
36
+ end
30
37
  else
31
- search.with column, normalize(column)
38
+ search.with column, value
32
39
  end
33
40
  end
34
41
  search.paginate pagination if pagination.try(:any?)
@@ -58,7 +65,11 @@ class Search < ActiveRecord::Base
58
65
  end
59
66
 
60
67
  def normalize_term_column(text)
61
- text.gsub(/[^[:alnum:]]+/, ' ') if text
68
+ text.gsub(/[^[:alnum:]~]+/, ' ').strip if text
69
+ end
70
+
71
+ def fuzzy?(text)
72
+ text =~ /~/
62
73
  end
63
74
 
64
75
  def klass
@@ -1,3 +1,3 @@
1
1
  module HasSearcher
2
- VERSION = "0.0.5.1"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- - 1
10
- version: 0.0.5.1
8
+ - 6
9
+ version: 0.0.6
11
10
  platform: ruby
12
11
  authors:
13
12
  - Dmitry Lihachev
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-04-21 00:00:00 +07:00
17
+ date: 2011-04-23 00:00:00 +07:00
19
18
  default_executable:
20
19
  dependencies: []
21
20