Firebase“喜欢”搜索字符串[重复]

问题描述 投票:0回答:1

我正在尝试根据名称搜索用户。如果名称是从第一个名称给出的,但没有在字符串上搜索第二个名称,那么它会完美搜索。例如,第一个和第二个都保存在一个由空格分隔的值中 “约翰·史密斯”。如果搜索“john”或“jo”等,它将检索记录,但如果搜索 smith,则不会检索到任何内容。 代码

 var ref = firebase.database().ref().child('User').orderByChild("name").startAt(searchString).endAt(searchString + "\uf8ff");
    $scope.usercollection = $firebaseArray(ref);
firebase firebase-realtime-database angularfire
1个回答
4
投票

对于您的查询,通常您只会得到以 j、jo、joh、john 等开头的结果... startAt 方法“创建具有指定起点的查询”。所以它会查看你的 searchString 变量starts如何。

Firebse 目前没有全文搜索机制。您会在网上找到实现这种机制的几种可能性,例如:

https://firebase.googleblog.com/2014/01/queries-part-2-advanced-searches-with.html

https://github.com/FirebaseExtended/flashlight

© www.soinside.com 2019 - 2024. All rights reserved.