How can I return a record based only on partial matching of this record?

I have done quite a bit of research on what, in my opinion, would be an easy question, but I cannot find what I am looking for. I'm just trying to return a post as a match only with a search term matching the portion of the text in the post.

For example, if a user searches for "ed," I would like any record containing "ed" to be returned. Therefore, if there is an entry in the name column with the name "Edward", it will be returned as a match. If the description had a β€œcompleted” entry, it would also return that entry to match.

I looked at the full-text search, but I'm not sure if this is what I will need to do, or if it even does what I need.

As always, I'm not looking for an answer, if I say, I'm just looking for a direction.

+3
source share
2 answers

SQLite has never been used before, but does it have a "LIKE" statement?

In MySQL, you can do something like:

SELECT name FROM list WHERE name LIKE '%ed%';
+9
source

Here is the code that will do what you want if you request a content provider. If you directly query the sqlite database object, 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 look for the content provider in urifor the ed line in column_name.

+1
source

All Articles