来自sqlite fts3 unionQuery的不正确和重复的结果

时间:2012-12-31 17:14:54

标签: sqlite fts3

我从我的rawQuery获得的结果是复制并遵循OR逻辑而不是AND逻辑,即我将获得包含“tuxedo”的所有条目以及包含“hotel”的所有条目想要包含两者的那些。

这是我的方法:

public ArrayList<Integer> getAdvancedResultIDList(String[] search)
{
    ArrayList<String> queryList = new ArrayList<String>();
    ArrayList<Integer> resultsList = new ArrayList<Integer>();
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    this.mDB = GamesList.mDBHelper.getDatabase();
    Cursor searchCursor = null;
    try
    {
        //TODO:
        // for each string in the search array search the whole of searchable table. Check that the results are only of the values that 
        // contain all the search strings, and add the id of that row to the results ArrayList
        for(int i = 0; i < search.length; i++)
        {
            String query;
            String s = '"' + search[i] + '"';
            query = "SELECT " + KEY_ID + " FROM "+ SEARCHABLE_TABLE + " WHERE " + SEARCHABLE_TABLE + " MATCH " + s;
            queryList.add(query);
        }

        String[] queryArray = queryList.toArray(new String[queryList.size()]);


        String unionQuery = builder.buildUnionQuery(queryArray, KEY_ID + " ASC", null);

        searchCursor = this.mDB.rawQuery(unionQuery, null);

        int colId = searchCursor.getColumnIndex(KEY_ID);

        String resultID;

        for(searchCursor.moveToFirst(); !searchCursor.isAfterLast();searchCursor.moveToNext())
        {
            resultID = searchCursor.getString(colId);
            Integer Id = Integer.parseInt(searchCursor.getString(colId));
            resultsList.add(Id);

        }
        searchCursor.close();

    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        try
        {
            this.mDB.close();

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    return resultsList;
}

提前致谢,新年快乐!

1 个答案:

答案 0 :(得分:0)

documentation解释了如何使用多个搜索字词:

SELECT id FROM searchTable WHERE searchTable MATCH 'tuxedo hotel'