Reputation: 219
Is there any sql method for querying consecutive texts from database?
For example I want to query just "koma azad" but the query method shows me "koma dengê azad", too.
Code:
public Cursor getmatches(String query, String[] columns) {
String selection = KEY_WORD + " MATCH ?";
String[] selectionArgs = new String[]{query};
return query(selection, selectionArgs, columns);
}
Upvotes: 1
Views: 52
Reputation: 219
public Cursor getmatchs(String query, String[] columns) {
String selection = KEY_WORD + " MATCH ?";
String[] selectionArgs = new String[]{query};
return query(selection, selectionArgs, columns);
}
Solution is adding double quotes:
public Cursor getmatchs(String query, String[] columns) {
String selection = KEY_WORD + " MATCH ?";
String[] selectionArgs = new String[]{"\""+query+"\""};
return query(selection, selectionArgs, columns);
}
}
Upvotes: 0
Reputation: 38595
You have to use double quotes if the match phrase has separators in it. If you were to inline the query text in the selection string, it looks like this:
String selection = KEY_WORD + " MATCH '\"" + query + "\"'";
I'm not sure if this will work with the ?
placeholder character, but you can try it and let us know.
Upvotes: 1