🔎 Fuzzy Search
With Backendflow's Fuzzy Search, you can add complex search to your Firebase apps.
How does it work?
Firebase stores data in collections, so querying is a little bit different than SQL. There's no default way to "search" a list of documents in your Firestore collection the same way you could do with SQL LIKE statements. Instead, Firebase offers a couple of basic querying options:
Equals (and Not Equals)
Greater than (and not greater than)
In (and not In)
Starts with
Lets say you want to search for "apple" in a list of fruits:
Name: Apple
Color: Red
Taste: Sweet
Name: Orange
Color: Orange
Taste: Sour
Name: Banana
Color: Yellow
Taste: Sweet
For understandable reasons, equals isn't helpful because "apple != Apple". Starts with also wouldn't work, because it is case sensitive - so "app" would not result in "Apple" showing up. This isn't a good user experience for search, so we must find a better way to do it.
Fuzzy Search
Fuzzy Search approaches things differently. It says: "I'm going to download every single document in this collection, and then use string similarity to find results that are close to my search query." This has pros and cons:
Pro: Strings like "app" or "apple" or "apl" or "aaapple" will all result with "Apple".
Pro: If your fruits have other fields, like taste, or color, you can also search "red", and "Apple" will show up. If you search for "Sweet", both Apple and Banana would show up.
Con: If you have a lot of documents (lets say 100,000), each time you search, it will make 100,000 reads (or equivalent to $0.0345 in read costs). So if you have 100 users searching 100,000 documents once a day, that would amount to $3.45 in total cost. So, in some cases, it wouldn't make sense to do Fuzzy Search.
When would it make sense to do Fuzzy Search?
In general, the benefit of Fuzzy Search is that:
It is much easier to set it up compared to other forms of Search (like Algolia)- so the benefit you are getting is terms of developer time and complexity.
When using a small collection, it is far cheaper than Algolia - which in many cases translates to higher cost savings.
In cases of having hundreds of thousands (or millions) of records, and when such collections are combined with high search volume (hundreds or thousands of users searching each time), then it is recommended to use Algolia instead of Fuzzy Search to save on reads. Otherwise, Fuzzy Search is preferable because of its ease of use and cost savings.
How to use Backendflow Fuzzy Search
The Backendflow Fuzzy Search is just an API that is connected to your project. Here's how to enable it:
Go to your Backendflow Project
Click on the Fuzzy Search button on the sidebar
Click on the checkbox
Now, your Backendflow Fuzzy Seach is enabled for your project. To use this API, you can either export the API file directly (and uploading it to Flutterflow if you have an FF paid plan) or add the API manually based on these specifications:
POST
https://api.backendflow.io/v1/fuzzySearch
Request Body
apiKey*
String
Your backendflow API key
collectionName*
String
The collection you are searching
fieldNames*
List of String
The document fields you are querying (e.g. ["name", "taste", "color"])
For Flutterflow API Export: Make sure you enter the fieldNames a one string separated by commas, like "name,taste,color". Do not enter it as an array form.
searchString*
String
The search string you are using
limit
Integer
The number of results you want to show
The results of the API call look something like:
You can then use Flutterflow's JSON path mechanism to retrieve the document data. We also attach the documentId for each resulting document, which you can then use to generate a Document Reference to pass around in Flutterflow, if needed.
Note: For Flutterflow Users
As mentioned, there are two ways to use Backendflow's APIs: 1. Manually 2. The Flutterflow API export button.
When exporting the API and uploading it directly to Flutterflow, the API has to be a little bit different to match Flutterflow's specific styling. The one key difference is that the API will pass values through the query parameters instead of the JSON body. This means, the `fieldNames` argument must be a string separated by commas instead of a standard JSON array.
For example:
Instead of:
Last updated