Firebase 和索引/搜索 [英] Firebase and indexing/search

查看:28
本文介绍了Firebase 和索引/搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将 Firebase 用于一个应用程序,该应用程序应该人们对几千个对象的集合使用全文搜索.我喜欢提供仅客户端应用程序的想法(不必担心托管数据),但我不确定如何处理搜索.数据将是静态的,因此索引本身并不是什么大问题.

I am considering using Firebase for an application that should people to use full-text search over a collection of a few thousand objects. I like the idea of delivering a client-only application (not having to worry about hosting the data), but I am not sure how to handle search. The data will be static, so the indexing itself is not a big deal.

我假设我需要一些额外的服务来运行查询并返回 Firebase 对象句柄.我可以在某个固定位置启动这样的服务,但随后我不得不担心它的可用性和可扩展性.虽然我不希望这个应用有太多的流量,但它可以达到几千个并发用户的峰值.

I assume I will need some additional service that runs queries and returns Firebase object handles. I can spin up such a service at some fixed location, but then I have to worry about its availability ad scalability. Although I don't expect too much traffic for this app, it can peak at a couple of thousand concurrent users.

建筑思想?

推荐答案

从长远来看,Firebase 可能有更高级的查询,所以希望它可以直接支持这类事情,而无需您做任何特殊的事情.在此之前,您有几个选择:

Long-term, Firebase may have more advanced querying, so hopefully it'll support this sort of thing directly without you having to do anything special. Until then, you have a few options:

  1. 编写服务器代码来处理搜索.最简单的方法是运行一些负责索引/搜索的服务器代码,正如您提到的.Firebase 有一个 Node.JS 客户端,因此这是将服务连接到 Firebase 的一种简单方法.所有数据传输仍然可以通过 Firebase 进行,但是您可以编写一个 Node.JS 服务来监视 Firebase 中某个指定位置的客户端搜索请求",然后通过将结果集写回 Firebase 来响应",对于客户消费.
  2. 将索引存储在 Firebase 中,客户端会自动更新它.如果您想变得非常聪明,您可以尝试实施一个无服务器方案,让客户端在写入数据时自动为其数据编制索引.. 因此,全文搜索的索引将存储在 Firebase 中,当客户端将新项目写入集合时,它也将负责相应地更新索引.为了进行搜索,客户端将直接使用索引来构建结果集.对于您想要索引存储在 Firebase 中的复杂对象的一个​​字段的简单情况,这实际上很有意义,但对于全文搜索,这可能非常粗糙.:-)
  3. 将索引存储在 Firebase 中并使用服务器代码更新它.您可以尝试一种混合方法,将索引存储在 Firebase 中并由客户端直接使用进行搜索,而不是让客户端更新索引,只要有新项目添加到集合中,您就会拥有更新索引的服务器代码.这样,当您的服务器关闭时,客户端仍然可以搜索数据.在您的服务器赶上索引编制之前,他们可能会得到陈旧的结果.
  1. Write server code to handle the searching. The easiest way would be to run some server code responsible for the indexing/searching, as you mentioned. Firebase has a Node.JS client, so that would be an easy way to interface the service into Firebase. All of the data transfer could still happen through Firebase, but you would write a Node.JS service that watches for client "search requests" at some designated location in Firebase and then "responds" by writing the result set back into Firebase, for the client to consume.
  2. Store the index in Firebase with clients automatically updating it. If you want to get really clever, you could try implementing a server-less scheme where clients automatically index their data as they write it... So the index for the full-text search would be stored in Firebase, and when a client writes a new item to the collection, it would be responsible for also updating the index appropriately. And to do a search, the client would directly consume the index to build the result set. This actually makes a lot of sense for simple cases where you want to index one field of a complex object stored in Firebase, but for full-text-search, this would probably be pretty gnarly. :-)
  3. Store the index in Firebase with server code updating it. You could try a hybrid approach where the index is stored in Firebase and is used directly by clients to do searches, but rather than have clients update the index, you'd have server code that updates the index whenever new items are added to the collection. This way, clients could still search for data when your server is down. They just might get stale results until your server catches up on the indexing.

在 Firebase 有更高级的查询之前,如果您愿意运行一些服务器代码,#1 可能是您最好的选择.:-)

Until Firebase has more advanced querying, #1 is probably your best bet if you're willing to run a little server code. :-)

这篇关于Firebase 和索引/搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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