|
18 | 18 | Mongoid::Search.stem_proc = @default_proc
|
19 | 19 | @product = Product.create brand: 'Apple',
|
20 | 20 | name: 'iPhone',
|
| 21 | + unit: 'mobile olé awesome', |
21 | 22 | tags: (@tags = %w[Amazing Awesome Olé].map { |tag| Tag.new(name: tag) }),
|
22 | 23 | category: Category.new(name: 'Mobile', description: 'Reviews'),
|
23 | 24 | subproducts: [Subproduct.new(brand: 'Apple', name: 'Craddle')],
|
|
52 | 53 | Mongoid::Search.ignore_list = nil
|
53 | 54 | @product = Product.create brand: 'Эльбрус',
|
54 | 55 | name: 'Процессор',
|
| 56 | + unit: 'kílográm Olé', |
55 | 57 | tags: %w[Amazing Awesome Olé].map { |tag| Tag.new(name: tag) },
|
56 | 58 | category: Category.new(name: 'процессоры'),
|
57 | 59 | subproducts: []
|
58 | 60 | end
|
59 | 61 |
|
60 | 62 | it 'should leave utf8 characters' do
|
61 | 63 | expect(@product._keywords).to eq %w[amazing awesome ole процессор процессоры эльбрус]
|
| 64 | + expect(@product._unit_keywords).to eq %w[kilogram ole] |
62 | 65 | end
|
63 | 66 |
|
64 | 67 | it "should return results in search when case doesn't match" do
|
65 | 68 | expect(Product.full_text_search('ЭЛЬБРУС').size).to eq 1
|
| 69 | + expect(Product.full_text_search('KILOGRAM', index: :_unit_keywords).size).to eq 1 |
66 | 70 | end
|
67 | 71 | end
|
68 | 72 |
|
|
74 | 78 | end
|
75 | 79 |
|
76 | 80 | it 'should validate keywords' do
|
77 |
| - product = Product.create brand: 'Apple', name: 'iPhone' |
| 81 | + product = Product.create brand: 'Apple', name: 'iPhone', unit: 'box' |
78 | 82 | expect(product._keywords).to eq(%w[apple iphone])
|
| 83 | + expect(product._unit_keywords).to eq(%w[box]) |
79 | 84 | end
|
80 | 85 | end
|
81 | 86 |
|
82 | 87 | it 'should set the _keywords field for array fields also' do
|
83 | 88 | @product.attrs = ['lightweight', 'plastic', :red]
|
| 89 | + @product.measures = ['box', 'bunch', :bag] |
84 | 90 | @product.save!
|
85 | 91 | expect(@product._keywords).to include 'lightweight', 'plastic', 'red'
|
| 92 | + expect(@product._unit_keywords).to include 'box', 'bunch', 'bag' |
86 | 93 | end
|
87 | 94 |
|
88 | 95 | it 'should inherit _keywords field and build upon' do
|
|
91 | 98 | tags: %w[Amazing Awesome Olé].map { |tag| Tag.new(name: tag) },
|
92 | 99 | category: Category.new(name: 'Mobile'),
|
93 | 100 | subproducts: [Subproduct.new(brand: 'Apple', name: 'Craddle')],
|
94 |
| - color: :white |
| 101 | + color: :white, |
| 102 | + size: :big |
95 | 103 | expect(variant._keywords).to include 'white'
|
| 104 | + expect(variant._unit_keywords).to include 'big' |
96 | 105 | expect(Variant.full_text_search(name: 'Apple', color: :white)).to eq [variant]
|
| 106 | + expect(Variant.full_text_search({ size: 'big' }, index: :_unit_keywords)).to eq [variant] |
97 | 107 | end
|
98 | 108 |
|
99 | 109 | it 'should expand the ligature to ease searching' do
|
100 | 110 | # ref: http://en.wikipedia.org/wiki/Typographic_ligature, only for french right now. Rules for other languages are not know
|
101 | 111 | variant1 = Variant.create tags: ['œuvre'].map { |tag| Tag.new(name: tag) }
|
102 | 112 | variant2 = Variant.create tags: ['æquo'].map { |tag| Tag.new(name: tag) }
|
| 113 | + variant3 = Variant.create measures: ['ꜵquo'].map { |measure| measure } |
103 | 114 |
|
104 | 115 | expect(Variant.full_text_search('œuvre')).to eq [variant1]
|
105 | 116 | expect(Variant.full_text_search('oeuvre')).to eq [variant1]
|
106 | 117 | expect(Variant.full_text_search('æquo')).to eq [variant2]
|
107 | 118 | expect(Variant.full_text_search('aequo')).to eq [variant2]
|
| 119 | + expect(Variant.full_text_search('aoquo', index: :_unit_keywords)).to eq [variant3] |
| 120 | + expect(Variant.full_text_search('ꜵquo', index: :_unit_keywords)).to eq [variant3] |
108 | 121 | end
|
109 | 122 |
|
110 |
| - it 'should set the _keywords field with stemmed words if stem is enabled' do |
| 123 | + it 'should set the keywords fields with stemmed words if stem is enabled' do |
111 | 124 | Mongoid::Search.stem_keywords = true
|
112 | 125 | @product.save!
|
113 | 126 | expect(@product._keywords.sort).to eq %w[amaz appl awesom craddl iphon mobil review ol info descript summari].sort
|
| 127 | + expect(@product._unit_keywords.sort).to eq %w[mobil awesom ol].sort |
114 | 128 | end
|
115 | 129 |
|
116 |
| - it 'should set the _keywords field with custom stemmed words if stem is enabled with a custom lambda' do |
| 130 | + it 'should set the keywords fields with custom stemmed words if stem is enabled with a custom lambda' do |
117 | 131 | Mongoid::Search.stem_keywords = true
|
118 | 132 | Mongoid::Search.stem_proc = proc { |word| word.upcase }
|
119 | 133 | @product.save!
|
120 | 134 | expect(@product._keywords.sort).to eq %w[AMAZING APPLE AWESOME CRADDLE DESCRIPTION INFO IPHONE MOBILE OLE REVIEWS SUMMARY]
|
| 135 | + expect(@product._unit_keywords.sort).to eq %w[AWESOME MOBILE OLE] |
121 | 136 | end
|
122 | 137 |
|
123 | 138 | it 'should ignore keywords in an ignore list' do
|
124 | 139 | Mongoid::Search.ignore_list = YAML.safe_load(File.open(File.dirname(__FILE__) + '/config/ignorelist.yml'))['ignorelist']
|
125 | 140 | @product.save!
|
126 | 141 | expect(@product._keywords.sort).to eq %w[apple craddle iphone mobile reviews ole info description summary].sort
|
| 142 | + expect(@product._unit_keywords.sort).to eq %w[mobile ole].sort |
127 | 143 | end
|
128 | 144 |
|
129 | 145 | it 'should incorporate numbers as keywords' do
|
|
205 | 221 | end
|
206 | 222 |
|
207 | 223 | it 'should have a method to index keywords' do
|
208 |
| - expect(@product.index_keywords!).to eq true |
| 224 | + expect(@product.index_keywords!).to include(true) |
209 | 225 | end
|
210 | 226 |
|
211 | 227 | it 'should have a class method to index all documents keywords' do
|
|
0 commit comments