mongoid_search 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +128 -115
- data/Rakefile +5 -2
- data/VERSION +1 -1
- data/lib/mongoid_search.rb +4 -8
- data/lib/mongoid_search/log.rb +2 -1
- data/lib/mongoid_search/mongoid_search.rb +23 -22
- data/lib/mongoid_search/tasks/mongoid_search.rake +1 -1
- data/lib/mongoid_search/util.rb +17 -18
- data/spec/models/product.rb +10 -6
- data/spec/models/subproduct.rb +1 -1
- data/spec/models/tag.rb +2 -2
- data/spec/models/variant.rb +1 -1
- data/spec/mongoid_search_spec.rb +158 -147
- data/spec/spec_helper.rb +4 -1
- data/spec/util_spec.rb +28 -29
- metadata +25 -11
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
|
-
expect(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
|
-
expect(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
|
-
expect(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
|
-
expect(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
|
-
expect(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
|
-
expect(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
|
-
expect(Mongoid::Search::Util.normalize_keywords("CaFé-express.com delicious;come visit, and 'win' an \"iPad\"")).to eq [
|
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
|
-
expect(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
|
-
expect(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
|
-
expect(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
|
-
expect(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
|
-
expect(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,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauricio Zaffari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fast-stemmer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: mongoid
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,33 +39,33 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: 3.0.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: database_cleaner
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :
|
47
|
+
version: 0.8.0
|
48
|
+
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 0.8.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: mongoid-compatibility
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
61
|
+
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|