NSPredicate predicateWithFormat“OR”有问题

发布于 2024-11-16 02:52:58 字数 516 浏览 3 评论 0原文

我正在尝试使用 NSPredicate 从 coredata 获取实体。我正在尝试采用“边输入边搜索”的方法。它适用于简单的产品名称,例如“椅子”或“桌子”。

但是,一旦我尝试了更复杂的东西,例如“轮椅 - 电动 - 电源”,那么当我输入“轮椅电动”时,结果就没有显示。我认为这与我的 NSPredicate predicateWithFormat 有关,但我已经这样做了一段时间了。所以我需要一些帮助。

这是我的代码(这些是我最好的猜测)

    request.predicate = [NSPredicate predicateWithFormat:@" Name BEGINSWITH [c] %@ ",searchText];
    request.predicate = [NSPredicate predicateWithFormat:@" Name BEGINSWITH [c] %@ OR Name like[cd] %@ ",searchText,searchText];  

提前致谢:) 池塘

I am trying to fetch an entity from coredata using NSPredicate. I am trying to do a 'search as you type' approach. It works fine on a simple product name like "chair" or "Table".

But as soon as I tried the more complicate stuff like "Wheelchair - electric - power" then when I type in "Wheelchair electric" the result is not showing. I think it has to do with my NSPredicate predicateWithFormat but I've been at this for awhile now. So I need some help.

Here is my code (these are my best guesses)

    request.predicate = [NSPredicate predicateWithFormat:@" Name BEGINSWITH [c] %@ ",searchText];
    request.predicate = [NSPredicate predicateWithFormat:@" Name BEGINSWITH [c] %@ OR Name like[cd] %@ ",searchText,searchText];  

Thanks in advance :)
Pondd

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦过后 2024-11-23 02:52:58

要进行 OR 搜索,您必须首先将搜索词按空格分割到一个数组中。然后,您需要为每个单独的组件创建一个 LIKE 谓词。最后,您必须将各个谓词与多个 OR 复合谓词组合起来。

To have an OR search you will have to first split the search term by whitespace into an array. Then you need to create a LIKE predicate for each individual component. Finally you have to combine the individual predicates with several OR compound predicates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文