我有一个带有名为kanji的表的sqlite数据库,其中有一个名为english_meaning的列。我想查询“单词”。
这是我现有的查询和代码:
public Cursor fetchAllKanjiWithQuery(String input) {
input = "%" + input + "%";
String query = "SELECT * FROM kanji WHERE literal LIKE ? OR radicals LIKE ? OR english_meaning LIKE ? OR kun_reading LIKE ? OR romaji LIKE ? ORDER BY stroke_count";
String[] selectionArgs = new String[]{input, input, input, input, input};
Cursor cursor = db.rawQuery(query, selectionArgs);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
如果输入为“one”,则english_meaning为“b one ”或“ one self”的结果将匹配。
但是,我只对带有“one”一词的字符串感兴趣。例如,有效匹配应包括:
即,“one”可以出现在字符串的开头或结尾,它通过空格与其他字符分开。如果可能,还应允许“one”后跟标点符号,如“,”和“。”。
目前,我使用LIKE和%input%的查询未提供所需的结果。如何解决这个问题?
答案 0 :(得分:0)
为什么不这样做:
SELECT *
from kanji
where (english_meaning = 'one'
or english_meaning = 'one.'
or english_meaning = 'one,'
or english_meaning like 'one %'
or english_meaning like '% one %'
or english_meaning like '% one'
or english_meaning like '% one.'
or english_meaning like '% one,')