使用部分字符串匹配进行Firebase查询 [英] Firebase querying with partial string match

查看:84
本文介绍了使用部分字符串匹配进行Firebase查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个简单的firebase实时数据库结构,其中的键为username,值为userid.现在,我要按username搜索userid.如果用户名匹配,这是非常容易的.但是如何获得部分匹配的答案.更明确的是,如果我要使用SQL编写此代码,将类似于:

Suppose I have a simple firebase realtime database structure where the key is username and the value is userid. Now I want to search userid by username. It is quite easy if the username matches. but how to get the answer for partial match. To be more clear if i were to write this using SQL it would be something like:

SELECT userid FROM tablename WHERE username LIKE 'abc%'

SELECT userid FROM tablename WHERE username LIKE 'abc%'

它将为我提供所有userid,其中usernameabc开头. 如何编写此类针对Firebase的查询?了解我在android设备上使用它,并且可能有很多用户.

it will give me all the userid where the username starts with abc. How to write this type of query for firebase? Understand i am using this on a android device and there can be a lot of user.

推荐答案

根据Java Admin的文档,您可以执行类似的操作,它也应与Android一起使用

According to the doc of Java Admin you can do something like this it should also work with Android

对于以abc开头的数据,

yourRef.orderByKey().startAt("abc").endAt("abc\uf8ff")

\ uf8ff在Unicode中大多数常规字符之后,因此查询应匹配以abc开头的所有值.

The \uf8ff is after most regular characters in Unicode, so the query should matches all values that start with a abc.

这篇关于使用部分字符串匹配进行Firebase查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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