I've done quite a bit of research on what I thought would be an easy question but I cannot find what I am looking for. I am simply trying to return a record as a match with only a search term matching part of the text in the record.
For example, if the user searches for "ed" I would like any record that contains "ed" to be returned. So if there was a record with the name "Edward" in the name column it would be returned as a match. If there was a record with "finished" in the description, it would also return that record as a match.
I have looked into full text search but not sure if this is something that I would need to do or if it would even do what I need.
As always, I'm not looking for an answer per say, I'm just looking for a direction.
Never used SQLite before, but does it have the "LIKE" operator?
In MySQL, you can do something like:
SELECT name FROM list WHERE name LIKE '%ed%';
Here is some code that will do what you want if you are querying a content provider. If you are querying a sqlite database object directly, the parameters are similar but different.
String search = "ed";
// surround it with the SQL wildcard '%'
String q = "%" + search + "%"
Cursor c = getContentResolver().query(uri,
new String[] { column1, column2 },
"column_name like ?",
new String[] { q },
null);
The snippet will search the content provider at uri
for the string ed in column_name
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With