Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call remove_from_ngram_index on collection #34

Open
Startouf opened this issue Apr 25, 2018 · 3 comments
Open

Cannot call remove_from_ngram_index on collection #34

Startouf opened this issue Apr 25, 2018 · 3 comments
Labels

Comments

@Startouf
Copy link

Startouf commented Apr 25, 2018

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.

@dblock
Copy link
Contributor

dblock commented Apr 25, 2018

Looks like a bug to me.

@dblock dblock added the bug? label Apr 25, 2018
@Startouf
Copy link
Author

Startouf commented Apr 25, 2018

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 ?

@tomasc
Copy link
Contributor

tomasc commented May 5, 2018

@Startouf this PR #35 fixes the issues you are running into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants