简体   繁体   English

具有错字容忍、计数、用户特定等功能的列表的高级过滤?

[英]Advanced filtering of a list with typo-tolerance, counting, user-specific etc.?

I am building an Android application, later on maybe also an iOS version of the app and a web application.我正在构建一个 Android 应用程序,稍后可能还会构建一个 iOS 版本的应用程序和一个 Web 应用程序。 I have a list, for example in this way:我有一个列表,例如以这种方式:

City Name城市名称 State状态 Counter Clicked计数器点击 More columns更多栏目
Dallas达拉斯 Texas德克萨斯州 4 4
Boston波士顿 Massachusetts马萨诸塞州 3 3
New York City纽约市 New York纽约 1 1
San Francisco旧金山 California加利福尼亚州 3 3
San Diego圣地亚哥 California加利福尼亚州 3 3
Seattle西雅图 Washington华盛顿 10 10
Boise博伊西 Idaho爱达荷州 0 0

I am searching for a solution how to meet the following requirements:我正在寻找如何满足以下要求的解决方案:

  • The list and its data are always up to date and transferred from a backend system (Google Firebase) when the user is online.该列表及其数据始终是最新的,并在用户在线时从后端系统 (Google Firebase) 传输。
  • The solution needs to work on iOS / Android devices and if possible also on a website.该解决方案需要在 iOS / Android 设备上运行,如果可能,还需要在网站上运行。
  • Typing in "D" only "Dallas" should be displayed.输入“D”只应显示“Dallas”。
  • Typing in "S" Seattle, San Diego, and San Francisco should be displayed in this order, because of the "Counter Clicked" value (the higher the value, the more relevant is the result)键入“S”西雅图、圣地亚哥和旧金山应按此顺序显示,因为“Counter Clicked”值(值越高,结果越相关)
  • Typing in "S" also Dallas, Boston, Boise should be displayed in this order (regarding "Counter Clicked") after the words beginning with "S", because they are containing the letter "S" within the word.在以“S”开头的单词之后,输入“S”也应按此顺序(关于“Counter Clicked”)显示达拉斯、波士顿、博伊西,因为它们在单词中包含字母“S”。
  • The "Counter Clicked" is handled per user. “点击计数器”按用户处理。 So the City Name can be selected and every time the user selects the city name, the "counter clicked" should be increased by 1.因此可以选择城市名称,每次用户选择城市名称时,“点击计数器”应增加 1。
  • The filter service should be offline ready, so the "Counter Clicked" should be handled on the device.过滤器服务应该是离线准备好的,所以应该在设备上处理“Counter Clicked”。 I am not quite sure if it makes sense to upload the data back to the Firebase backend server, what do you think?我不太确定将数据上传回 Firebase 后端服务器是否有意义,您怎么看?
  • It would be great to have a typo tolerance.有错字容忍度会很棒。 So for example typing "Bostn" or "Sen" (tolerance by one letter) "Boston" or "San …" should be displayed.因此,例如键入“Bostn”或“Sen”(一个字母的容差)“Boston”或“San ...”应显示。
  • I will also have the possibility to have a facet filter so that I can filter before typing for one of the "State"s of the USA.我还将有可能拥有一个方面过滤器,以便我可以在输入美国“州”之一之前进行过滤。

I am interested in a professional solution if this is available on the market, otherwise, I need to build it for myself.如果市场上有专业的解决方案,我对它感兴趣,否则,我需要为自己构建它。

I am building an Android application, later on maybe also an iOS version of the app and a web application.我正在构建一个 Android 应用程序,稍后可能还会构建一个 iOS 版本的应用程序和一个 Web 应用程序。

You can achieve that using Firebase because:您可以使用Firebase实现这一目标,因为:

Firebase is a platform developed by Google for creating mobile (iOS and Android) and web applications. Firebase 是由 Google 开发的用于创建移动(iOS 和 Android)和 Web 应用程序的平台。

I am searching for a solution how to meet the following requirements我正在寻找如何满足以下要求的解决方案

To answer your questions, I will use Cloud Firestore which is:为了回答您的问题,我将使用Cloud Firestore ,它是:

Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud. Cloud Firestore 是一个灵活、可扩展的数据库,用于 Firebase 和 Google Cloud 的移动、网络和服务器开发。 Like Firebase Realtime Database, it keeps your data in-sync across client apps through real-time listeners and offers offline support for mobile and web so you can build responsive apps that work regardless of network latency or Internet connectivity.与 Firebase 实时数据库一样,它通过实时侦听器使您的数据在客户端应用程序之间保持同步,并为移动设备和 Web 提供离线支持,因此您可以构建响应式应用程序,无论网络延迟或互联网连接如何。

Let's get started:让我们开始吧:

The list and its data are always up to date and transferred from a backend system (Google Firebase) when the user is online.该列表及其数据始终是最新的,并在用户在线时从后端系统 (Google Firebase) 传输。

You have the answer right above, "it keeps your data in-sync across client apps through realtime listeners ".您的答案就在上面,“它通过实时侦听器使您的数据在客户端应用程序之间保持同步”。 So your data will always up to date.因此,您的数据将始终是最新的。

The solution needs to work on iOS / Android devices and if possible also on a website.该解决方案需要在 iOS / Android 设备上运行,如果可能,还需要在网站上运行。

It will, as Firebase is a cross-platform solution.它将,因为 Firebase 是一个跨平台的解决方案。

Typing in "D" only "Dallas" should be displayed.输入“D”只应显示“Dallas”。

You can achieve that in a very simple way, by using Query's startAt() method:您可以通过使用 Query 的startAt()方法以非常简单的方式实现这一点:

Creates and returns a new Query that starts at the provided fields relative to the order of the query.创建并返回一个新的查询,该查询从与查询顺序相关的提供的字段开始。

So you query should look in code like this:所以你的查询应该是这样的代码:

ref.collection("cities").orderBy("cityName").startAt(name).endAt(name + "\uf8ff");

You can also check the docs for that, and see my answer from the following article:您还可以查看文档,并从以下文章中查看我的答案:

Typing in "S" Seattle, San Diego, and San Francisco should be displayed in this order, because of the "Counter Clicked" value (the higher the value, the more relevant is the result)键入“S”西雅图、圣地亚哥和旧金山应按此顺序显示,因为“Counter Clicked”值(值越高,结果越相关)

To solve this, you can use Query's orderBy(String field, Query.Direction direction) method:要解决这个问题,您可以使用 Query 的orderBy(String field, Query.Direction direction)方法:

Creates and returns a new Query that's additionally sorted by the specified field, optionally in descending order instead of ascending.创建并返回一个新的 Query,该 Query 额外按指定字段排序,可选择按降序而不是升序。

So you can display those cities according to the number of the "Counter Clicked".因此,您可以根据“点击计数器”的数量显示这些城市。

Typing in "S" also Dallas, Boston, Boise should be displayed in this order (regarding "Counter Clicked") after the words beginning with "S", because they are containing the letter "S" within the word.在以“S”开头的单词之后,输入“S”也应按此顺序(关于“Counter Clicked”)显示达拉斯、波士顿、博伊西,因为它们在单词中包含字母“S”。

Unfortunately, Firestore does not support full-text search.不幸的是,公司的FireStore支持全文搜索。 The official documentation regarding the full-text search in Cloud Firestore is up to date and stands for Algolia.关于Cloud Firestore 中全文搜索的官方文档是最新的,代表 Algolia。

For Android, please see my answer from the following post:对于 Android,请参阅我在以下帖子中的回答:

Or:要么:

The "Counter Clicked" is handled per user. “点击计数器”按用户处理。 So the City Name can be selected and every time the user selects the city name, the "counter clicked" should be increased by 1.因此可以选择城市名称,每次用户选择城市名称时,“点击计数器”应增加 1。

This can be very simply achieved using FieldValue.increment(1) as explained in my answer from the following post:这可以使用FieldValue.increment(1)非常简单地实现,如我在以下帖子中的回答中所述:

The filter service should be offline ready, so the "Counter Clicked" should be handled on the device.过滤器服务应该是离线准备好的,所以应该在设备上处理“Counter Clicked”。 I am not quite sure if it makes sense to upload the data back to the Firebase backend server, what do you think?我不太确定将数据上传回 Firebase 后端服务器是否有意义,您怎么看?

According to the official documentation regarding Access data offline :根据有关离线访问数据的官方文档:

Cloud Firestore supports offline data persistence. Cloud Firestore 支持离线数据持久化。 For Android and iOS, offline persistence is enabled by default.对于 Android 和 iOS,默认启用离线持久化。 For the web, offline persistence is disabled by default.对于 Web,默认情况下禁用离线持久性。 To enable persistence, call the enablePersistence method.要启用持久性,请调用 enablePersistence 方法。

So you have support for three platforms, and yes, it makes sense to upload the data to the server because in that way you'll always have consistent data.所以您支持三个平台,是的,将数据上传到服务器是有意义的,因为这样您将始终拥有一致的数据。

It would be great to have a typo tolerance.有错字容忍度会很棒。 So for example typing "Bostn" or "Sen" (tolerance by one letter) "Boston" or "San …" should be displayed.因此,例如键入“Bostn”或“Sen”(一个字母的容差)“Boston”或“San ...”应显示。

That's nothing built-in Firestore that can help you with that. Firestore 内置的任何东西都无法帮助您解决这个问题。 What you can do, is to create an additional field of type array and search within it.您可以做的是创建一个数组类型的附加字段并在其中搜索。 So that array might have typos like that "Bostn" or "Bston".所以该数组可能有“Bostn”或“Bston”之类的拼写错误。

I will also have the possibility to have a facet filter so that I can filter before typing for one of the "State"s of the USA.我还将有可能拥有一个方面过滤器,以便我可以在输入美国“州”之一之前进行过滤。

That's also nothing already built-in Firestore, but you can implement for sure something like that.这也不是已经内置的 Firestore,但您可以肯定地实现类似的东西。 Most likely you might consider defining some filters and use them before typing.您很可能会考虑定义一些过滤器并在输入之前使用它们。

I am interested in a professional solution if this is available on the market, otherwise, I need to build it for myself.如果市场上有专业的解决方案,我对它感兴趣,否则,我需要为自己构建它。

For sure Firebase can help you achieve what you want, so I hope I was able to provide the best solutions for that. Firebase 肯定可以帮助您实现您想要的,所以我希望我能够为此提供最佳解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM