pose 1.2.2 → 1.2.3
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/README.md +5 -3
 - data/lib/pose/static_api.rb +5 -5
 - data/lib/pose/version.rb +1 -1
 - data/spec/pose_api_spec.rb +30 -6
 - metadata +2 -2
 
    
        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 
     | 
    
         
            -
            *  
     | 
| 
       9 
     | 
    
         
            -
            * The  
     | 
| 
      
 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 
     | 
    
         | 
    
        data/lib/pose/static_api.rb
    CHANGED
    
    | 
         @@ -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) 
     | 
| 
      
 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
    
    
    
        data/spec/pose_api_spec.rb
    CHANGED
    
    | 
         @@ -162,14 +162,38 @@ describe Pose do 
     | 
|
| 
       162 
162 
     | 
    
         | 
| 
       163 
163 
     | 
    
         
             
                describe "'limit' parameter" do
         
     | 
| 
       164 
164 
     | 
    
         | 
| 
       165 
     | 
    
         
            -
                   
     | 
| 
       166 
     | 
    
         
            -
                    FactoryGirl.create :posable_one, text: 'foo  
     | 
| 
       167 
     | 
    
         
            -
                    FactoryGirl.create :posable_one, text: 'foo  
     | 
| 
       168 
     | 
    
         
            -
                    FactoryGirl.create :posable_one, text: 'foo  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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. 
     | 
| 
      
 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- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-10-07 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rails
         
     |