stijnsanders / TMongoWire

Delphi MongoDB driver
MIT License
102 stars 37 forks source link

Implement Search #49

Closed Skullwing closed 4 years ago

Skullwing commented 4 years ago

Hello,

I am programming a search function into my application. I already have two different ways implemented and would be interested to know if you or anyone has implemented a method yourself/himself. It has to be able to find parts of names, e.g. if I search for "Man" it has to output any document which holds the name "Manuel" or any other name with "Man".

I am happy for any information.

Thanks, Etienne

stijnsanders commented 4 years ago

I guess you'll need to use a special query. If I look at the documentation:

$regex takes a regular expression, so if you accept 'free' input from users, you'll have to convert it to a valid regular expression first. Don't let that scare you, there's a lot of info about them online, e.g. https://www.regextutorial.org/ . I once worked myself halfway through this one and it feels like I know what I need to, I've done some great things with regexes since the *

$text but that one uses a text index. I don't know what that is and if it's worth the extra effect it takes to set that up, but I guess it might, especially with the specific queries you're describing.

I was looking for a specific 'contains' string operator, which perhaps may exists but I'm currently overlooking. Or you could set up a (java)script function to do exactly what you need.