Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

reactjs - algolia full text search, firebase

i am using the firebase boilerplate: https://github.com/WataruMaeda/react-firebase-boilerplate

and immediately tried to add full text search.

Code

import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();
const env = functions.config();

const algoliasearch = require("algoliasearch");

var client = algoliasearch(env.algolia.appid, env.algolia.apikey);
const index = client.initIndex("Moseley");

exports.indexHomecare = functions.firestore
  .document("contractors")
  .onCreate((snap, context) => {
    const data = snap.data()
    const objectId = snap.id
    return index.addObject({
      objectId,
      ...data,
    })
  });

exports.removeHomeCare = functions.firestore
  .document("contractors")
  .onDelete((snap, context) => {
    const objectId = snap.id
    return index.deleteObject({
      objectId,
    })
  });

error message

+  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
+  functions: required API cloudbuild.googleapis.com is enabled
+  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (43.24 KB) for uploading
+  functions: functions folder uploaded successfully
i  functions: uploading functions in project: indexHomecare(europe-west2), removeHomeCare(europe-west2)
i  functions: creating Node.js 12 function indexHomecare(europe-west2)...
i  functions: creating Node.js 12 function removeHomeCare(europe-west2)...
!  functions: failed to create function removeHomeCare
HTTP Error: 400, The request has errors
!  functions: failed to create function indexHomecare
HTTP Error: 400, The request has errors


Functions deploy had errors with the following functions:
        indexHomecare
        removeHomeCare


To try redeploying those functions, run:
    firebase deploy --only "functions:indexHomecare,functions:removeHomeCare"


To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

Having trouble? Try firebase [command] --help

C:Userspjsupportfolio
eact-firebase-boilerplatefunctions>

There does not seem to be any error message telling me what is wrong, further I have closely followed the fireship video here: https://www.youtube.com/watch?v=3Z0V3cvgns8&ab_channel=Fireship

any ideas how to fix this?

question from:https://stackoverflow.com/questions/65837478/algolia-full-text-search-firebase

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like the failure was due to the error in your function code.

  1. indexHomeCare - To add object to index you have to use saveObject
  1. removeHomeCare - To remove an object from index, pass the object ID as string value / or for multiple delete within an array.
exports.indexHomecare = functions.firestore
  .document("contractors")
  .onCreate((snap, context) => {
    const data = snap.data()
    const objectId = snap.id
    return index.saveObject({
      objectId,
      ...data,
    })
  });

exports.removeHomeCare = functions.firestore
  .document("contractors")
  .onDelete((snap, context) => {
    const objectId = snap.id
    return index.deleteObject(objectId);
  });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...