has_searcher 0.0.5.1 → 0.0.6
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/app/models/search.rb +14 -3
- data/lib/has_searcher/version.rb +1 -1
- metadata +3 -4
data/lib/app/models/search.rb
CHANGED
@@ -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
|
-
|
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,
|
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
|
data/lib/has_searcher/version.rb
CHANGED
metadata
CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
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-
|
17
|
+
date: 2011-04-23 00:00:00 +07:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|