quest_search 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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] || 1000
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 = nil)
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
- self.where(conditions).order(@order).limit(@limit).sort do |a, b|
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
 
@@ -1,3 +1,3 @@
1
1
  module QuestSearch
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quest_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: