0

I want search from firstore database user that displayname or nickname contians the search term. I have following code but don't search.

export const searchUsers = async (queryText)=>{
const searchTerm=queryText.toLowerCase();
const usersRef = collection(db, "users");
const users = [];
// Create a query against the collection.
const q = query(usersRef, where("displayName", "array-contains", searchTerm)||where("nickName", "array-contains", searchTerm) ,orderBy("nickName"));
onSnapshot(q, (querySnapshot) => {
    
    querySnapshot.forEach((doc) => { console.log("docsearch:"+doc)
        users.push(doc.data());
    });

})
return users;

}

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ogs1017
  • 1
  • 2
  • Please edit your question to show a screenshot of a document in the Firestore console that you expect this query to return. --- Note that Firestore does not have full-text search operators though, so you can't search for a value that *contains* another string. I just commented about that here too: https://stackoverflow.com/questions/75070421/improve-search-in-flutter-firebase-with-multiple-parameters-lowcase-contains#comment132477665_75070421 – Frank van Puffelen Jan 10 '23 at 14:25

1 Answers1

0

I dscoveret that the best way from this issue is make indexes with algolia following the next video: https://www.youtube.com/watch?v=eD1CUWs_3_k&ab_channel=midudev

ogs1017
  • 1
  • 2
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](https://meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it is there, then quote the most relevant part of the page you are linking to in case the target page is unavailable. – cursorrux Jan 12 '23 at 05:43