Merym
Merym

Reputation: 901

Search with multi fields firestore

I have collection of places:

PLaces:
  doc1:
   title:    "Paris"
   category: "Pharmacy"
   city:      "Paris"
 doc2:
   title:     "Paris"
   category:   "Pharmacy
   city: "New york"

  doc3:
   title:     "Paris"
   category:   "School
   city: "New york"

And if I want to search places that there name contains Paris , I would do the following:

>  db.collection('places')
>     .orderBy('title')
>     .startAt(['Paris']).endAt(['Paris'+ '\uf8ff']).getDocuements();

And that would show me all the places that contain the name paris.

However, how would I be able to search places with other criteria like

get just Pharmacy with name paris or pharmacy paris in city Paris Knowing that there is one Input field which allowed to write the search keywords

example of inputs Searchs :

Is this even possible in Cloud Firestore? If not is there any alternative way to do this?

Upvotes: 0

Views: 1298

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317968

If you're asking if it's possible to accept a single string and search across fields with it, no it's not possible. Firestore isn't a text search engine.

The only way you can query across fields is using a compound search query as described in that documentation. You have to call out each field you want to match, and you can only have one range filter per query (so you can't use startAt/EndAt with multiple fields). You will need to use the exact values of the fields to filter the results.

If you want full text search, the documentation recommends mirroring your data to an actual text search engine.

Upvotes: 2

Related Questions