Back

Query.search not working when searching for number string

  • 0
  • Self Hosted
  • Flutter
Kevins35
10 Jun, 2024, 20:14

Im encountering an issue while using the Query.search Query, to filter a fulltext string Attribute ("modell") in my database. I have a document in my database with a name containing "T561". When using Query.search("modell", "T56") i get the right document. If I however use the Query Query.search("modell", "56") i won´t get the corresponding document.

To me it seems, that there is an issue, when using a filter, containing no letters. Is this an issue on my side or is this a bug within appwrite.

Here is an example of how i use the Query (obviously this is a temporarily hardcoded Value for debugging purposes)

TypeScript
DocumentList response = await databases.listDocuments(
      databaseId: storeSpecificDatabase,
      collectionId: devicesCollection,
      queries: [
        Query.limit(count),
        Query.offset(offset),
        Query.orderAsc('manufacturer'),
        Query.orderAsc('modell'),
        Query.search("modell", "T56")
      ],
    );

Im Using Appwrite 1.5.1 and the appwrite Flutter SDK version 12.0.0

Help is apreciated. Thanks in advance

TL;DR
Developers are having an issue with `Query.search` function when searching for a number string. The issue seems to occur when the filter contains no letters. The solution is to use `contains` instead of `search` for a substring match.
Steven
10 Jun, 2024, 20:17

This is expected because search does not do a substring match.

Perhaps you can try contains instead

Kevins35
10 Jun, 2024, 20:23

Well thank you for the quick help. That was the solution. I was under the impression that contains is only used for finding a value in an array.

Steven
10 Jun, 2024, 20:26

It's substring if used on a string attribute

Kevins35
10 Jun, 2024, 20:27

ah i see... thankyou 🙂

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more