在前端应用程序中实时搜索数据库的最佳方法是什么?

huangapple go评论86阅读模式
英文:

What is the best approach searching data in database from the front end application in real-time?

问题

我正在使用Flutter-NodeJS-Cassandra编写一个全栈应用程序。我想要添加一个搜索栏,用户可以在数据库中搜索某些内容,比如特定的产品,例如。同时,用户在搜索栏中输入内容时,会提供一个建议列表(就像我们在许多网站/应用程序或Google地图中看到的,当用户输入与已输入内容相似的位置时,会提供类似的建议)。

我不知道最佳的做法是什么?

  1. 我应该捕获用户在textField中进行的每一次更改,并针对每次更改向数据库发出查询吗?(每次更改都会有一个查询)。

  2. 我应该首先从数据库中读取所有数据,然后在前端应用程序中搜索用户尝试查找的内容吗?(只有一个查询来获取所有可用的数据)。

英文:

I am writing a full stack application using Flutter-NodeJS-Cassandra. I want to add a search bar that user can search something inside the database, like a specific product for example. Also a suggestion list will be available while user is writing into the search bar( like what we see in many websites/applications or google map when it suggests for similar locations to what has been typed by user so far).

I don't know what is the best way of doing that?

  1. Should I capture every changes user makes in the textField and make a query to the database for each change happen? (one query for each change).

  2. Should I read all the data from database first, then search what user tries to find in the front-end application? (only one query for all the available data).

答案1

得分: 1

你可以选择你提出的任一方法,但查找不完整的单词会非常昂贵。此外,在Cassandra中,你需要确切的分区键,如果单词不完整可能不会有帮助。例如,如果我的表的分区键是(color),我输入 blu 并进行搜索,这对我没有帮助,因为在基本的Cassandra中不会显示任何结果。

你可能需要的是一个预测性文本库,例如:

https://pypi.org/project/pressagio/

再加上类似Solr Search或Elastic这样的东西,可以对你的表进行索引并根据关键词进行搜索。

以前的例子来说,Solr和Elastic将允许你使用 blu* 并找到所有包含字母 blu 的内容。

英文:

You could do either of those that you suggested, but it would be very expensive to look up incomplete words. Besides that, in Cassandra, you would need exact partition keys, which probably wouldn't help you if the words were incomplete. For instance, if my table's partition key is (color), and I type, blu and do a search, that doesn't help me at all because nothing will come up in base Cassandra.

What you probably need is a predictive text library, for example:

https://pypi.org/project/pressagio/

Along with something like Solr Search or Elastic to be able to index your table and search on keywords.

Given the previous example, Solr and Elastic would allow you to use blu* and find everything with the letters blu in it.

答案2

得分: 1

你可以选择使用DSE Search。请参阅此示例

英文:

You may alternatively use DSE Search. See this example.

huangapple
  • 本文由 发表于 2023年6月8日 05:50:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427313.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定