pose 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,9 +4,10 @@ Pose ("Polymorphic Search") allows fulltext search for ActiveRecord objects.
4
4
 
5
5
  * Searches over several ActiveRecord classes at once.
6
6
  * The searchable fulltext content per document can be freely customized.
7
- * Uses the Rails database, no sparate search engines are necessary.
8
- * The algorithm is designed to work with any data store that allows for range queries: SQL and NoSQL.
9
- * The search runs very fast, doing simple queries over fully indexed columns.
7
+ * Uses the main Rails database, no sparate search engines are necessary.
8
+ * Does not require to add attributes to the searchable classes or their database tables.
9
+ * The algorithm is designed to work with any data store that allows for range queries, which covers pretty much every SQL or NoSQL database.
10
+ * The search is very fast, doing only simple queries over fully indexed columns.
10
11
  * The search index provides data for autocomplete search fields.
11
12
 
12
13
 
@@ -120,6 +121,7 @@ result = Pose.search 'foo',
120
121
  MyClass,
121
122
  limit: 3, # Limit the result count to 3.
122
123
  result_type: :ids # Don't load the resulting objects, return just their ids.
124
+ where: [ public: true, ['user_id <> ?', @user.id] ] # Additional where clauses for when the result entries are loaded from the database.
123
125
  ```
124
126
 
125
127
 
@@ -51,19 +51,18 @@ module Pose
51
51
  else
52
52
  # Here we have results.
53
53
 
54
- # Limit.
55
- ids = ids.slice(0, options[:limit]) if options[:limit]
56
-
57
54
  if options[:result_type] == :ids
58
55
  # Ids requested for result.
59
56
 
60
57
  if options[:where].blank?
61
58
  # No scope.
62
- result[result_class] = ids
59
+ result[result_class] = options[:limit] ? ids.slice(0, options[:limit]) : ids
63
60
  else
64
61
  # We have a scope.
65
62
  options[:where].each do |scope|
66
- query = result_class.select('id').where('id IN (?)', ids).where(scope).to_sql
63
+ query = result_class.select('id').where('id IN (?)', ids).where(scope)
64
+ query = query.limit(options[:limit]) unless options[:limit].blank?
65
+ query = query.to_sql
67
66
  result[result_class] = result_class.connection.select_values(query).map(&:to_i)
68
67
  end
69
68
  end
@@ -72,6 +71,7 @@ module Pose
72
71
  # Classes requested for result.
73
72
 
74
73
  result[result_class] = result_class.where(id: ids)
74
+ result[result_class] = result[result_class].limit(options[:limit]) unless options[:limit].blank?
75
75
  unless options[:where].blank?
76
76
  options[:where].each do |scope|
77
77
  result[result_class] = result[result_class].where('id IN (?)', ids).where(scope)
data/lib/pose/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pose
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
@@ -162,14 +162,38 @@ describe Pose do
162
162
 
163
163
  describe "'limit' parameter" do
164
164
 
165
- it 'works' do
166
- FactoryGirl.create :posable_one, text: 'foo one'
167
- FactoryGirl.create :posable_one, text: 'foo two'
168
- FactoryGirl.create :posable_one, text: 'foo three'
165
+ before :each do
166
+ @pos1 = FactoryGirl.create :posable_one, text: 'foo', private: true
167
+ @pos2 = FactoryGirl.create :posable_one, text: 'foo', private: true
168
+ @pos3 = FactoryGirl.create :posable_one, text: 'foo', private: false
169
+ end
169
170
 
170
- result = Pose.search 'foo', PosableOne, limit: 2
171
+ context 'with ids and no scope' do
172
+ it 'limits the result set to the given number' do
173
+ result = Pose.search 'foo', PosableOne, result_type: :ids, limit: 1
174
+ result[PosableOne].should have(1).item
175
+ end
176
+ end
171
177
 
172
- result[PosableOne].should have(2).items
178
+ context 'with ids and scope' do
179
+ it 'limits the result set to the given number' do
180
+ result = Pose.search 'foo', PosableOne, result_type: :ids, limit: 1, where: [private: false]
181
+ result[PosableOne].should have(1).item
182
+ end
183
+ end
184
+
185
+ context 'with classes and no scope' do
186
+ it 'limits the result set to the given number' do
187
+ result = Pose.search 'foo', PosableOne, limit: 1
188
+ result[PosableOne].should have(1).item
189
+ end
190
+ end
191
+
192
+ context 'with classes and scope' do
193
+ it 'limits the result set to the given number' do
194
+ result = Pose.search 'foo', PosableOne, limit: 1, where: [private: false]
195
+ result[PosableOne].should have(1).item
196
+ end
173
197
  end
174
198
  end
175
199
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pose
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-06 00:00:00.000000000 Z
12
+ date: 2012-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails