Edit $score using fulltext search / Handle Index on Textsearch?

#1

Hey Guys,

I am using a fulltext search inside my cloudCode. With this URL Request:

params: ‘where={“searchName”:{"$text":{"$search":{"$term":"’+_term+’"}}}}’

Now… If my term is 5 Characters long, I will get a result, but not before… Is there any way to configure the score of matching, so it will return me results even if 1 character is matching? Or is this a fixed setting due to performance in the search?

Help would be great.

Best Nico

#2

As long as I know, there is no minimum string length in the search process. You are probably observing one of these two scenarios:

  • MongoDB only indexes the complete stemmed terms. For example, if my document has a field with value “Parse Platform”, and I search for “Parse” it will return, but it won’t return if I search for “Pars”.
  • MongoDB excludes stop words like: “a”, “and”, “the”.

Can you please send an example of search that you are trying to do and what you expected to find?

#3

Hey, thanks for your reply. :slight_smile:

In my database “Event” i have a column named “searchname” containing names of the events based on their city, act and so on.
So let’s say it’s “berlin”.

If I send a request with “berl” to the textsearch, i get 0 results … until I send “berlin” - so it’s term based. But this seems like a limitation from parse server and mongoDB. Cause in “raw” mongo i could run something like:

{"$text":{"$search":“ber”}}

which is not working with parse-server.

You know a solution for this?

Best Nico

#4

Is it working directly in MongoDB and not through Parse Server API?

#5

It seems so - yes.

You can call: (Assuming the field contains “Linkin Park” as content)

curl -X GET \
-H "X-Parse-Application-Id: **" \
-H "X-Parse-REST-API-Key: **" \
-G \
--data-urlencode 'where={"searchName":{"$text":{"$search":{"$term":"link"}}}}' \
http://localhost:1337/parse/classes/Event

getting 0 results.

On mongoDB only you can query for

{"$text":{"$search":"link"}}

If I try the mongoDB Query on parse, I receive this error:

curl -X GET \
-H "X-Parse-Application-Id: konzertbegleitung" \
-H "X-Parse-REST-API-Key: restkey" \
-G \
--data-urlencode 'where={"searchName":{"$text":{"$search":"lin"}}}' \
http://localhost:1337/parse/classes/Event

{"code":107,"error":"bad $text: $search, should be object"}

#6

But are you receiving any result from Mongo when querying for this? The behavior should be the same. MongoDB uses “link” as a term and will try to match only complete terms in the objects. In this case, I understand that MongoDB should not return any results as well.

#7

If you take a look in this line here (https://github.com/parse-community/parse-server/blob/7122ca05c4e29ccf9d1c86ab3864b08508a09915/src/Adapters/Storage/Mongo/MongoTransform.js#L971), you will see that Parse Server just passes to MongoDB in the format of {"$text":{"$search":“the term goes here”}}

#8

Hmm so, what should be my apporach to get the results, I want to? (Instead of splitting the String-term into an array)

#9

Unfortunately, you will not be able to match partial terms with MongoDB text search (“Linkin Park” is not supposed to return if you search for “link” using this feature). I think your options are:

  • Accept the limitation of MongoDB text search :slight_smile:
  • Use Regular Expressions (https://docs.parseplatform.org/rest/guide/#queries-on-string-values) - you will have to do an additional query constraint for each of the document fields you want to search in and overall it does not have the same performance as text searches
  • Integrate to a third-party service such as Algolia or AWS Elastic Search - It will require you some additional effort to integrate and it’s not that cheap

I don’t know your real needs, but if I really need to match partial terms and my app is not yet so popular, I’d try to:

  1. Perform a text search in all fields I need

  2. In the case I got no results, I’d repeat the query, using SECONDARY read preference, with regular expression applied only in the most importat field(s)