Cannot call `remove_from_ngram_index` on collection
The readme suggests it's possible to call Artwork.remove_from_ngram_index
But on ruby 2.3.3 and mongoid v6 it raises
NoMethodError: undefined method `mongo_v2?' for Artwork::Class
I believe there is a context issue in the module that defines that method. The mongo_v2 is indeed defined in some of this gem's module but is not called appropriately. I believe some similar method should be provided by the Mongoid Compatibility gem and should be called directly.
Looks like a bug to me.
Also, while I was developing some feature with ngrams and switched branches, I ended up with a mongoid fulltext collection that contained invalid ID references in the ngrams, and this caused the code to crash badly. Calling .update_ngram_index didn't help at all, which is why I tried to clean the ngram index in the first place with remove_from_ngram_index
It would be nice to use a non-crashing method when encountering invalid IDs, otherwise it can be easy to run into errors like
Document(s) not found for class Artwork with id(s) 5adf49e0aba9cf087f496d4e.. summary: When calling Artwork.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): 5adf49e0aba9cf087f496d4e. ... (1 total) and the following ids were not found: 5adf49e0aba9cf087f496d4e..
I'm talking about the find here, it could be replaced by where.first and make sure the code around it doesn't crash ?
@Startouf this PR #35 fixes the issues you are running into.