Android搜索匹配2列SQL语句

时间:2018-06-25 20:58:17

标签: android sql sqlite search

我正在遵循Android SearchableDictionary教程here和代码here,可以使所有工作正常进行,并理解代码。但是,我一生无法在可搜索的sqliteDB的2列中进行搜索。有关我要完成的操作,请参见下面的评论

public Cursor getWordMatches(String query, String[] columns) {
        //This (original code) searches your query in the KEY_WORD column, which is the SUGGEST_COLUMN_TEXT_1 column.
        //String selection = KEY_WORD + " MATCH ?";

        // This searches your query across ALL columns of the table, not what I want because I have added additional columns to the sqlitedb table
        //String selection = FTS_VIRTUAL_TABLE + " MATCH ?";

        // This is what I want, to search my query in both the keyword and keydefinition columns, which is the 1 and 2 suggest column text
        String selection = KEY_WORD +"OR" + KEY_DEFINITION+ " MATCH ?";
        String[] selectionArgs = new String[] {query+"*"};

        return query(selection, selectionArgs, columns);

        /* This builds a query that looks like:
         *     SELECT <columns> FROM <table> WHERE <KEY_WORD> MATCH 'query*'
         * which is an FTS3 search for the query text (plus a wildcard) inside the word column.

我尝试过的东西(还有更多,但是它们是对以下格式的微小修改):

String selection = KEY_WORD +"OR" + KEY_DEFINITION+ " MATCH ?";

String selection = FTS_VIRTUAL_TABLE+ " MATCH 'suggest_text_1:? OR suggest_text_2:?'";

我也阅读了this的相关部分,对我没有帮助,因为它再次给出了在1列中搜索并使用隐藏的db named列在所有列中搜索的示例。我需要在单个SQL语句中搜索1个以上的列。

0 个答案:

没有答案