Closed frostbytedata closed 6 years ago
Which version of MongoDB do you have?
It appears I am using v3.4.10. And using v1.1.1 of your plugin.
I added an integration test for the REST API https://github.com/arve0/feathers-mongodb-fuzzy-search/pull/6, it seems to work fine. I also use Mongo 3.4.1.
@claustres correct me if i'm wrong but it looks as if those tests are for the messages service which is only doing a full text search and therefore isn't actually using $regex?
Yes you are right but it is an integration test, it ensures the module still works when called from an external provider instead of internally. If it works for one service it should for the others or this is more likely a bug in Feathers and not the module.
Anyway I also added a test for the users
service which uses $regex
.
@frostbytedata can you try /customers?name[$search]=sharon
and see if that works for you?
I tested it locally since I prefer to use the request library to make sure the URL is correctly formatted in tests and it works as well. We might integrate the feathers client library to make integration test still one level up but not sure if it is required.
I will test this as soon as I'm back at my desk. Thanks for the replies guys.
@nathanstaines Nathan your syntax works!! /customers?name[$search]=sharon
Thanks a bunch!! So was this just me acting like a fool? or Is there a discrepancy in the README? Thanks again guys!!
Regex requires a field to search on in the query contrary to full-text search, cf. https://github.com/arve0/feathers-mongodb-fuzzy-search#usage.
Seems like an inconsistency between this module and feathers-nedb-fuzzy-search which does full text search through a number of specified fields, while with this module one gets
MongoError: unknown top level operator: $regex
I'm trying to use both simultaneously as using NeDB simplifies development, it's surprisingly simple and robust to do.
Update1:
Using only search()
I get the error Error: text index required for $text query
. I do have an index set on one of the columns of the collection.
Update2: Found out text indexes are not the same as regular old indexes, I managed to make it work for MongoDB only with these instructions... https://docs.mongodb.com/manual/core/index-text/
Update3: $text can't really pull off fuzzy search at all. If I search "Kardashian", it won't find "The Kardashians" which is no what most people expect.
Using nodejs mongodb
client 3.0.0-rc0
Well not sure how we can unify since it seems to be a little bit different. In this module the field search allows you to search for different patterns on different fields simultaneously like { firstName: { $search: 'ay' }, lastName: { $search: 'b' } }
. If I understand it well the other module allows you to select which fields will be used for the full-text search but not to query fields individually.
If you want to use both with the same code base you should only use the common feature of the full-text search and not the field matching feature, so use only search()
without the fields option. With this module which fields are used to perform the full-text search is based on the MongoDB indexes.
Adding: Field search can be implemented in NeDB too, the code should be similar to this plugin. See https://github.com/louischatriot/nedb#operators-lt-lte-gt-gte-in-nin-ne-exists-regex
@rayfoss Please open an issue at feathers-nedb-fuzzy-search, so we can track it where it belongs.
I believe I am doing something wrong here to see this message when my service method is called:
Method: find: unknown top level operator: $regex
Here are my service hooks:
And the GET request I am making as a URL:
GET /customers?$search=sharon
I read through the README, but don't think I am missing anything. Of course I used
npm install
to add the plugin. Any ideas? Thanks!