has_searcher 0.0.6.1 → 0.0.7
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 +17 -3
- data/lib/has_searcher/version.rb +1 -1
- metadata +3 -4
data/lib/app/models/search.rb
CHANGED
@@ -13,6 +13,12 @@ class Search < ActiveRecord::Base
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
def pagination
|
17
|
+
@paginatation ||= {}
|
18
|
+
@paginatation.merge! :per_page => per_page if respond_to? :per_page
|
19
|
+
@paginatation
|
20
|
+
end
|
21
|
+
|
16
22
|
delegate :results, :to => :search
|
17
23
|
|
18
24
|
def result_ids
|
@@ -26,7 +32,7 @@ class Search < ActiveRecord::Base
|
|
26
32
|
search.keywords keywords if search_columns.delete("keywords")
|
27
33
|
search_columns.each do | column |
|
28
34
|
value = normalize(column)
|
29
|
-
if column_for_attribute(column).type == :text
|
35
|
+
if column_for_attribute(column).type == :text && self.class.serialized_attributes[column] != Array
|
30
36
|
if fuzzy?(value)
|
31
37
|
search.adjust_solr_params do |params|
|
32
38
|
params[:q] = value.split(/ /).map{ |value| "#{column}_text:#{value}"}.join(' ')
|
@@ -35,9 +41,17 @@ class Search < ActiveRecord::Base
|
|
35
41
|
search.keywords value, :fields => column
|
36
42
|
end
|
37
43
|
else
|
38
|
-
|
44
|
+
case column
|
45
|
+
when /_lt$/
|
46
|
+
search.with(column[0..-4]).less_than(value)
|
47
|
+
when /_gt$/
|
48
|
+
search.with(column[0..-4]).greater_than(value)
|
49
|
+
else
|
50
|
+
search.with column, value
|
51
|
+
end
|
39
52
|
end
|
40
53
|
end
|
54
|
+
search.order_by order_by if respond_to?(:order_by) && order_by.present?
|
41
55
|
search.paginate pagination if pagination.try(:any?)
|
42
56
|
end
|
43
57
|
end
|
@@ -47,7 +61,7 @@ class Search < ActiveRecord::Base
|
|
47
61
|
end
|
48
62
|
|
49
63
|
def search_columns
|
50
|
-
@search_columns ||= self.class.column_names.select{ |column| normalize(column).present? }
|
64
|
+
@search_columns ||= (self.class.column_names - %w[per_page order_by]).select{ |column| normalize(column).present? }
|
51
65
|
end
|
52
66
|
|
53
67
|
def normalize(column)
|
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.6.1
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
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-
|
17
|
+
date: 2011-05-16 00:00:00 +07:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|