Searching in Firebase RealtimeDB via WebAPI

ORIGINAL QUESTION
The RealtimeDB Component is a great way to store and retrieve data, but the question is if there’s a list of 100k entries (e.g. Movie Titles), how do you perform a search (Movie Title, Year, etc) and pagination ?

UPDATE: I realize that Web API could be used to perform the queries, but it doesn’t seem to do very well with alphabets filtering. See the following example:

A list of movies
{
{
“name” : “Rambo”
},
{
“name” : “Zombies”
},
{
“name” : “Madagascar”
},
{
“name” : “monster inc”
},
}

Upon querying with startAt=“M”, only “Madagascar” is displayed, “monster inc” also starts with “m” but it does not show up. Anyone with an idea to solve this issue?

Hey @billyljren, welcome to the community and thanks for posting the question! :wave:

what are the blocks you are using to call your database?

can you show a screenshot sample of the data tree?

If you want to do use advanced features, you may need to use the API. here are the docs to do what you are talking about. it even talks about how to order the results of the response

@jared I’ve been curious about this too. I see the specifics on Filtering data in the link you provided. (Now bookmarked.) But I’m new to Thunkable and Firebase’s NoSQL structure.

I’m no where near ready to begin coding these Filtering queries, but for now my question is a matter of theory. Does this Filtering facility allow for efficient (quick) retrieval of a single data-point from a list of 1000’s or even 100,000’s?

I know relational databases do this with keys, but… is this something that is just not possible with NoSQL db’s like Firebase? I suspect your answer will be something like, “it is possible if the data is structured correctly.” And If so, a few general pointers would be very helpful to this newbie.

This will make a big difference in my decision on what to build with Thunkable.

1 Like

You know, From the look of the docs, if you know the key, you can filter quickly. You can also return a filtered range of data, like all movies that start with the letter D for example. The bright side is you can easily construct these queries

Airtable does this easily but you my be limited by the Number of rows.

Here’s the blocks I’ve used to query.

And here’s the results I got.

UPDATE: Ignore this part regarding T < U, I’ve figured out it should be using T and T\uf8ff instead.
It starts at “T” and ends at “U”, which brings out all entries beginning with T < U but ignores t.

Maybe automatically converting to both Uppercase + Lowercase and performing the query twice is the only way ? One for T and one for t.

There’s also a question of what if users search anything in between ? e.g. searching for “matrix” would also match “The Matrix”. At this point, my understanding is that startAt and endAt doesn’t give that flexibility. Do shed some light.

@Townsend I found out that you’d have to achieve this using WebAPI instead of RealtimeDB component. Look at Firebase REST API docs. I’ve attached above on how my blocks look like. There’s also a limit results query parameter (limitToFirst) that can be added to restrict number of results returned, but its not straightforward like usual SQL that we are used to.

I think this is why some recommend use “Argolia” because argolia ignores wheter is Mayus or Minus , or if user search the matrix or matrix, I think is a little complicated…

Maybe you can add an appart data call it maybe “Search” and you type the name of the movie only in minus and the user text you convert it in minus but this still the users have to write the exact same words

Since you are surfing throught Firebase API , take a look at Cloud firestore API, I Switched completly from database to Cloud firestore, using full WebAPI, is totally possible…

If you are interesting let me know and i’ll show you some examples codes here

2 Likes

@Daniel_Coglitore I am. What benefit do you find using Firestone instead of Firebase

I’d be interested to explore that, could you share more information ?

Sorry is “Algolia” is a full text search? visit their web page or maybe in youtube some examples!

oh sorry I think Algolia doesnt have API for HTTPS,

you still can try the example I give you

1 Like

Is because of the querying , for example if you want to search in your database all the “restaurants” of “Japanese” food , located in the country of “Canada” in the city “Toronto” with the rates of “5” starts you can totally do that

also you can easily create a “Like” or “Counter” system, the function “Transform” allows you to easily do maths function in the firestore database.

that’s awesome! could you share an example by chance?


I’m going to get “upcomingMatches” from > Category = Honor and Country = Chile

API Url : https://firestore.googleapis.com/v1/projects/test-d03ac/databases/(default)/documents/Club/VBQMMKZlyqeYlhzmVa528LblHfC3:runQuery

API Body :

{
“structuredQuery”: {
“from”: [
{
“collectionId”: “upcomingMatches”
}
],
“where”: {
“compositeFilter”: {
“filters”: [
{
“fieldFilter”: {
“field”: {
“fieldPath”: “Filters.Category”
},
“op”: “EQUAL”,
“value”: {
“stringValue”: “Honor”
}
}
},
{
“fieldFilter”: {
“field”: {
“fieldPath”: “Filters.Country”
},
“op”: “EQUAL”,
“value”: {
“stringValue”: “Chile”
}
}
}
],
“op”: “AND”
}
}
}
}

This is the tool you’ll use for creating the body it will help you a lot

Parent(url in the google tool api): projects/test-d03ac/databases/(default)/documents/Club/VBQMMKZlyqeYlhzmVa528LblHfC3

Body

Response :

[{
“document”: {
“name”: “projects/test-d03ac/databases/(default)/documents/Club/VBQMMKZlyqeYlhzmVa528LblHfC3/upcomingMatches/202003062300mi8fdXFvY2g52IDHVKS8H9m5yPr2”,
“fields”: {
“Player2”: {
“mapValue”: {
“fields”: {
“ID”: {
“stringValue”: “dakshgdas”
},
“FullName”: {
“stringValue”: “- - - - -”
},
“Picture”: {
“stringValue”: “- - - - -”
}
}
}
},
“Player1”: {
“mapValue”: {
“fields”: {
“ID”: {
“stringValue”: “mi8fdXFvY2g52IDHVKS8H9m5yPr2”
},
“FullName”: {
“stringValue”: “D. Coglitore”
},
“Picture”: {
“stringValue”: “http://res.cloudinary.com/dcfaahtoy/image/upload/v1583083064/2019/iehbhccimtt4rjbferkk.jpg
}
}
}
},
“Filters”: {
“mapValue”: {
“fields”: {
“City”: {
“stringValue”: “Concepcion”
},
“Category”: {
“stringValue”: “Honor”
},
“Mode”: {
“stringValue”: “Singles”
},
“Country”: {
“stringValue”: “Chile”
}
}
}
},
“Status”: {
“mapValue”: {
“fields”: {
“Value”: {
“stringValue”: “Finished”
},
“Reason”: {
“stringValue”: “Game Finished without score given”
}
}
}
},
“Player4”: {
“mapValue”: {
“fields”: {
“Picture”: {
“stringValue”: “- - - - -”
},
“ID”: {
“stringValue”: “- - - - -”
},
“FullName”: {
“stringValue”: “- - - - -”
}
}
}
},
“MatchID”: {
“stringValue”: “202003062300mi8fdXFvY2g52IDHVKS8H9m5yPr2”
},
“Date”: {
“mapValue”: {
“fields”: {
“Complete”: {
“stringValue”: “March 06, 2020”
},
“Format”: {
“stringValue”: “2020-03-06”
}
}
}
},
“Club”: {
“mapValue”: {
“fields”: {
“ID”: {
“stringValue”: “VBQMMKZlyqeYlhzmVa528LblHfC3”
},
“Picture”: {
“stringValue”: “https://res.cloudinary.com/dcfaahtoy/image/upload/v1578071094/2019/LogoClubDeTenisDeConcepcion.png
},
“Name”: {
“stringValue”: “Club de Tenis de Concepcion”
}
}
}
},
“Time”: {
“mapValue”: {
“fields”: {
“Complete”: {
“stringValue”: “23:00”
},
“Format”: {
“stringValue”: “23-00”
}
}
}
},
“Score”: {
“stringValue”: “NA”
},
“Player3”: {
“mapValue”: {
“fields”: {
“Picture”: {
“stringValue”: “- - - - -”
},
“ID”: {
“stringValue”: “ASDasd”
},
“FullName”: {
“stringValue”: “asdasd”
}
}
}
}
},
“createTime”: “2020-03-07T01:07:39.928846Z”,
“updateTime”: “2020-03-09T21:07:06.521173Z”
},
“readTime”: “2020-04-14T15:04:58.711755Z”
}
,

1 Like

VERY COOL! thanks for sharing @Daniel_Coglitore! Thunkable apps can be powerful when we learn to move slightly beyond a pure #noCode approach!

1 Like

Thanks for sharing @Daniel_Coglitore! It is surely more complicated that I imagined.

I’ve been researching around and I found this RestDB, which seem to make life easier using Web API and simple query parameters. From the docs, it seems to support filter queries easily. I’m going to explore this one.
https://restdb.io/docs/querying-with-the-api#restdb

1 Like

Have you had any success using the RestDB API queries with thunkable?