Hy everyone..!!


I am using FTS(full-text-search) mechanisam to search a word from table.

Problem i am facing is that it is unable to search exact word  from table may be due to my poor logic.
If i write M* then it returns true.
But if i search Meet it return false even though Meet exists in table.

Please suggest where i change in code  to search exact word from table...??

Code...


public class DatabaseTable {

    private static final String TAG = "DictionaryDatabase";

    //The columns we'll include in the dictionary table
    public static final String COL_WORD = "WORD";
    
    private static final String DATABASE_NAME = "DICTIONARY";
    private static final String FTS_VIRTUAL_TABLE = "FTS";
    private static final int DATABASE_VERSION = 1;

    private final DatabaseOpenHelper mDatabaseOpenHelper;

    DatabaseTable(Context context) {
        mDatabaseOpenHelper = new DatabaseOpenHelper(context);
    }

    public static class DatabaseOpenHelper extends SQLiteOpenHelper {

        private final Context mHelperContext;
        private SQLiteDatabase mDatabase;

        private static final String FTS_TABLE_CREATE =
                    "CREATE VIRTUAL TABLE " + FTS_VIRTUAL_TABLE +
                    " USING fts3 (" +
                    COL_WORD + ")";
        @Override
        public void onCreate(SQLiteDatabase db) {        
            mDatabase = db;
            mDatabase.execSQL(FTS_TABLE_CREATE);
            loadDictionary();

        }

        DatabaseOpenHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            mHelperContext = context;
            SQLiteDatabase obj;
            obj=getReadableDatabase();
            
          
        }

      

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS " + FTS_VIRTUAL_TABLE);
            onCreate(db);
        }
        private void loadDictionary() {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        loadWords();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            }).start();
        }

    private void loadWords() throws IOException {
        final Resources resources = mHelperContext.getResources();
        InputStream inputStream = resources.openRawResource(R.raw.data);
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

        try {
            String line;
            while ((line = reader.readLine()) != null) {                    
                long id = addWord(line);
                }
            }
        } finally {
            reader.close();
        }
    }

    public long addWord(String word) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(COL_WORD, word);   
        return mDatabase.insert(FTS_VIRTUAL_TABLE, null, initialValues);
    }
    }

// input is word that i want to check in database
   /* public Cursor getWordMatches(String input, String columns) {
        String selection = COL_WORD + " MATCH ?";
        String[] selectionArgs = new String[] {input};

        return query(selection, selectionArgs, columns);
    }

    private boolean query(String selection, String[] selectionArgs, String[] columns) {
        SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
        builder.setTables(FTS_VIRTUAL_TABLE);

        Cursor cursor = builder.query(mDatabaseOpenHelper.getReadableDatabase(),
                columns, selection, selectionArgs, null, null, null);

        if (cursor == null) {
            return false;
        } else if (!cursor.moveToFirst()) {
            cursor.close();
            return false;
        }
        return true;
    }
}