mongoid_search 0.3.2 → 0.4.0
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.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +179 -116
- data/Rakefile +5 -2
- data/lib/mongoid_search.rb +14 -7
- data/lib/mongoid_search/log.rb +2 -1
- data/lib/mongoid_search/mongoid_search.rb +61 -42
- data/lib/mongoid_search/railtie.rb +2 -5
- data/lib/mongoid_search/tasks/mongoid_search.rake +16 -0
- data/lib/mongoid_search/util.rb +19 -18
- data/spec/models/category.rb +2 -0
- data/spec/models/product.rb +15 -6
- data/spec/models/subproduct.rb +2 -1
- data/spec/models/tag.rb +3 -2
- data/spec/models/variant.rb +3 -1
- data/spec/mongoid_search_spec.rb +231 -133
- data/spec/spec_helper.rb +4 -1
- data/spec/util_spec.rb +28 -29
- metadata +56 -54
- data/VERSION +0 -1
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -8,9 +8,10 @@ require 'database_cleaner' | |
| 8 8 | 
             
            require 'fast_stemmer'
         | 
| 9 9 | 
             
            require 'yaml'
         | 
| 10 10 | 
             
            require 'mongoid_search'
         | 
| 11 | 
            +
            require 'mongoid-compatibility'
         | 
| 11 12 |  | 
| 12 13 | 
             
            Mongoid.configure do |config|
         | 
| 13 | 
            -
              config.connect_to  | 
| 14 | 
            +
              config.connect_to 'mongoid_search_test'
         | 
| 14 15 | 
             
            end
         | 
| 15 16 |  | 
| 16 17 | 
             
            Dir["#{File.dirname(__FILE__)}/models/*.rb"].each { |file| require file }
         | 
| @@ -19,6 +20,8 @@ DatabaseCleaner.orm = :mongoid | |
| 19 20 |  | 
| 20 21 | 
             
            RSpec.configure do |config|
         | 
| 21 22 | 
             
              config.before(:all) do
         | 
| 23 | 
            +
                Mongoid.logger.level = Logger::INFO
         | 
| 24 | 
            +
                Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5_or_newer?
         | 
| 22 25 | 
             
                DatabaseCleaner.strategy = :truncation
         | 
| 23 26 | 
             
              end
         | 
| 24 27 |  | 
    
        data/spec/util_spec.rb
    CHANGED
    
    | @@ -1,8 +1,7 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
             | 
| 2 2 | 
             
            require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
         | 
| 3 3 |  | 
| 4 4 | 
             
            describe Mongoid::Search::Util do
         | 
| 5 | 
            -
             | 
| 6 5 | 
             
              before(:all) do
         | 
| 7 6 | 
             
                @default_proc = Mongoid::Search.stem_proc
         | 
| 8 7 | 
             
              end
         | 
| @@ -13,61 +12,61 @@ describe Mongoid::Search::Util do | |
| 13 12 |  | 
| 14 13 | 
             
              before do
         | 
| 15 14 | 
             
                Mongoid::Search.stem_keywords = false
         | 
| 16 | 
            -
                Mongoid::Search.ignore_list =  | 
| 15 | 
            +
                Mongoid::Search.ignore_list = ''
         | 
| 17 16 | 
             
                Mongoid::Search.stem_proc = @default_proc
         | 
| 18 17 | 
             
              end
         | 
| 19 18 |  | 
| 20 | 
            -
              it  | 
| 21 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 19 | 
            +
              it 'should return an empty array if no text is passed' do
         | 
| 20 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('')).to eq []
         | 
| 22 21 | 
             
              end
         | 
| 23 22 |  | 
| 24 | 
            -
              it  | 
| 25 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 23 | 
            +
              it 'should return an array of keywords' do
         | 
| 24 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('keyword').class).to eq Array
         | 
| 26 25 | 
             
              end
         | 
| 27 26 |  | 
| 28 | 
            -
              it  | 
| 29 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 27 | 
            +
              it 'should return an array of strings' do
         | 
| 28 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('keyword').first.class).to eq String
         | 
| 30 29 | 
             
              end
         | 
| 31 30 |  | 
| 32 | 
            -
              it  | 
| 33 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 31 | 
            +
              it 'should remove accents from the text passed' do
         | 
| 32 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('café')).to eq ['cafe']
         | 
| 34 33 | 
             
              end
         | 
| 35 34 |  | 
| 36 | 
            -
              it  | 
| 37 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 35 | 
            +
              it 'should downcase the text passed' do
         | 
| 36 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('CaFé')).to eq ['cafe']
         | 
| 38 37 | 
             
              end
         | 
| 39 38 |  | 
| 40 | 
            -
              it  | 
| 41 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 39 | 
            +
              it 'should downcase utf-8 chars of the text passed' do
         | 
| 40 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('Кафе')).to eq ['кафе']
         | 
| 42 41 | 
             
              end
         | 
| 43 42 |  | 
| 44 | 
            -
              it  | 
| 45 | 
            -
                Mongoid::Search::Util.normalize_keywords("CaFé-express.com delicious;come visit, and 'win' an \"iPad\""). | 
| 43 | 
            +
              it 'should split whitespaces, hifens, dots, underlines, etc..' do
         | 
| 44 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords("CaFé-express.com delicious;come visit, and 'win' an \"iPad\"")).to eq %w[cafe express com delicious come visit and win an ipad]
         | 
| 46 45 | 
             
              end
         | 
| 47 46 |  | 
| 48 | 
            -
              it  | 
| 47 | 
            +
              it 'should stem keywords' do
         | 
| 49 48 | 
             
                Mongoid::Search.stem_keywords = true
         | 
| 50 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 49 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('A runner running and eating')).to eq %w[runner run and eat]
         | 
| 51 50 | 
             
              end
         | 
| 52 51 |  | 
| 53 | 
            -
              it  | 
| 52 | 
            +
              it 'should stem keywords using a custom proc' do
         | 
| 54 53 | 
             
                Mongoid::Search.stem_keywords = true
         | 
| 55 | 
            -
                Mongoid::Search.stem_proc =  | 
| 54 | 
            +
                Mongoid::Search.stem_proc = ->(word) { word.upcase }
         | 
| 56 55 |  | 
| 57 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 56 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('A runner running and eating')).to eq %w[RUNNER RUNNING AND EATING]
         | 
| 58 57 | 
             
              end
         | 
| 59 58 |  | 
| 60 | 
            -
              it  | 
| 59 | 
            +
              it 'should ignore keywords from ignore list' do
         | 
| 61 60 | 
             
                Mongoid::Search.stem_keywords = true
         | 
| 62 | 
            -
                Mongoid::Search.ignore_list = YAML. | 
| 63 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 61 | 
            +
                Mongoid::Search.ignore_list = YAML.safe_load(File.open(File.dirname(__FILE__) + '/config/ignorelist.yml'))['ignorelist']
         | 
| 62 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('An amazing awesome runner running and eating')).to eq %w[an runner run and eat]
         | 
| 64 63 | 
             
              end
         | 
| 65 64 |  | 
| 66 | 
            -
              it  | 
| 67 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 65 | 
            +
              it 'should ignore keywords with less than two words' do
         | 
| 66 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('A runner running')).not_to include 'a'
         | 
| 68 67 | 
             
              end
         | 
| 69 68 |  | 
| 70 | 
            -
              it  | 
| 71 | 
            -
                Mongoid::Search::Util.normalize_keywords( | 
| 69 | 
            +
              it 'should not ignore numbers' do
         | 
| 70 | 
            +
                expect(Mongoid::Search::Util.normalize_keywords('Ford T 1908')).to include '1908'
         | 
| 72 71 | 
             
              end
         | 
| 73 72 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,94 +1,97 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: mongoid_search
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
               | 
| 5 | 
            -
              version: 0.3.2
         | 
| 4 | 
            +
              version: 0.4.0
         | 
| 6 5 | 
             
            platform: ruby
         | 
| 7 6 | 
             
            authors:
         | 
| 8 7 | 
             
            - Mauricio Zaffari
         | 
| 9 8 | 
             
            autorequire: 
         | 
| 10 9 | 
             
            bindir: bin
         | 
| 11 10 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 11 | 
            +
            date: 2020-07-07 00:00:00.000000000 Z
         | 
| 13 12 | 
             
            dependencies:
         | 
| 14 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            -
              name:  | 
| 16 | 
            -
              type: :runtime
         | 
| 14 | 
            +
              name: fast-stemmer
         | 
| 17 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 18 | 
            -
                none: false
         | 
| 19 16 | 
             
                requirements:
         | 
| 20 | 
            -
                - -  | 
| 17 | 
            +
                - - "~>"
         | 
| 21 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            -
                    version:  | 
| 19 | 
            +
                    version: 1.0.0
         | 
| 20 | 
            +
              type: :runtime
         | 
| 23 21 | 
             
              prerelease: false
         | 
| 24 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            -
                none: false
         | 
| 26 23 | 
             
                requirements:
         | 
| 27 | 
            -
                - -  | 
| 24 | 
            +
                - - "~>"
         | 
| 28 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            -
                    version:  | 
| 26 | 
            +
                    version: 1.0.0
         | 
| 30 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 31 | 
            -
              name:  | 
| 32 | 
            -
              type: :runtime
         | 
| 28 | 
            +
              name: mongoid
         | 
| 33 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 34 | 
            -
                none: false
         | 
| 35 30 | 
             
                requirements:
         | 
| 36 | 
            -
                - -  | 
| 31 | 
            +
                - - ">="
         | 
| 37 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 38 | 
            -
                    version:  | 
| 33 | 
            +
                    version: 5.0.0
         | 
| 34 | 
            +
              type: :runtime
         | 
| 39 35 | 
             
              prerelease: false
         | 
| 40 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            -
                none: false
         | 
| 42 37 | 
             
                requirements:
         | 
| 43 | 
            -
                - -  | 
| 38 | 
            +
                - - ">="
         | 
| 44 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 45 | 
            -
                    version:  | 
| 40 | 
            +
                    version: 5.0.0
         | 
| 46 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 47 42 | 
             
              name: database_cleaner
         | 
| 48 | 
            -
              type: :development
         | 
| 49 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 50 | 
            -
                none: false
         | 
| 51 44 | 
             
                requirements:
         | 
| 52 | 
            -
                - -  | 
| 45 | 
            +
                - - ">="
         | 
| 53 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 47 | 
             
                    version: 0.8.0
         | 
| 48 | 
            +
              type: :development
         | 
| 55 49 | 
             
              prerelease: false
         | 
| 56 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            -
                none: false
         | 
| 58 51 | 
             
                requirements:
         | 
| 59 | 
            -
                - -  | 
| 52 | 
            +
                - - ">="
         | 
| 60 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 54 | 
             
                    version: 0.8.0
         | 
| 62 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 63 | 
            -
              name:  | 
| 56 | 
            +
              name: mongoid-compatibility
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 64 62 | 
             
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: rake
         | 
| 65 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 66 | 
            -
                none: false
         | 
| 67 72 | 
             
                requirements:
         | 
| 68 | 
            -
                - -  | 
| 73 | 
            +
                - - ">="
         | 
| 69 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 70 | 
            -
                    version: 0 | 
| 75 | 
            +
                    version: '11.0'
         | 
| 76 | 
            +
              type: :development
         | 
| 71 77 | 
             
              prerelease: false
         | 
| 72 78 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 73 | 
            -
                none: false
         | 
| 74 79 | 
             
                requirements:
         | 
| 75 | 
            -
                - -  | 
| 80 | 
            +
                - - ">="
         | 
| 76 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 77 | 
            -
                    version: 0 | 
| 82 | 
            +
                    version: '11.0'
         | 
| 78 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 79 84 | 
             
              name: rspec
         | 
| 80 | 
            -
              type: :development
         | 
| 81 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 82 | 
            -
                none: false
         | 
| 83 86 | 
             
                requirements:
         | 
| 84 | 
            -
                - - ~>
         | 
| 87 | 
            +
                - - "~>"
         | 
| 85 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 86 89 | 
             
                    version: '2.4'
         | 
| 90 | 
            +
              type: :development
         | 
| 87 91 | 
             
              prerelease: false
         | 
| 88 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 89 | 
            -
                none: false
         | 
| 90 93 | 
             
                requirements:
         | 
| 91 | 
            -
                - - ~>
         | 
| 94 | 
            +
                - - "~>"
         | 
| 92 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 93 96 | 
             
                    version: '2.4'
         | 
| 94 97 | 
             
            description: Simple full text search implementation.
         | 
| @@ -98,15 +101,15 @@ executables: [] | |
| 98 101 | 
             
            extensions: []
         | 
| 99 102 | 
             
            extra_rdoc_files: []
         | 
| 100 103 | 
             
            files:
         | 
| 104 | 
            +
            - LICENSE
         | 
| 105 | 
            +
            - README.md
         | 
| 106 | 
            +
            - Rakefile
         | 
| 107 | 
            +
            - lib/mongoid_search.rb
         | 
| 101 108 | 
             
            - lib/mongoid_search/log.rb
         | 
| 102 109 | 
             
            - lib/mongoid_search/mongoid_search.rb
         | 
| 103 110 | 
             
            - lib/mongoid_search/railtie.rb
         | 
| 111 | 
            +
            - lib/mongoid_search/tasks/mongoid_search.rake
         | 
| 104 112 | 
             
            - lib/mongoid_search/util.rb
         | 
| 105 | 
            -
            - lib/mongoid_search.rb
         | 
| 106 | 
            -
            - LICENSE
         | 
| 107 | 
            -
            - README.md
         | 
| 108 | 
            -
            - Rakefile
         | 
| 109 | 
            -
            - VERSION
         | 
| 110 113 | 
             
            - spec/config/ignorelist.yml
         | 
| 111 114 | 
             
            - spec/models/category.rb
         | 
| 112 115 | 
             
            - spec/models/product.rb
         | 
| @@ -116,37 +119,36 @@ files: | |
| 116 119 | 
             
            - spec/mongoid_search_spec.rb
         | 
| 117 120 | 
             
            - spec/spec_helper.rb
         | 
| 118 121 | 
             
            - spec/util_spec.rb
         | 
| 119 | 
            -
            homepage:  | 
| 120 | 
            -
            licenses: | 
| 122 | 
            +
            homepage: https://github.com/mongoid/mongoid_search
         | 
| 123 | 
            +
            licenses:
         | 
| 124 | 
            +
            - MIT
         | 
| 125 | 
            +
            metadata: {}
         | 
| 121 126 | 
             
            post_install_message: 
         | 
| 122 127 | 
             
            rdoc_options: []
         | 
| 123 128 | 
             
            require_paths:
         | 
| 124 129 | 
             
            - lib
         | 
| 125 130 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 126 | 
            -
              none: false
         | 
| 127 131 | 
             
              requirements:
         | 
| 128 | 
            -
              - -  | 
| 132 | 
            +
              - - ">="
         | 
| 129 133 | 
             
                - !ruby/object:Gem::Version
         | 
| 130 134 | 
             
                  version: '0'
         | 
| 131 135 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 132 | 
            -
              none: false
         | 
| 133 136 | 
             
              requirements:
         | 
| 134 | 
            -
              - -  | 
| 137 | 
            +
              - - ">="
         | 
| 135 138 | 
             
                - !ruby/object:Gem::Version
         | 
| 136 139 | 
             
                  version: 1.3.6
         | 
| 137 140 | 
             
            requirements: []
         | 
| 138 | 
            -
             | 
| 139 | 
            -
            rubygems_version: 1.8.23
         | 
| 141 | 
            +
            rubygems_version: 3.0.3
         | 
| 140 142 | 
             
            signing_key: 
         | 
| 141 | 
            -
            specification_version:  | 
| 143 | 
            +
            specification_version: 4
         | 
| 142 144 | 
             
            summary: Search implementation for Mongoid ORM
         | 
| 143 145 | 
             
            test_files:
         | 
| 146 | 
            +
            - spec/spec_helper.rb
         | 
| 144 147 | 
             
            - spec/config/ignorelist.yml
         | 
| 148 | 
            +
            - spec/models/variant.rb
         | 
| 145 149 | 
             
            - spec/models/category.rb
         | 
| 150 | 
            +
            - spec/models/tag.rb
         | 
| 146 151 | 
             
            - spec/models/product.rb
         | 
| 147 152 | 
             
            - spec/models/subproduct.rb
         | 
| 148 | 
            -
            - spec/models/tag.rb
         | 
| 149 | 
            -
            - spec/models/variant.rb
         | 
| 150 | 
            -
            - spec/mongoid_search_spec.rb
         | 
| 151 | 
            -
            - spec/spec_helper.rb
         | 
| 152 153 | 
             
            - spec/util_spec.rb
         | 
| 154 | 
            +
            - spec/mongoid_search_spec.rb
         | 
    
        data/VERSION
    DELETED
    
    | @@ -1 +0,0 @@ | |
| 1 | 
            -
            0.2.2
         |