简体   繁体   中英

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. I have a list, for example in this way:

City Name State Counter Clicked More columns
Dallas Texas 4
Boston Massachusetts 3
New York City New York 1
San Francisco California 3
San Diego California 3
Seattle Washington 10
Boise Idaho 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.
  • The solution needs to work on iOS / Android devices and if possible also on a website.
  • Typing in "D" only "Dallas" should be displayed.
  • 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)
  • 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.
  • 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.
  • The filter service should be offline ready, so the "Counter Clicked" should be handled on the device. I am not quite sure if it makes sense to upload the data back to the Firebase backend server, what do you think?
  • 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.
  • 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.

You can achieve that using Firebase because:

Firebase is a platform developed by Google for creating mobile (iOS and Android) and web applications.

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 is a flexible, scalable database for mobile, web, and server development from Firebase and 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.

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.

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.

It will, as Firebase is a cross-platform solution.

Typing in "D" only "Dallas" should be displayed.

You can achieve that in a very simple way, by using Query's startAt() method:

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)

To solve this, you can use Query's orderBy(String field, Query.Direction direction) method:

Creates and returns a new Query that's additionally sorted by the specified field, optionally in descending order instead of ascending.

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.

Unfortunately, Firestore does not support full-text search. The official documentation regarding the full-text search in Cloud Firestore is up to date and stands for Algolia.

For Android, please see my answer from the following post:

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.

This can be very simply achieved using FieldValue.increment(1) as explained in my answer from the following post:

The filter service should be offline ready, so the "Counter Clicked" should be handled on the device. I am not quite sure if it makes sense to upload the data back to the Firebase backend server, what do you think?

According to the official documentation regarding Access data offline :

Cloud Firestore supports offline data persistence. For Android and iOS, offline persistence is enabled by default. For the web, offline persistence is disabled by default. To enable persistence, call the enablePersistence method.

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.

That's nothing built-in Firestore that can help you with that. 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".

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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