Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2026-10-17 02:30:37 UTC using RuboCop version 1.92.0.
# on 2026-10-17 03:01:17 UTC using RuboCop version 1.92.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -58,7 +58,7 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 632
Max: 644

# Offense count: 5
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand Down Expand Up @@ -129,19 +129,6 @@ Style/FormatString:
Style/FormatStringToken:
EnforcedStyle: unannotated

# Offense count: 30
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/HashTransformValues:
Exclude:
- 'lib/mongoid/full_text_search.rb'

# Offense count: 2
Style/MultilineBlockChain:
Exclude:
Expand All @@ -163,14 +150,6 @@ Style/OptionalBooleanParameter:
Exclude:
- 'lib/mongoid/full_text_search.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- 'lib/mongoid/full_text_search.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.8.3 (Next)

* [#59](https://github.com/mongoid/mongoid_fulltext/pull/59): Document and cover class-level indexing timeout options - [@dblock](https://github.com/dblock).
* [#52](https://github.com/mongoid/mongoid_fulltext/pull/52): Fix full-text index creation before any documents exist - [@dblock](https://github.com/dblock).
* [#51](https://github.com/mongoid/mongoid_fulltext/pull/51): Modernize CI through Ruby 4.0, Mongoid 9, and MongoDB 8 with real coverage, RuboCop 1.92, and fork-safe Danger workflows - [@dblock](https://github.com/dblock).
* [#45](https://github.com/mongoid/mongoid_fulltext/pull/45): Allow for class level ngram updates to not timeout - [@roykolak](https://github.com/roykolak).
* Your contribution here.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ Indexing Options

`Artwork.update_ngram_index(timeout: false)` rebuilds the index for all records without a cursor timeout; the `timeout` option belongs to the class method, not the per-document `artwork.update_ngram_index` method.

`Artwork.create_indexes` can create the full-text collections and their indexes before any artworks have been saved.

Additional indexing/query options can be used as parameters to `fulltext_search_in`.

* `alphabet`: letters to index, default is `abcdefghijklmnopqrstuvwxyz0123456789 `.
Expand Down
15 changes: 8 additions & 7 deletions lib/mongoid/full_text_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def fulltext_search_ensure_indexes(index_name, config)
db = collection.database
coll = db[index_name]

# Creating an index also creates the collection before older drivers list its indexes.
Mongoid.logger.info "Ensuring document_id index on #{coll.name}" if Mongoid.logger
if Mongoid::Compatibility::Version.mongoid5_or_newer?
coll.indexes.create_one('document_id' => 1)
else
coll.indexes.create('document_id' => 1)
end

# The order of filters matters when the same index is used from two or more collections.
filter_indexes = (config[:filters] || []).map do |key, _value|
["filter_values.#{key}", 1]
Expand Down Expand Up @@ -116,13 +124,6 @@ def fulltext_search_ensure_indexes(index_name, config)
else
coll.indexes.create(Hash[index_definition], name: 'fts_index')
end

Mongoid.logger.info "Ensuring document_id index on #{coll.name}" if Mongoid.logger
if Mongoid::Compatibility::Version.mongoid5_or_newer?
coll.indexes.create_one('document_id' => 1) # to make removes fast
else
coll.indexes.create('document_id' => 1) # to make removes fast
end
end

def fulltext_search(query_string, options = {})
Expand Down
14 changes: 14 additions & 0 deletions spec/mongoid/full_text_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,20 @@
end
end

context 'creating indexes before any documents exist' do
it 'creates both indexes in a missing collection without inserting documents' do
coll = BasicArtwork.collection.database[BasicArtwork.mongoid_fulltext_config.keys.first]
BasicArtwork.create_indexes
coll.drop
BasicArtwork.create_indexes

indexes = []
coll.indexes.each { |index| indexes << index['name'] }
expect(indexes).to include('fts_index', 'document_id_1') if Mongoid::Compatibility::Version.mongoid5_or_newer?
expect(coll.find.count).to eq(0)
end
end

# For =~ operator documentation
# https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/match_array.rb#L53

Expand Down
Loading