What I'm trying to accomplish: custom search in Android that can look across multiple columns for suggestions to the user.
I can map a single column "Topics" to the system-specified SUGGEST_COLUMN_TEXT_1
, and that works wonderfully, I even have it grouping topics to remove duplicate entries.
However, what I'd like is to include "Author First Name || ' ' || Author Last Name" (concat these two for a single row entry) and "Author Group Name" into that single SUGGEST_COLUMN_TEXT_1 (and then figure out how to group by any duplicate I guess?).
I've thought about using a HashMap, but the query builder calls for a single String, so I'm not sure if that would work.
Is this possible? No. I'm certain it is. Any ideas? Perhaps a Union? I've commented out some of the code below that doesn't seem to work.
private static final HashMap<String, String> SEARCH_PROJECTION_MAP;
static {
SEARCH_PROJECTION_MAP = new HashMap<String, String>();
SEARCH_PROJECTION_MAP.put("_id", "_id");
SEARCH_PROJECTION_MAP.put(SearchManager.SUGGEST_COLUMN_TEXT_1,
ExternalDbContract.QuoteEntry.TOPIC
// + " OR \"" + ExternalDbContract.QuoteEntry.AUTHOR_FIRST_NAME
// + "\" || \' \' || \"" + ExternalDbContract.QuoteEntry.AUTHOR_LAST_NAME
// + "\" OR \"" + ExternalDbContract.QuoteEntry.AUTHOR_GROUP_NAME
+ "\" AS "
+ SearchManager.SUGGEST_COLUMN_TEXT_1);
}
As far as raw SQL goes, I think this is what I'm trying to accomplish:
"SELECT Topic FROM quotes WHERE Topic LIKE " + selectionArgs[0] +
"UNION SELECT \"Author First Name\" || ' ' || \"Author Last Name\" FROM quotes WHERE \"Author First Name\" LIKE " + selectionArgs[0] + " OR " + "\"Author Last Name\" LIKE " + selectionArgs[0] +
"UNION SELECT \"Author Group Name\" FROM quotes WHERE \"Author Group Name\" LIKE " + selectionArgs[0] +
"ORDER BY ASC LIMIT 10";
How might I accomplish this with Android's custom suggestions format?