【问题标题】:dart: get SQL like "%text%" search from firebase database snapshotdart:从 firebase 数据库快照中获取类似“%text%”的 SQL 搜索
【发布时间】:2019-05-18 21:05:21
【问题描述】:

我目前正在我的应用程序中开发搜索功能。这获得了我的 firebase 数据库快照的参考。我为此使用了 firebaseDatabase 包。

目前我正在使用它来搜索我的数据库

FirebaseDatabase.instance.reference().child('products').orderByChild('title').equalTo(searchQuery)

searchQuery 变量是用于搜索数据库的字符串。这将返回标题等于 searchQuery 的产品列表。

searchQuery = 'hello';
title1 = 'hello';
title2 = 'hello there';

暂时只有

searchQuery == title1;
searchQuery != title2;

但我也希望将其退回

searchQuery == title2;

我现在使用的方式有可能吗?

【问题讨论】:

    标签: android string dart flutter


    【解决方案1】:

    您正在寻找 contains 查询,但 Firebase 不提供该查询。您可以通过查找 equalToendAtstartAt 的值来优化您的实际查询(您也可以使用这些方法)。但是,提出三个请求将是昂贵的。

    如果您的数据库不大并且您的数据不敏感,我建议获取整个数据并制作一个客户端过滤器,如图所示here

    【讨论】:

    • 我看到像 .equalsTo(query + "\nf8ff" 这样的查询将返回查询文本之后的所有内容。所以查询 "hello"+"\nf8ff" 也将返回 "hello there" . 所以我认为 "\nf8ff" + "there"+ "\nf8ff" 也会返回 "hello there" 但事实并非如此。我不知道为什么没有实现这样的基本查询:(
    • 你在哪里看到的?
    • stackoverflow.com/questions/46460825/… 我找到了多个使用这种方法的帖子。问题是您只能查询“abc%”而不是“%abc%”:/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    • 2018-07-10
    相关资源
    最近更新 更多