search by substring in flutter with bloc [duplicate] - flutter

This question already has answers here:
Google Firestore: Query on substring of a property value (text search)
(25 answers)
Closed 2 years ago.
I store data in firestore and I want to query it using substrings. How can I perform a search with BLoC in flutter? I'm using Firestore and I need to search some items by substring from it.
I fail to understand how to properly perform a search. Could you share me some links with guides or examples?

I've found this article that explains how to request Firestore from flutter using the BLoC pattern. It's explained step by step and you will be able to reproduce it in order to understand the whole process.
You will also be introduced to "collections" and "documents", things that you should know when querying your database. Bear in mind that as stated in this answer you will not be able to filter just with the request, so you will have to request all the documents and filter them on your app.

Related

how to push firestore data to algolia Swift

I've been doing research for the last several hours finding out how to do full text search in iOS apps with Firestore. I eventually realized full-text search is not supported. I read up on Algolia, watched tutorials, read articles and still don't see a way to push data from Firestore to Algolia in Swift. Can somebody guide me to a post or maybe add like a code snippet or something to show me how I can use this software? Thanks.
Algolia offers SWIFT API client
Swift API client is an open source, production-ready API wrapper that abstracts from the complexity of directly interfacing with the Algolia Search API
Basically to work with algolia using any API client, you have to do few things,
Install the algolia client
https://www.algolia.com/doc/api-client/getting-started/install/swift/?client=swift
Initialize the client with your application ID and KEY
https://www.algolia.com/doc/api-client/getting-started/instantiate-client-index/
Indexing your data & Setup searchable attributes
https://www.algolia.com/doc/api-client/methods/indexing/
https://www.algolia.com/doc/guides/managing-results/must-do/searchable-attributes/
Perform search
https://www.algolia.com/doc/api-reference/api-methods/search/
Many sub-actions available within these to improve your experience with Algolia. I recommend you to go through the docs fully.
Yes, there are few other ways available to work with algolia, like using cloud functions for indexing data into algolia and doing only search from your client. But as you specifically mentioned SWIFT the above references would help you to get started!

Searching WITHIN a single doc - Firestore

I know that you can query a collection in Cloud Firestore to get documents that contain a certain field. However, is there a way where I can query/search WITHIN an already obtained document?
I am using it for a web app.
I know this question is a little vague and I have not provided any code, so I would be willing to provide clarification if needed.
Firestore doesn't provide a way to search the contents of a document snapshot that you already have. You will have to provide code to scan its field values yourself.

Firestore data model for posts and comments

I am currently watching a how-to create an instagram clone for Swift and want to understand the data model for the comments.
What is the purpose of using a model for the comments like:
post-comment (key = post-id) and comments
over something like this, where every comment has the post-id in it?
Without knowing what exactly they're building, and the types of queries they need to support for the app, one can only guess that this post-comments collection satisfies the need for a query to find out which comments are a part of which posts, while still allowing queries that search all posts or all comments. You should find the part of the tutorial that queries this collection to find out what it's trying to do.
This tutorial might be kind of old, because this sort of thing would be a little bit easier to express today using collection group queries.

Is there a way to retrieve a list of document IDs from a collection in Firestore? [duplicate]

This question already has answers here:
How to get a list of document IDs in a collection Cloud Firestore?
(4 answers)
Closed 3 years ago.
I've been researching efficient ways to retrieve data and one way is to set up what's basically a batch read (not sure if this is possible) from a list of document IDs.
I can probably store the document IDs in a field with an array, but curious if getting the list of document IDs (not all of the data within them) is possible in the Javascript library. I see it's possible with the REST API but so far I'm just using the client SDK so not sure I want to get started adding that.
For reference: https://firebase.google.com/docs/firestore/reference/rest/v1beta1/projects.databases.documents/list
There is no API for any mobile client SDK to get a list of just document IDs. You will have to query the entire collection and load all the documents.

Whole Word Search using Graph API? [duplicate]

This question already has answers here:
Using the Facebook Graph API to search for an exact string
(2 answers)
Closed 9 years ago.
I'm using the Graph API, but it's returning results I'm not looking for. I'm using /search?q=unmasked&type=post, but it's actually returning posts that contain unmask. I want to do a whole word search, but the Graph API seems to be stemming the search terms. Is there a way around this?
As far as I know, there is no way to search for exact expressions like you will be able to do on Google using double quotes: "To be or not to be".
Facebook intentionally implemented an algorithm to find similar words and help users to find relevant information.
But you won't be able to transcend it at the API level.
The only thing you can do, is to write a filter in your own language that checks in each returned post that "unmasked" is indeed included.
Edit: just saw that a duplicate question exists, you can get inspired from it (Using the Facebook Graph API to search for an exact string).