I have a FTS3 table in Android SQLite database. Database is working fine. Now I want to search in table that has word column. Searching is also fine but the problem is when I search with a word the searched word is in the bottom or another position in the list. Suppose I want to search "GOOD" here I want the only "GOOD" will be in top of the list other will be bottom of the list.
Please see my code.
cursor = db.query("wordfts", new String[]{"id,word,mean"}, "wordfts" + " MATCH ?", new String[]{"*"+constraint.toUpperCase() + "*"}, null, null, "word", "5");
Sorry for my bad English
The 7th argument of the
query()method is theORDER BYclause of your statement.So with your code the results are simply sorted by the column
word.But if you want at the top the row(s) that match exactly your pattern, you must change it to:
So change your code to this:
Or better use
rawQuery()so you can use?placeholders to pass all parameters, including the one in theORDER BYclause, making your code safer: