quest_search 0.0.3 → 0.0.4
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/quest_search/quest_search_on.rb +20 -3
- data/lib/quest_search/version.rb +1 -1
- metadata +1 -1
@@ -11,14 +11,14 @@ module QuestSearch
|
|
11
11
|
options = fields.extract_options!
|
12
12
|
|
13
13
|
@order = options[:order] || "id desc"
|
14
|
-
@limit = options[:limit] ||
|
14
|
+
@limit = options[:limit] || 100
|
15
15
|
|
16
16
|
cattr_accessor :quest_search_fields
|
17
17
|
|
18
18
|
self.quest_search_fields = fields
|
19
19
|
end
|
20
20
|
|
21
|
-
def quest_search_for(query, page_no = 1, page_size =
|
21
|
+
def quest_search_for(query, page_no = 1, page_size = 2**32)
|
22
22
|
words = query.to_s.split " "
|
23
23
|
conditions = words.map do |w|
|
24
24
|
self.quest_search_fields.map do |f|
|
@@ -26,9 +26,26 @@ module QuestSearch
|
|
26
26
|
end.join " OR "
|
27
27
|
end.join " OR "
|
28
28
|
|
29
|
-
|
29
|
+
offset = (page_no * page_size) - page_size
|
30
|
+
offset_ends = offset + page_size
|
31
|
+
|
32
|
+
results = self.where(conditions).order(@order).sort do |a, b|
|
30
33
|
b.points_for(query) <=> a.points_for(query)
|
31
34
|
end
|
35
|
+
|
36
|
+
end_results = []
|
37
|
+
|
38
|
+
results.each_with_index do |r, index|
|
39
|
+
if index == offset_ends
|
40
|
+
break
|
41
|
+
end
|
42
|
+
|
43
|
+
if index >= offset
|
44
|
+
end_results.push r
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end_results
|
32
49
|
end
|
33
50
|
end
|
34
51
|
|
data/lib/quest_search/version.rb
CHANGED