0

Hi I want implements search functions in my app who uses firebase for background I have some posts of users , I want if an users search " Apple " Every posts witch have apple in their description must be show . How can I do that please

1 Answers1

0

You can use Algolia to full text search your Firebase data – this is done by mirroring the posts in an index which can easily be maintained by setting up Cloud Functions to do it for you.

import * as algolia from 'algoliasearch'
import { config, firestore } from 'firebase-functions'

const { app_id, api_key } = config().algolia
const postsDocument = firestore.document('posts/{postId}')
const postsIndex = algolia(app_id, api_key).initIndex('POSTS')
const toObject = (snap) => ({ objectID: snap.id, ...snap.data() })

export const onCreatePost = postsDocument.onCreate((snapshot, context) => {
    return postsIndex.saveObject(toObject(snapshot))
});

export const onUpdatePost = postsDocument.onUpdate((snapshot, context) => {
    return postsIndex.saveObject(toObject(snapshot.after))
})

export const onDeletePost = postsDocument.onDelete((snapshot, context) => {
    return postsIndex.deleteObject(snapshot.id)
})
Callam
  • 11,409
  • 2
  • 34
  • 32
  • Read the tags I use Java not Javascript –  Apr 28 '18 at 16:51
  • Algolia provides an Android SDK so you can query the posts you're indexing. The javascript in my answer is for the cloud functions you'll need to deploy in order to keep your posts indexed – https://www.algolia.com/doc/api-client/android/getting-started/ – Callam Apr 28 '18 at 21:06