0

After reading the Firebase documentation, I understood that the logical structure in NoSql is totally different than in SQlite. I can do basic searches ordered with:

orderByChild(), orderByKey() and orderByValue() and filtered with startAt(), endAt() and equalTo().

I'm building an app similar to the Bible. The app project requires that there be search filters, such as:

  • "Starting with": ex: Excelent
  • "Containing": ex: Exchent
  • "All Words": ex: Jesus is the same
  • Exact Phrase: ex: Jesus is the same

The Firebase Realtime Database function is excellent for fixing typing errors or missing text, once the broadcast changes on all devices, this is undoubtedly something phenomenal.

Considering the image:

See the structure of JSON in firebase

  1. Is it possible to do these search filters with Firebase?
  2. What is the best way to build these filters using Firebase's own API?
  3. Would I have to use these same filters with the offline data?
Community
  • 1
  • 1
  • It is not really possible. There are limited workarounds I think. – creativecreatorormaybenot Sep 13 '17 at 16:30
  • Firebase Realtime Database doesn't have text searching as you describe. – Doug Stevenson Sep 13 '17 at 16:48
  • Is there any other DataBase that when changing or adding data, it makes a broadcast, changing on all devices? What would be the best option? – Oséias Ribeiro Sep 13 '17 at 17:32
  • Yes, you can perform these kinda of queries. However, you have to do them in a 'NoSQL' way. You could 'push the easy button' with [ElasticSearch](https://medium.com/joolsoftware/extending-firebase-with-cloud-functions-elasticsearch-129fbbb951e0) or craft your own search engine. A lot of depends on much much text you have. See [this question](https://stackoverflow.com/questions/36365157/wildcard-query-on-firebase/36366619#36366619) and [another question](https://stackoverflow.com/questions/38538863/firebase-query-containing-value/38541967#38541967) for some hints. You can also filter in code. – Jay Sep 14 '17 at 20:36

2 Answers2

0

No, it's not possible. Unfortunately, Firebase does not provide a text search mechanism as you described in your post and as far as i know, there is no other database which provides something like this by default.

halfer
  • 19,824
  • 17
  • 99
  • 186
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
0

There is no such a think as a LIKE query equivalent in Firebase. You could create an extra node like this:

"common_queries": {
    "jesus": {
     "0": "awdawdn",
     "1": "oiefpowmfpowmf"
    },
    "eggcelent":{
     "0": "oiefpowmfpowmf"
    }
}

Then you can query trying to hit a key, and the results are the reference to the keys of other nodes.

There is another alternative wich involves using the startAt() method and endAt(), by adding the last text searchable value, here is a great video for it

I think Firebase is a tool in your toolbelt, in this case, is not the most suitable tool. Don't drill a hole with a circular saw, just use a drill.

cutiko
  • 9,887
  • 3
  • 45
  • 59
  • 1
    Using your tip, it worked. I was able to do a Query by bringing all paragraphs of a book and using Array to do the word search. Thank you! – Oséias Ribeiro Sep 14 '17 at 23:31
  • @OséiasRibeiro Great! Wich tip, the video or the "common_queries" node? – cutiko Sep 15 '17 at 00:03
  • paragrafos ----> UHIudiuhiUHRI10 ----> texto: "valor" banco de dados = FirebaseDatabase.getInstance (); reference = database.getReference ("paragrafos"); Consulta de consulta = reference.orderByChild ("id"). EqualTo (msgId); – Oséias Ribeiro Sep 15 '17 at 18:39