Full text search mongo or parse problem?

I’m trying to simply search our users with parse query based on phrase, so for example when I type: “mar” it will find “Mark” user (fullname) field. I’ve created mongodb text index, but it works only with full words. I can’t query for “Mar”, but need to type the full word “Mark”.
How to fix it?

Unfortunately there is no way to solve that. It is how mongodb full text search works (https://docs.mongodb.com/manual/reference/operator/query/text/#stemmed-words). You can achieve what you want with regex (very expensive) or maybe integrating to an elastic search solution.

Thank you,
maybe I could add another text field with all the sufixes “m ma mar mark” and then create index on that field, what do you think?

I am not sure. You need to test.

How long is your text? If you gonna create all possible substring by yourself, then maybe storing them in an array field and querying them with containedIn would perform better. Full text search is an expensive operation. But size of the text is important.

I guess it’s all a matter of your scale and use case. As @davimacedo says, regex is expensive, but if your data set isn’t too big, then this might be the quickest and easiest approach.

I’m currently doing a compound regex search matching across four user fields (username, name, surname, email) and it’s more than fast enough for me. I’ve ensured that I implement a debounce on the frontend so that I’m not hitting the server with every key stroke and this search feature is only used by admins, so I know the impact on the server is fairly limited.

Definitely be careful with this sort of thing though :slight_smile:

const usernameQuery = new Parse.Query("_User").matches("username", term, "i");
const nameQuery = new Parse.Query("_User").matches("name", term, "i");
const surnameQuery = new Parse.Query("_User").matches("surname", term, "i");
const emailQuery = new Parse.Query("_User").matches("email", term, "i");

const users = await Parse.Query.or(
  usernameQuery, nameQuery, surnameQuery, emailQuery
).find({ useMasterKey: true });

We tried with full text search as well and regex but we decided to use Elasticsearch instead which is much more efficient and allow us to search on different field with different rules (names, usernames, emails…)
We still have to try with MongoDB Atlas Search to see if we can do the same without Elasticsearch.

Have you a chance to investigate the MongoDB Atlas Search as an alternative to ElasticSearch? I am using a custom plugin in the ElasticSearch and would be interested if this is transferable as both search engines are based on Lucene?

Not for now
Lots of queries we use on ES are not available on Atlas Search (like geo queries, aggs, etc.)
And it does not seems as easy as it sounds to convert index mapping from ES to Atlas Search to use the pure text search for autocomplete

1 Like

Looking into the documentation I see there are geo query operators. I am not sure how would these could be used efficiently as I haven’t tried it yet.

One other thing I am not sure are custom plugins. In ElasticSearch I am using a Roaring Bitmap to pass large Bloom Filter to the Elastic Search and the plugin scores results that are already in the Bloom Filter with a value bellow threshold. I avoid this way fetching the same documents twice. Alternative to that could be term operator (or text as term is deprecated) but this would mean I would need to pass around the Bloom Filter in non-compressed Roaring Bitmap format.

Perhaps @Manuel would know if there is a possibility to implement custom plugin that would read Roaring Bitmap passed as parameter to search query and then use it to score results?

Thanks!

We successfully use Meilisearch as an open source alternative for full-text search. It integrates very well with parse server

MongoDB Atlas Search supports most/if not all (few like vector search) the Lucene implementations. Partial key word search can be implemented through Autocomplete (https://www.mongodb.com/docs/atlas/atlas-search/tutorial/autocomplete-tutorial/) or through regex or wildcard operators.

PS: geo queries can be run using the regular Mongodb 2dspere indexes or Atlas search geo-queries (https://www.mongodb.com/docs/atlas/atlas-search/tutorial/run-geo-query/)

do you know how to call an atlas search query with the parse SDK? is there an easy integration, or do you need to use the mongo node client instead or going through parse?

You could use the $search stage in an aggregation pipeline to use MongoDB Atlas Search.

is there any document of MS for parse server /.