代码之家  ›  专栏  ›  技术社区  ›  Bqin1

Android Search Match 2列SQL语句

  •  0
  • Bqin1  · 技术社区  · 8 年前

    我正在学习Android SearchableDictionary教程 here 和代码 here

    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

    0 回复  |  直到 8 年前