匹配FTS表中的3个或更多值

时间:2013-09-26 17:20:53

标签: android sql sqlite match fts3

我有2个 FTS 表:搜索 search_eng 。我想从 search_eng 获取匹配字词的 entry_id 。然后我根据 entry_id 搜索中获取值。但是,当我尝试使用下面显示的方式时,它给出了错误: SQL逻辑错误。 这是因为 MATCH 超过2个值?如果不是我做错了什么?

//takes entry_id, g_value where matches word 
        query = "SELECT * FROM search_eng WHERE g_value MATCH '"
                + lookingFor + "' LIMIT 10";
        cursor = db.rawQuery(query, null);
        if (cursor.moveToFirst()) {
            //if cursor is not empty
            int num = 0;//counter for loop
            query = querySelectFromTableWhere;//"SELECT entry_id AS _id, re_value, ke_value, g_value, pos FROM search WHERE "
            do {
                if (num == 0) {
                    //for the first time
                    //query for getting all data of words which matches with entry_id which was got from search_eng
                    query = query
                            + " entry_id MATCH '"
                            + cursor.getString(cursor
                                    .getColumnIndex("entry_id"))+"'";
                } else {
                    //next tries: 2nd time, 3rd time...
                    //query for getting all data of words which matches with entry_id which was got from search_eng
                    query = query
                            + " OR entry_id MATCH '"
                            + cursor.getString(cursor
                                    .getColumnIndex("entry_id"))+"'";
                }
                num++;//plus counter
            } while (cursor.moveToNext());
            query=query+" LIMIT 10";
        }

堆栈跟踪:

  

09-26 21:48:14.937:E / AndroidRuntime(29495):致命异常:主要   09-26 21:48:14.937:E / AndroidRuntime(29495):   android.database.sqlite.SQLiteException:SQL逻辑错误或缺失   数据库09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.database.sqlite.SQLiteQuery.native_fill_window(原生方法)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:73)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:299)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:272)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.support.v4.widget.CursorAdapter.getCount(CursorAdapter.java:202)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.widget.ListView.setAdapter(ListView.java:489)09-26   21:48:14.937:E / AndroidRuntime(29495):at   com.joericharduz.akita.MainActivity.displayListView(MainActivity.java:147)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   com.joericharduz.akita.MainActivity.access $ 0(MainActivity.java:136)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   com.joericharduz.akita.MainActivity $ 1.onTextChanged(MainActivity.java:122)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.widget.TextView.sendOnTextChanged(TextView.java:6603)09-26   21:48:14.937:E / AndroidRuntime(29495):at   android.widget.TextView.handleTextChanged(TextView.java:6650)09-26   21:48:14.937:E / AndroidRuntime(29495):at   android.widget.TextView $ ChangeWatcher.onTextChanged(TextView.java:6794)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:889)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:352)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:269)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:432)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:409)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:28)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:654)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:180)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:120)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:283)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   com.android.internal.view.IInputConnectionWrapper $ MyHandler.handleMessage(IInputConnectionWrapper.java:79)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   android.os.Handler.dispatchMessage(Handler.java:99)09-26   21:48:14.937:E / AndroidRuntime(29495):at   android.os.Looper.loop(Looper.java:130)09-26 21:48:14.937:   E / AndroidRuntime(29495):at   android.app.ActivityThread.main(ActivityThread.java:3687)09-26   21:48:14.937:E / AndroidRuntime(29495):at   java.lang.reflect.Method.invokeNative(Native Method)09-26   21:48:14.937:E / AndroidRuntime(29495):at   java.lang.reflect.Method.invoke(Method.java:507)09-26 21:48:14.937:   E / AndroidRuntime(29495):at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)   09-26 21:48:14.937:E / AndroidRuntime(29495):at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)09-26   21:48:14.937:E / AndroidRuntime(29495):at   dalvik.system.NativeStart.main(原生方法)

1 个答案:

答案 0 :(得分:0)

请参阅sqlite文档here

要匹配多个字词,您必须在字词之间添加OR,而不是MATCH es。类似的东西:

SELECT entry_id AS _id, re_value, ke_value, g_value, pos
FROM search
WHERE entry_id MATCH 'firstWord OR secondWord`

是的,或者在''内。