FTS3 中的多列匹配
我有一个包含三列的简单数据库:标题、数据、信息。我将它们存储在 SQLite FTS3 数据库中,以便我可以轻松执行全文搜索。我的应用程序基于 Android 的可搜索词典示例。我不知道该怎么做的一件事是如何跨两列搜索(匹配)。我基本上想接受查询并在标题和数据列中搜索它。以下是准备查询的方法:
public Cursor searchMatches(String query, String[] columns) {
String selection = KEY_TITLE + " MATCH ?";
String[] selectionArguements = new String[] {query + "*"};
return query(selection, selectionArguements, columns);
}
如果我不遵循精确的格式 KEY_TITLE + " MATCH ?"
进行选择,则其他任何方法都不起作用,尽管 FTS3 文档说其他方法可以工作。如何在 Android 中设置此选择以跨两列进行搜索?我尝试添加 OR
但只是出现 SQL 逻辑错误。多谢!
I have a simple database of three columns: title, data, info. I'm storing them in a SQLite FTS3 database so I can easily perform full-text searches. I've been basing my app off the Searchable Dictionary example from Android. The one thing I can't figure out how to do is how to search (match) across two columns. I basically want to take the query and search it in both the title and data columns. The following is the method that prepares the query:
public Cursor searchMatches(String query, String[] columns) {
String selection = KEY_TITLE + " MATCH ?";
String[] selectionArguements = new String[] {query + "*"};
return query(selection, selectionArguements, columns);
}
If I do not follow that exact format KEY_TITLE + " MATCH ?"
for the selection, nothing else will work despite the fact that the FTS3 document says other ways can work. How can set up this selection in Android to search across two columns? I've tried adding OR
but I simply get a SQL logic error. Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我找到了一个可行的解决方案,尽管它不是最漂亮的。它涉及使用
UNION
简单地组合两个MATCH
查询。Alright, I found a workable solution although it isn't the prettiest. It involves using
UNION
to simply combine twoMATCH
queries.您将必须编写自己的查询函数。您将希望您的查询看起来像这样:
您不能简单地将 or 添加到语句的 equals 部分(一个常见错误)。
You're going to have to write your own query function. You'll want your query to look something like:
You can't simply add an or to the equals part of the statement (a common mistake).
我就是这样做的
This is how I do it