mongoid_fulltext 0.8.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop_todo.yml +62 -27
- data/.travis.yml +6 -3
- data/CHANGELOG.md +5 -0
- data/Dangerfile +1 -1
- data/Gemfile +5 -3
- data/README.md +1 -2
- data/RELEASING.md +43 -0
- data/Rakefile +1 -1
- data/lib/mongoid/full_text_search.rb +30 -31
- data/lib/mongoid/full_text_search/indexable.rb +1 -1
- data/lib/mongoid/full_text_search/indexes.rb +1 -1
- data/lib/mongoid/full_text_search/version.rb +1 -1
- data/mongoid_fulltext.gemspec +4 -3
- data/spec/models/filtered_artist.rb +1 -2
- data/spec/models/filtered_artwork.rb +1 -2
- data/spec/models/filtered_other.rb +1 -2
- data/spec/models/partitioned_artist.rb +1 -1
- data/spec/models/russian_artwork.rb +2 -2
- data/spec/mongoid/full_text_search_spec.rb +11 -7
- data/spec/spec_helper.rb +10 -7
- data/spec/support/mongoid.rb +6 -4
- metadata +26 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 177a2fc11491445aa0dfeaba3932e40fd2a2c37e89914dc7a1849ecfa6904e8c
|
4
|
+
data.tar.gz: 1ad51ce427c54fea7b7feed000bd2443b66d33d901c3713d72707e36620c32da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c48d9412a4141c93888b67cb8c3bac7bae22c35a19cf20612be770c152af77502f408316b21a98802dc7417235067bf6d3114501d22e7be3ec2fc9870cd38bde
|
7
|
+
data.tar.gz: 1337bddf536cbda56b5d638e5e4f3c1458dc145043d45d1a810ec386ad0d6c13d5f27760503a2cd0da3bb596af572f02ae4198d00139b58a52c9c17ac11b1d80
|
data/.rubocop_todo.yml
CHANGED
@@ -1,22 +1,31 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2018-05-08 14:54:25 +0200 using RuboCop version 0.55.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
+
# Offense count: 6
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
|
12
|
+
Bundler/DuplicatedGem:
|
13
|
+
Exclude:
|
14
|
+
- 'Gemfile'
|
15
|
+
|
9
16
|
# Offense count: 1
|
10
|
-
#
|
11
|
-
|
17
|
+
# Cop supports --auto-correct.
|
18
|
+
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
|
19
|
+
# SupportedStylesAlignWith: keyword, variable, start_of_line
|
20
|
+
Layout/EndAlignment:
|
12
21
|
Exclude:
|
13
22
|
- 'lib/mongoid/full_text_search.rb'
|
14
23
|
|
15
24
|
# Offense count: 1
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
25
|
+
# Configuration parameters: AllowSafeAssignment.
|
26
|
+
Lint/AssignmentInCondition:
|
27
|
+
Exclude:
|
28
|
+
- 'lib/mongoid/full_text_search.rb'
|
20
29
|
|
21
30
|
# Offense count: 2
|
22
31
|
Lint/HandleExceptions:
|
@@ -36,17 +45,17 @@ Lint/UselessAssignment:
|
|
36
45
|
|
37
46
|
# Offense count: 5
|
38
47
|
Metrics/AbcSize:
|
39
|
-
Max:
|
48
|
+
Max: 104
|
49
|
+
|
50
|
+
# Offense count: 7
|
51
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
52
|
+
Metrics/BlockLength:
|
53
|
+
Max: 622
|
40
54
|
|
41
55
|
# Offense count: 4
|
42
56
|
Metrics/CyclomaticComplexity:
|
43
57
|
Max: 22
|
44
58
|
|
45
|
-
# Offense count: 262
|
46
|
-
# Configuration parameters: AllowURI, URISchemes.
|
47
|
-
Metrics/LineLength:
|
48
|
-
Max: 174
|
49
|
-
|
50
59
|
# Offense count: 5
|
51
60
|
# Configuration parameters: CountComments.
|
52
61
|
Metrics/MethodLength:
|
@@ -55,47 +64,73 @@ Metrics/MethodLength:
|
|
55
64
|
# Offense count: 1
|
56
65
|
# Configuration parameters: CountComments.
|
57
66
|
Metrics/ModuleLength:
|
58
|
-
Max:
|
67
|
+
Max: 223
|
59
68
|
|
60
69
|
# Offense count: 4
|
61
70
|
Metrics/PerceivedComplexity:
|
62
71
|
Max: 25
|
63
72
|
|
64
73
|
# Offense count: 1
|
74
|
+
Naming/ConstantName:
|
75
|
+
Exclude:
|
76
|
+
- 'spec/models/russian_artwork.rb'
|
77
|
+
|
78
|
+
# Offense count: 1
|
79
|
+
# Configuration parameters: AllowedChars.
|
65
80
|
Style/AsciiComments:
|
66
81
|
Exclude:
|
67
82
|
- 'spec/mongoid/full_text_search_spec.rb'
|
68
83
|
|
69
84
|
# Offense count: 1
|
70
|
-
#
|
85
|
+
# Cop supports --auto-correct.
|
86
|
+
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
87
|
+
# SupportedStyles: nested, compact
|
71
88
|
Style/ClassAndModuleChildren:
|
72
89
|
Exclude:
|
73
90
|
- 'lib/mongoid/full_text_search.rb'
|
74
91
|
|
75
|
-
# Offense count:
|
76
|
-
Style/ConstantName:
|
77
|
-
Exclude:
|
78
|
-
- 'spec/models/russian_artwork.rb'
|
79
|
-
|
80
|
-
# Offense count: 22
|
92
|
+
# Offense count: 4
|
81
93
|
Style/Documentation:
|
82
|
-
|
94
|
+
Exclude:
|
95
|
+
- 'spec/**/*'
|
96
|
+
- 'test/**/*'
|
97
|
+
- 'lib/mongoid/full_text_search.rb'
|
98
|
+
- 'lib/mongoid/full_text_search/indexable.rb'
|
99
|
+
- 'lib/mongoid/full_text_search/indexes.rb'
|
83
100
|
|
84
101
|
# Offense count: 3
|
85
|
-
#
|
102
|
+
# Cop supports --auto-correct.
|
103
|
+
# Configuration parameters: EnforcedStyle.
|
104
|
+
# SupportedStyles: format, sprintf, percent
|
86
105
|
Style/FormatString:
|
87
106
|
Exclude:
|
88
107
|
- 'lib/mongoid/full_text_search.rb'
|
89
108
|
- 'spec/models/external_artwork_no_fields_supplied.rb'
|
90
109
|
|
110
|
+
# Offense count: 6
|
111
|
+
# Configuration parameters: EnforcedStyle.
|
112
|
+
# SupportedStyles: annotated, template, unannotated
|
113
|
+
Style/FormatStringToken:
|
114
|
+
Exclude:
|
115
|
+
- 'lib/mongoid/full_text_search.rb'
|
116
|
+
- 'spec/models/external_artwork_no_fields_supplied.rb'
|
117
|
+
|
91
118
|
# Offense count: 2
|
92
119
|
Style/MultilineBlockChain:
|
93
120
|
Exclude:
|
94
121
|
- 'lib/mongoid/full_text_search.rb'
|
95
122
|
|
96
|
-
# Offense count:
|
97
|
-
#
|
98
|
-
|
123
|
+
# Offense count: 2
|
124
|
+
# Cop supports --auto-correct.
|
125
|
+
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
126
|
+
# SupportedStyles: predicate, comparison
|
127
|
+
Style/NumericPredicate:
|
99
128
|
Exclude:
|
129
|
+
- 'spec/**/*'
|
100
130
|
- 'lib/mongoid/full_text_search.rb'
|
101
|
-
|
131
|
+
|
132
|
+
# Offense count: 262
|
133
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
134
|
+
# URISchemes: http, https
|
135
|
+
Metrics/LineLength:
|
136
|
+
Max: 174
|
data/.travis.yml
CHANGED
@@ -2,11 +2,14 @@ sudo: false
|
|
2
2
|
|
3
3
|
matrix:
|
4
4
|
include:
|
5
|
-
- rvm: 2.
|
5
|
+
- rvm: 2.5.0
|
6
6
|
env:
|
7
|
-
- MONGOID_VERSION=
|
7
|
+
- MONGOID_VERSION=7.0
|
8
8
|
before_script:
|
9
9
|
- bundle exec danger
|
10
|
+
- rvm: 2.3.1
|
11
|
+
env:
|
12
|
+
- MONGOID_VERSION=6.0
|
10
13
|
- rvm: 2.3.1
|
11
14
|
env:
|
12
15
|
- MONGOID_VERSION=5.0
|
@@ -25,6 +28,6 @@ services: mongodb
|
|
25
28
|
addons:
|
26
29
|
apt:
|
27
30
|
sources:
|
28
|
-
- mongodb-3.
|
31
|
+
- mongodb-3.4-precise
|
29
32
|
packages:
|
30
33
|
- mongodb-org-server
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.8.1 (Next)
|
2
|
+
|
3
|
+
* [#35](https://github.com/mongoid/mongoid_fulltext/pull/35): Mongoid 7 compatibility - [@tomasc](https://github.com/tomasc).
|
4
|
+
* Your contribution here.
|
5
|
+
|
1
6
|
### 0.8.0 (1/19/2017)
|
2
7
|
|
3
8
|
* [#28](https://github.com/mongoid/mongoid_fulltext/pull/28): Moved to the mongoid organization - [@dblock](https://github.com/dblock).
|
data/Dangerfile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
danger.import_dangerfile(gem:
|
1
|
+
danger.import_dangerfile(gem: 'mongoid-danger')
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
case version = ENV['MONGOID_VERSION'] || '
|
3
|
+
case version = ENV['MONGOID_VERSION'] || '7'
|
4
|
+
when /7/
|
5
|
+
gem 'mongoid', '~> 7.0'
|
4
6
|
when /6/
|
5
7
|
gem 'mongoid', '~> 6.0'
|
6
8
|
when /5/
|
@@ -22,7 +24,7 @@ group :test do
|
|
22
24
|
end
|
23
25
|
|
24
26
|
group :development do
|
25
|
-
gem 'rake', '< 11'
|
26
|
-
gem 'rubocop', '0.34.1'
|
27
27
|
gem 'mongoid-danger', '~> 0.1.1'
|
28
|
+
gem 'rake', '< 11'
|
29
|
+
gem 'rubocop', '~> 0.55'
|
28
30
|
end
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ lets you do a fuzzy string search across relatively short strings, which makes i
|
|
13
13
|
Install
|
14
14
|
-------
|
15
15
|
|
16
|
-
Version 0.6.1 or newer of this gem requires Ruby 1.9.3 or newer and works with Mongoid 3, 4, 5 and 6.
|
16
|
+
Version 0.6.1 or newer of this gem requires Ruby 1.9.3 or newer and works with Mongoid 3, 4, 5 and 6, 7.
|
17
17
|
Use version 0.5.x for Mongoid 2.4.x and Ruby 1.8.7, 1.9.2 or 1.9.3.
|
18
18
|
For Ruby 1.8.7 and/or Mongoid 2.x use [mongoid_fulltext 0.5.x](https://github.com/mongoid/mongoid_fulltext/tree/0.5-stable).
|
19
19
|
|
@@ -397,4 +397,3 @@ Copyright and License
|
|
397
397
|
MIT License, see [LICENSE](LICENSE) for details.
|
398
398
|
|
399
399
|
(c) 2011-2017 [Artsy Inc.](http://artsy.github.io)
|
400
|
-
|
data/RELEASING.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Releasing `mongoid_fulltext`
|
2
|
+
## Guidelines
|
3
|
+
Generally, `mongoid_fulltext` should be released with enthusiasm but care. Release bug fixes as added, features as desired, and breaking API changes as absolutely necessary.
|
4
|
+
|
5
|
+
## This is how we do it.
|
6
|
+
1. Run the test suite in your local environment first, and ensure that everything's passing.
|
7
|
+
|
8
|
+
```bash
|
9
|
+
bundle install
|
10
|
+
rake
|
11
|
+
```
|
12
|
+
|
13
|
+
2. Run the test suite on [Travis](https://travis-ci.org) to be certain that your changes work in a variety of environments. Only merge and release when all tests are passing.
|
14
|
+
|
15
|
+
3. Bump the version in [`lib/mongoid/full_text_search/version.rb`](lib/mongoid/full_text_search/version.rb).
|
16
|
+
|
17
|
+
* If the release fixes bugs or adds features with negligible impact, increment the third number (e.g., `0.3.2` → `0.3.3`).
|
18
|
+
* If the release adds significant new features, increment the second number and zero out the third (e.g., `0.3.2` → `0.4.0`).
|
19
|
+
* If the release adds breaking API changes, increment the first number and zero out the second and third (e.g., `0.3.2` → `1.0.0`).
|
20
|
+
|
21
|
+
You've gotta know it---it's semantic!
|
22
|
+
|
23
|
+
4. Add a header for the new version to [`CHANGELOG.md`](CHANGELOG.md) and list all the changes your release will include underneath it, crediting contributors as appropriate.
|
24
|
+
|
25
|
+
6. Update the [`README`](README.md) to document any new features. Remove any warnings indicating that users are reading the documentation for an unreleased version.
|
26
|
+
|
27
|
+
7. Commit your changes...
|
28
|
+
|
29
|
+
```bash
|
30
|
+
git add README.md CHANGELOG.md lib/mongoid/full_text_search/version.rb
|
31
|
+
git commit -m "Preparing for release, 0.4.0."
|
32
|
+
git push origin master
|
33
|
+
```
|
34
|
+
|
35
|
+
8. ...and do the thing!
|
36
|
+
|
37
|
+
```bash
|
38
|
+
rake release
|
39
|
+
#=> mongoid_fulltext 0.4.0 built to pkg/mongoid_fulltext-0.4.0.gem
|
40
|
+
#=> Tagged 0.4.0.
|
41
|
+
#=> Pushed git commits and tags.
|
42
|
+
#=> Pushed mongoid_fulltext 0.4.0 to rubygems.org.
|
43
|
+
```
|
data/Rakefile
CHANGED
@@ -24,11 +24,11 @@ module Mongoid::FullTextSearch
|
|
24
24
|
def fulltext_search_in(*args)
|
25
25
|
self.mongoid_fulltext_config = {} if mongoid_fulltext_config.nil?
|
26
26
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
27
|
-
if options.key?(:index_name)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
index_name = if options.key?(:index_name)
|
28
|
+
options[:index_name]
|
29
|
+
else
|
30
|
+
'mongoid_fulltext.index_%s_%s' % [name.downcase, mongoid_fulltext_config.count]
|
31
|
+
end
|
32
32
|
|
33
33
|
config = {
|
34
34
|
alphabet: 'abcdefghijklmnopqrstuvwxyz0123456789 ',
|
@@ -41,7 +41,7 @@ module Mongoid::FullTextSearch
|
|
41
41
|
max_candidate_set_size: 1000,
|
42
42
|
remove_accents: true,
|
43
43
|
reindex_immediately: true,
|
44
|
-
stop_words: Hash[%w
|
44
|
+
stop_words: Hash[%w[i a s t me my we he it am is be do an if
|
45
45
|
or as of at by to up in on no so our you him
|
46
46
|
his she her its who are was has had did the and
|
47
47
|
but for out off why how all any few nor not own
|
@@ -52,7 +52,7 @@ module Mongoid::FullTextSearch
|
|
52
52
|
being doing until while about after above below under
|
53
53
|
again there where other myself itself theirs having during
|
54
54
|
before should himself herself because against between through
|
55
|
-
further yourself ourselves yourselves themselves
|
55
|
+
further yourself ourselves yourselves themselves].map { |x| [x, true] }]
|
56
56
|
}
|
57
57
|
|
58
58
|
config.update(options)
|
@@ -95,7 +95,7 @@ module Mongoid::FullTextSearch
|
|
95
95
|
all_filter_keys |= keys.find_all { |key| key.starts_with?('filter_values.') }
|
96
96
|
next unless keys & correct_keys != correct_keys
|
97
97
|
Mongoid.logger.info "Dropping #{idef['name']} [#{keys & correct_keys} <=> #{correct_keys}]" if Mongoid.logger
|
98
|
-
if Mongoid::Compatibility::Version.
|
98
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
99
99
|
coll.indexes.drop_one(idef['key'])
|
100
100
|
else
|
101
101
|
coll.indexes.drop(idef['key'])
|
@@ -108,14 +108,14 @@ module Mongoid::FullTextSearch
|
|
108
108
|
end
|
109
109
|
|
110
110
|
Mongoid.logger.info "Ensuring fts_index on #{coll.name}: #{index_definition}" if Mongoid.logger
|
111
|
-
if Mongoid::Compatibility::Version.
|
111
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
112
112
|
coll.indexes.create_one(Hash[index_definition], name: 'fts_index')
|
113
113
|
else
|
114
114
|
coll.indexes.create(Hash[index_definition], name: 'fts_index')
|
115
115
|
end
|
116
116
|
|
117
117
|
Mongoid.logger.info "Ensuring document_id index on #{coll.name}" if Mongoid.logger
|
118
|
-
if Mongoid::Compatibility::Version.
|
118
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
119
119
|
coll.indexes.create_one('document_id' => 1) # to make removes fast
|
120
120
|
else
|
121
121
|
coll.indexes.create('document_id' => 1) # to make removes fast
|
@@ -127,7 +127,7 @@ module Mongoid::FullTextSearch
|
|
127
127
|
return_scores = options.key?(:return_scores) ? options.delete(:return_scores) : false
|
128
128
|
if mongoid_fulltext_config.count > 1 && !options.key?(:index)
|
129
129
|
error_message = '%s is indexed by multiple full-text indexes. You must specify one by passing an :index_name parameter'
|
130
|
-
|
130
|
+
raise UnspecifiedIndexError, error_message % name, caller
|
131
131
|
end
|
132
132
|
index_name = options.key?(:index) ? options.delete(:index) : mongoid_fulltext_config.keys.first
|
133
133
|
|
@@ -143,7 +143,7 @@ module Mongoid::FullTextSearch
|
|
143
143
|
coll = collection.database[index_name]
|
144
144
|
cursors = ngrams.map do |ngram|
|
145
145
|
query = { 'ngram' => ngram[0] }
|
146
|
-
query.update(map_query_filters
|
146
|
+
query.update(map_query_filters(options))
|
147
147
|
count = coll.find(query).count
|
148
148
|
{ ngram: ngram, count: count, query: query }
|
149
149
|
end.sort! { |record1, record2| record1[:count] <=> record2[:count] }
|
@@ -182,8 +182,7 @@ module Mongoid::FullTextSearch
|
|
182
182
|
scores = candidates.map do |candidate_id, data|
|
183
183
|
{ id: candidate_id,
|
184
184
|
clazz: data[:clazz],
|
185
|
-
score: data[:score] + candidates_list.map { |others| (others.delete(candidate_id) || { score: 0 })[:score] }.sum
|
186
|
-
}
|
185
|
+
score: data[:score] + candidates_list.map { |others| (others.delete(candidate_id) || { score: 0 })[:score] }.sum }
|
187
186
|
end
|
188
187
|
all_scores.concat(scores)
|
189
188
|
end
|
@@ -220,11 +219,11 @@ module Mongoid::FullTextSearch
|
|
220
219
|
# Figure out how many ngrams to extract from the string. If we can't afford to extract all ngrams,
|
221
220
|
# step over the string in evenly spaced strides to extract ngrams. For example, to extract 3 3-letter
|
222
221
|
# ngrams from 'abcdefghijk', we'd want to extract 'abc', 'efg', and 'ijk'.
|
223
|
-
if bound_number_returned
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
222
|
+
step_size = if bound_number_returned
|
223
|
+
[((filtered_str.length - config[:ngram_width]).to_f / config[:max_ngrams_to_search]).ceil, 1].max
|
224
|
+
else
|
225
|
+
1
|
226
|
+
end
|
228
227
|
|
229
228
|
# Create an array of records of the form {:ngram => x, :score => y} for all ngrams that occur in the
|
230
229
|
# input string using the step size that we just computed. Let score(x,y) be the score of string x
|
@@ -233,12 +232,12 @@ module Mongoid::FullTextSearch
|
|
233
232
|
# property that score(x,y) > score(x,z) for any string z containing y and score(x,y) > score(x,z)
|
234
233
|
# for any string z contained in y.
|
235
234
|
ngram_array = (0..filtered_str.length - config[:ngram_width]).step(step_size).map do |i|
|
236
|
-
if i == 0 || (config[:apply_prefix_scoring_to_all_words] && \
|
235
|
+
score = if i == 0 || (config[:apply_prefix_scoring_to_all_words] && \
|
237
236
|
config[:word_separators].key?(filtered_str[i - 1].chr))
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
237
|
+
Math.sqrt(1 + 1.0 / filtered_str.length)
|
238
|
+
else
|
239
|
+
Math.sqrt(2.0 / filtered_str.length)
|
240
|
+
end
|
242
241
|
{ ngram: filtered_str[i..i + config[:ngram_width] - 1], score: score }
|
243
242
|
end
|
244
243
|
|
@@ -282,7 +281,7 @@ module Mongoid::FullTextSearch
|
|
282
281
|
def remove_from_ngram_index
|
283
282
|
mongoid_fulltext_config.each_pair do |index_name, _fulltext_config|
|
284
283
|
coll = collection.database[index_name]
|
285
|
-
if Mongoid::Compatibility::Version.
|
284
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
286
285
|
coll.find('class' => name).delete_many
|
287
286
|
else
|
288
287
|
coll.find('class' => name).remove_all
|
@@ -299,12 +298,12 @@ module Mongoid::FullTextSearch
|
|
299
298
|
# Take a list of filters to be mapped so they can update the query
|
300
299
|
# used upon the fulltext search of the ngrams
|
301
300
|
def map_query_filters(filters)
|
302
|
-
Hash[filters.map do|key, value|
|
301
|
+
Hash[filters.map do |key, value|
|
303
302
|
case value
|
304
303
|
when Hash then
|
305
304
|
if value.key? :any then format_query_filter('$in', key, value[:any])
|
306
305
|
elsif value.key? :all then format_query_filter('$all', key, value[:all])
|
307
|
-
else
|
306
|
+
else raise UnknownFilterQueryOperator, value.keys.join(','), caller end
|
308
307
|
else format_query_filter('$all', key, value)
|
309
308
|
end
|
310
309
|
end]
|
@@ -328,7 +327,7 @@ module Mongoid::FullTextSearch
|
|
328
327
|
|
329
328
|
# remove existing ngrams from external index
|
330
329
|
coll = collection.database[index_name.to_sym]
|
331
|
-
if Mongoid::Compatibility::Version.
|
330
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
332
331
|
coll.find('document_id' => _id).delete_many
|
333
332
|
else
|
334
333
|
coll.find('document_id' => _id).remove_all
|
@@ -343,7 +342,7 @@ module Mongoid::FullTextSearch
|
|
343
342
|
filter_values = Hash[fulltext_config[:filters].map do |key, value|
|
344
343
|
begin
|
345
344
|
[key, value.call(self)]
|
346
|
-
rescue
|
345
|
+
rescue StandardError
|
347
346
|
# Suppress any exceptions caused by filters
|
348
347
|
end
|
349
348
|
end.compact]
|
@@ -352,7 +351,7 @@ module Mongoid::FullTextSearch
|
|
352
351
|
ngrams.each_pair do |ngram, score|
|
353
352
|
index_document = { 'ngram' => ngram, 'document_id' => _id, 'score' => score, 'class' => self.class.name }
|
354
353
|
index_document['filter_values'] = filter_values if fulltext_config.key?(:filters)
|
355
|
-
if Mongoid::Compatibility::Version.
|
354
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
356
355
|
coll.insert_one(index_document)
|
357
356
|
else
|
358
357
|
coll.insert(index_document)
|
@@ -364,7 +363,7 @@ module Mongoid::FullTextSearch
|
|
364
363
|
def remove_from_ngram_index
|
365
364
|
mongoid_fulltext_config.each_pair do |index_name, _fulltext_config|
|
366
365
|
coll = collection.database[index_name]
|
367
|
-
if Mongoid::Compatibility::Version.
|
366
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
368
367
|
coll.find('document_id' => _id).delete_many
|
369
368
|
else
|
370
369
|
coll.find('document_id' => _id).remove_all
|
data/mongoid_fulltext.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
$LOAD_PATH.push File.expand_path('
|
1
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
2
|
require 'mongoid/full_text_search/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
@@ -13,7 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.homepage = 'https://github.com/mongoid/mongoid_fulltext'
|
14
14
|
s.licenses = ['MIT']
|
15
15
|
s.summary = 'Full-text search for the Mongoid ORM, using n-grams extracted from text.'
|
16
|
-
s.add_dependency 'mongoid', '>= 3.0'
|
17
|
-
s.add_dependency 'mongoid-compatibility'
|
16
|
+
s.add_dependency 'mongoid', '>= 3.0', '< 8'
|
17
|
+
s.add_dependency 'mongoid-compatibility', '>= 0.5.1'
|
18
18
|
s.add_dependency 'unicode_utils'
|
19
|
+
s.add_development_dependency 'database_cleaner'
|
19
20
|
end
|
@@ -5,6 +5,5 @@ class FilteredArtist
|
|
5
5
|
fulltext_search_in :full_name, index_name: 'mongoid_fulltext.artworks_and_artists',
|
6
6
|
filters: { is_foobar: ->(x) { x.full_name == 'foobar' },
|
7
7
|
is_artist: ->(_x) { true },
|
8
|
-
is_artwork: ->(_x) { false }
|
9
|
-
}
|
8
|
+
is_artwork: ->(_x) { false } }
|
10
9
|
end
|
@@ -8,7 +8,7 @@ class PartitionedArtist
|
|
8
8
|
fulltext_search_in :full_name,
|
9
9
|
index_name: 'mongoid_fulltext.partitioned_artists',
|
10
10
|
filters: {
|
11
|
-
has_exhibitions: ->(x) { x.exhibitions.
|
11
|
+
has_exhibitions: ->(x) { !x.exhibitions.empty? },
|
12
12
|
exhibitions: ->(x) { [x.exhibitions].flatten }
|
13
13
|
}
|
14
14
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
class RussianArtwork
|
3
3
|
include Mongoid::Document
|
4
4
|
include Mongoid::FullTextSearch
|
5
5
|
|
6
|
-
Alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789абвгдежзиклмнопрстуфхцчшщъыьэюя'
|
6
|
+
Alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789абвгдежзиклмнопрстуфхцчшщъыьэюя'.freeze
|
7
7
|
|
8
8
|
field :title
|
9
9
|
fulltext_search_in :title, alphabet: Alphabet
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Mongoid::FullTextSearch do
|
@@ -355,6 +355,8 @@ describe Mongoid::FullTextSearch do
|
|
355
355
|
# fields as well as the union of all the filter fields to allow for efficient lookups.
|
356
356
|
|
357
357
|
it 'creates a proper index for searching efficiently' do
|
358
|
+
# see https://github.com/mongoid/mongoid_fulltext/pull/39
|
359
|
+
pending unless Mongoid::Compatibility::Version.mongoid5_or_newer?
|
358
360
|
[FilteredArtwork, FilteredArtist, FilteredOther].each(&:create_indexes)
|
359
361
|
index_collection = FilteredArtwork.collection.database['mongoid_fulltext.artworks_and_artists']
|
360
362
|
ngram_indexes = []
|
@@ -421,7 +423,7 @@ describe Mongoid::FullTextSearch do
|
|
421
423
|
let!(:somao) { ExternalArtwork.create(title: 'Somao by Randy Morehall') }
|
422
424
|
|
423
425
|
it "returns basic matches that don't match a whole word and aren't prefixes with score < 1" do
|
424
|
-
%w
|
426
|
+
%w[paox porehall].each do |query|
|
425
427
|
results = ExternalArtist.fulltext_search(query, return_scores: true)
|
426
428
|
expect(results.length).to be > 0
|
427
429
|
expect(results.map { |result| result[-1] }.inject(true) { |accum, item| accum &= (item < 1) }).to be_truthy
|
@@ -429,7 +431,7 @@ describe Mongoid::FullTextSearch do
|
|
429
431
|
end
|
430
432
|
|
431
433
|
it 'returns prefix matches with a score >= 1 but < 2' do
|
432
|
-
%w
|
434
|
+
%w[warho rand].each do |query|
|
433
435
|
results = ExternalArtist.fulltext_search(query, return_scores: true)
|
434
436
|
expect(results.length).to be > 0
|
435
437
|
expect(results.map { |result| result[-1] if result[0].to_s.starts_with?(query) }.compact.inject(true) { |accum, item| accum &= (item >= 1 && item < 2) }).to be_truthy
|
@@ -437,7 +439,7 @@ describe Mongoid::FullTextSearch do
|
|
437
439
|
end
|
438
440
|
|
439
441
|
it 'returns full-word matches with a score >= 2' do
|
440
|
-
%w
|
442
|
+
%w[andy warhol mao].each do |query|
|
441
443
|
results = ExternalArtist.fulltext_search(query, return_scores: true)
|
442
444
|
expect(results.length).to be > 0
|
443
445
|
expect(results.map { |result| result[-1] if result[0].to_s.split(' ').member?(query) }.compact.inject(true) { |accum, item| accum &= (item >= 2) }).to be_truthy
|
@@ -568,7 +570,7 @@ describe Mongoid::FullTextSearch do
|
|
568
570
|
|
569
571
|
context 'and is not a symbol, string, or proc' do
|
570
572
|
before(:each) do
|
571
|
-
conditional_index[:update_if] = %w
|
573
|
+
conditional_index[:update_if] = %w[this isn't a symbol string or proc]
|
572
574
|
end
|
573
575
|
|
574
576
|
it "doesn't update the index for the document" do
|
@@ -597,7 +599,7 @@ describe Mongoid::FullTextSearch do
|
|
597
599
|
context 'incremental' do
|
598
600
|
it 'removes an existing record' do
|
599
601
|
coll = Mongoid.default_session['mongoid_fulltext.index_basicartwork_0']
|
600
|
-
if Mongoid::Compatibility::Version.
|
602
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
601
603
|
coll.find('document_id' => flowers1._id).delete_many
|
602
604
|
else
|
603
605
|
coll.find('document_id' => flowers1._id).remove_all
|
@@ -609,11 +611,13 @@ describe Mongoid::FullTextSearch do
|
|
609
611
|
|
610
612
|
context 'mongoid indexes' do
|
611
613
|
it 'can re-create dropped indexes' do
|
614
|
+
# see https://github.com/mongoid/mongoid_fulltext/pull/39
|
615
|
+
pending unless Mongoid::Compatibility::Version.mongoid5_or_newer?
|
612
616
|
# there're no indexes by default as Mongoid.autocreate_indexes is set to false
|
613
617
|
# but mongo will automatically attempt to index _id in the background
|
614
618
|
expect(Mongoid.default_session['mongoid_fulltext.index_basicartwork_0'].indexes.count).to be <= 1
|
615
619
|
BasicArtwork.create_indexes
|
616
|
-
expected_indexes = %w
|
620
|
+
expected_indexes = %w[_id_ fts_index document_id_1].sort
|
617
621
|
current_indexes = []
|
618
622
|
Mongoid.default_session['mongoid_fulltext.index_basicartwork_0'].indexes.each do |idef|
|
619
623
|
current_indexes << idef['name']
|
data/spec/spec_helper.rb
CHANGED
@@ -3,27 +3,30 @@ require 'bundler/setup'
|
|
3
3
|
require 'rspec'
|
4
4
|
|
5
5
|
require 'mongoid'
|
6
|
+
require 'database_cleaner'
|
6
7
|
|
7
8
|
ENV['MONGOID_ENV'] = 'test'
|
8
9
|
|
9
|
-
require File.expand_path('
|
10
|
+
require File.expand_path('../lib/mongoid_fulltext', __dir__)
|
10
11
|
|
11
12
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
12
13
|
Dir["#{File.dirname(__FILE__)}/models/**/*.rb"].each { |f| require f }
|
13
14
|
|
15
|
+
DatabaseCleaner.orm = :mongoid
|
16
|
+
DatabaseCleaner.strategy = :truncation
|
17
|
+
|
18
|
+
Mongoid.logger.level = Logger::INFO
|
19
|
+
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
20
|
+
|
14
21
|
Mongoid.configure do |config|
|
15
22
|
config.connect_to('mongoid_fulltext_test')
|
16
23
|
end
|
17
24
|
|
18
25
|
RSpec.configure do |c|
|
19
26
|
c.before :each do
|
20
|
-
|
27
|
+
DatabaseCleaner.clean
|
21
28
|
end
|
22
29
|
c.after :all do
|
23
|
-
|
24
|
-
end
|
25
|
-
c.before :all do
|
26
|
-
Mongoid.logger.level = Logger::INFO
|
27
|
-
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
|
30
|
+
DatabaseCleaner.clean
|
28
31
|
end
|
29
32
|
end
|
data/spec/support/mongoid.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
2
|
+
module Mongoid
|
3
|
+
def self.default_session
|
4
|
+
default_client
|
5
|
+
end
|
4
6
|
end
|
5
|
-
end
|
7
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_fulltext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Windsor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '8'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,20 +27,23 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '8'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: mongoid-compatibility
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
39
|
+
version: 0.5.1
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 0.5.1
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: unicode_utils
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +58,20 @@ dependencies:
|
|
52
58
|
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: database_cleaner
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
55
75
|
description:
|
56
76
|
email: aaron.windsor@gmail.com
|
57
77
|
executables: []
|
@@ -69,6 +89,7 @@ files:
|
|
69
89
|
- Gemfile
|
70
90
|
- LICENSE
|
71
91
|
- README.md
|
92
|
+
- RELEASING.md
|
72
93
|
- Rakefile
|
73
94
|
- lib/mongoid/full_text_search.rb
|
74
95
|
- lib/mongoid/full_text_search/indexable.rb
|
@@ -118,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
139
|
version: 1.3.6
|
119
140
|
requirements: []
|
120
141
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.7.6
|
122
143
|
signing_key:
|
123
144
|
specification_version: 4
|
124
145
|
summary: Full-text search for the Mongoid ORM, using n-grams extracted from text.
|