我可以将Firebase Cloud Functions用于搜索引擎吗? [英] Can I use Firebase Cloud Functions for search engine?

查看:62
本文介绍了我可以将Firebase Cloud Functions用于搜索引擎吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebase最近发布了与Cloud Functions的集成,该功能使我们能够上传Javascript函数来运行,而无需我们自己的服务器.

Firebase recently released integration to Cloud Functions that allows us to upload Javascript functions to run without needing our own servers.

是否可以使用这些功能构建搜索引擎?我的想法是使用本地磁盘(tmpfs卷)将索引数据保留在内存中,并且对于每个写入事件,我都会索引新数据. tmpfs是否在函数调用(实例)之间保留数据?

Is it possible to build a search engine using those functions? My idea is to use local disk (tmpfs volume) to keep indexed data in memory and for each write event I would index the new data. Does tmpfs keeps data between function calls (instances)?

可以将云功能用于此目的,还是应该使用专用服务器为数据建立索引?

Can cloud functions be used for this purpose or should I use a dedicated server for indexing data?

与此相关的另一个问题是:当云功能从Firebase实时数据库获取数据时,它消耗网络资源还是仅消耗磁盘读取资源?怎么计算呢?

Another question related to this is: when cloud functions get data from Firebase Realtime Database, does it consumes network or just disk reading? How is it computed in princing?

谢谢

推荐答案

您当然可以尝试.云功能具有本地文件系统,该文件系统通常用于在运行期间维护状态.有关更多信息,请参见以下答案:从Google Cloud Function写入临时文件

You could certainly try that. Cloud Functions have a local file system that typically is used to maintain state during a run. See this answer for more: Write temporary files from Google Cloud Function

但是(据我所知)不能保证在函数运行之间将保持状态.甚至该函数下次将在同一容器上运行.下次您可能正在新创建的容器上运行.或者,当调用激增时,您的函数可能会同时在多个容器上运行.因此,您可能必须为每次运行函数重建搜索索引.

But there are (as far as I know) no guarantees that state will be maintained between runs of your function. Or even that the function will be running on the same container next time. You may be running on a newly created container next time. Or when there's a spike in invocations, your function may be running on multiple containers at once. So you'd potentially have to rebuild the search index for every run of your function.

在本示例中,我将改为集成外部专用搜索引擎,例如Algolia: https://github.com/firebase/functions-samples/tree/master/fulltext-search .看一下代码:即使加上注释和许可,它也只有55行!

I would instead look at integrating an external dedicated search engine, such as Algolia in this example: https://github.com/firebase/functions-samples/tree/master/fulltext-search. Have a look at the code: even with comments and license it's only 55 lines!

或者,您可以找到一个持久性存储服务(Firebase Database和Firebase Storage是两个示例),然后使用该服务来持久化搜索索引.因此,您将运行代码以更新Cloud Functions中的搜索索引,但会将生成的索引文件存储在更持久的位置.

Alternatively you could find a persistent storage service (Firebase Database and Firebase Storage being two examples) and use that to persist the search index. So you'd run the code to update the search index in Cloud Functions, but would store the resulting index files in a more persistent location.

这篇关于我可以将Firebase Cloud Functions用于搜索引擎吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆