0

I need help.. So am making like a store kinda app. Where item name are stored in a cloud fire store and I want user to be able to search on the home page what they are looking for.. So what is most cost and time efficient way to allow user to search the entire database .. For example if the word "Bike " is type I want to search the database for all items with the name bike..

But so its is cost efficient I don't want it to run for individual letters until the whole word is submitted.. So it won't query for..

B.. Then BI.. Then BIK.

Only fore bike when it is submitted.. Please any help..

1 Answer 1

1

Create a TextEditingController like:

TextEditingController _controller;

Then assign your textField with your controller:

TextField(controller: _controller);

Now, in the onPressed method of a button, get the text of the user:

FlatButton(child: Text('Search!'), onPressed: (){String textResult = _controller.text})

Then if you want to set up a query then just use:

Firestore.instance.collection('Vehicles').where('name', whereIn: _controller.text).snapshots();

Example of hardcoded data:

Firestore.instance.collection('Vehicles').where('name', whereIn: 'Bike').snapshots();

The snapshots() function will return all the data related to that search.

You can use a StreamBuilder to retrieve the data.

Sign up to request clarification or add additional context in comments.

3 Comments

OK.. Thanks let me try that.. I would get back to you.
Quick question.. So if there is an item like ''Flash the movie' and the user searches on flash.. Would flash the movie come.. And also if I have 100000 documents would firebase not search through all of them is that cost friendly for me..
It depends. If the user searches flash the movie, but there is no specific "Flash the movie" in your name firestore field, it won't work. To overcome that though, you can use a for statement that gets each word and searches for that instead. As per cost, it's a better practice to structure your data into collections and subcollections instead of one huge collection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.