0

我有 2 个FTS表:searchsearch_eng。我正在尝试从search_eng获取匹配词的entry_id。然后我根据这些entry_id从搜索中获取值。但是当我尝试以下面显示的方式实现它时,它给出了错误:SQL logic error。这是因为MATCH ing 超过 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): 致命异常: main 09-26 21:48:14.937: E/AndroidRuntime(29495): android.database.sqlite.SQLiteException: SQL 逻辑错误或缺少数据库09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.database.sqlite.SQLiteQuery.native_fill_window(Native Method) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.database .sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:73) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:299) 09-26 21 :48:14.937: E/AndroidRuntime(29495): 在 android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:272) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.support。 v4.widget.CursorAdapter.getCount(CursorAdapter.java:202) 09-26 21:48:14.937: E/AndroidRuntime(29495):在 android.widget.ListView.setAdapter(ListView.java:489) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 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): 在 android.widget.TextView.sendOnTextChanged(TextView.java:6603) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.widget.TextView.handleTextChanged(TextView.java:6650) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.widget.TextView $ChangeWatcher.onTextChanged(TextView.java:6794) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:889) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:352) 09-26 21:48: 14.937: E/AndroidRuntime(29495): 在 android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:269) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.text.SpannableStringBuilder.replace(SpannableStringBuilder .java:432) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:409) 09-26 21:48:14.937: E/AndroidRuntime(29495 ): 在 android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:28) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:654) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:180) 09-26 21:48:14.937: E/AndroidRuntime(29495) : 在 com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:120) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper .java:283) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:79) 09-26 21:48:14.937 : E/AndroidRuntime(29495): 在 android.os.Handler.dispatchMessage(Handler.java:99) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 android.os.Looper.loop(Looper. java:130) 09-26 21:48:14.937: E/AndroidRuntime(29495):在 android.app.ActivityThread.main(ActivityThread.java:3687) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 java.lang.reflect.Method.invokeNative(Native Method) 09-26 21: 48:14.937: E/AndroidRuntime(29495): 在 java.lang.reflect.Method.invoke(Method.java:507) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 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(Native Method)reflect.Method.invoke(Method.java:507) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 09 -26 21:48:14.937: E/AndroidRuntime(29495): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 09-26 21:48:14.937: E/AndroidRuntime(29495):在 dalvik.system.NativeStart.main(本机方法)reflect.Method.invoke(Method.java:507) 09-26 21:48:14.937: E/AndroidRuntime(29495): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 09 -26 21:48:14.937: E/AndroidRuntime(29495): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 09-26 21:48:14.937: E/AndroidRuntime(29495):在 dalvik.system.NativeStart.main(本机方法)

4

1 回答 1

0

请参阅此处sqlite的文档。

要匹配多个单词,您必须OR在单词之间添加,而不是MATCHes。就像是:

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

是的,OR 在里面''

于 2013-10-02T16:34:20.033 回答