Algolia Search Query
You can set up an Algolia Search backend query to automatically trigger a search once the user navigates to the page. This will help users to find any document present inside a Firestore Collection by providing a search term.
There are some prerequisites before you start defining the search query:
- A properly configured Algolia account.
- Have at least one Firestore Collection connected to the Algolia account.
- Completed Algolia configuration on FlutterFlow.
If you haven't completed these steps, please follow the instructions present on the following page before proceeding: Algolia Search
Building Search UI
You will need a text to be used as the search term while using the Algolia search backend query. Let's build a search UI to take the term as user input and display the results returned from the query in a list. You can use a TextField
to take the search term as input and a ListView
to display the results.
Follow the steps below to create this UI:
- Drag a TextField widget and drop it onto the canvas. (In the demo below, the TextField is placed inside the AppBar of the app).
- You can customize the TextField properties to match your app's design style. Add a search Icon to signify that it's a search field.
- Check the Update Page On Change checkbox. This helps to update the page as the user types inside the TextField. This would be required to use the latest text field value as the search term.
- Set an Update Delay (in milliseconds). This specifies the amount of time after the user stops typing to update the page.
- Now, drag and drop a ListView widget onto the canvas.
- Similarly, you can add widgets inside the ListView that you need for displaying the search result. (In the following demo, you will find that two Text widgets are added inside a Column).
Define Algolia Search Backend Query
Once the UI of the page is ready, you can move on to the next step, that is, defining an Algolia Search Backend Query.
Follow the steps below to define the Backend Query:
- Select the widget (or page) on which to apply the query. In this case, it's recommended to
apply the query on the
ListView
widget. - Select Backend Query from the Properties Panel (the right menu).
- Select the Query Type as Algolia Search.
- Choose the Firebase Collection on which to perform the search.
- Define from where to get the Search Term. You can either choose Specific Value or From Variable. If you want to use a
TextField
value as the search term, you should choose From Variable. - If you have chosen Specific Value,define the term inside the field present.
- If you have chosen From Variable, select a Source from the dropdown menu and then select an option from the Available Options. For example, if you want to use the value of a
TextField
, select the Source as Widget State and choose the field name under Available Options. - Set the number of maximum search results to fetch under Max Results. Keep this field blank if you want to fetch all the matching search results.
Display Search Results
Follow the step below to display the search results inside the ListView
:
- Select a widget present inside the
ListView
, for example, aText
widget. - Click Set from Variable from the Properties Panel (right menu).
- From the Source dropdown menu, choose the response of the Algolia Search that you had defined on the ListView widget.
- Under Available Options select the name of the field whose value you want to use.
- (Optional) You can specify a Default Value that would be shown if the field value is empty.
- Click Save.
- Repeat Steps 1 to 6 for using the search response data on any other widget.