Estoy siguiendo el ejemplo de Google Storing and Searching for Data
como buscar en una base de datos y devolver los resultados de un viewSearch, todo me funciona perfectamente, pero solo busca en una columna COL_WORD
public Cursor getWordMatches(String queryStr, String[] columns) {
String selection = "" + COL_WORD + " MATCH ? ";
String[] selectionArgs = new String[] { queryStr + "*," };
return query(selection, selectionArgs, columns);
}
private Cursor query(String selection, String[] selectionArgs, String[] columns) {
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables(FTS_VIRTUAL_TABLE);
Cursor cursor = builder.query(mDatabaseOpenHelper.getReadableDatabase(),
columns, selection, selectionArgs, null, null, null);
if (cursor == null) {
return null;
} else if (!cursor.moveToFirst()) {
cursor.close();
return null;
}
return cursor;
}
Me gustaría adaptar el código que buscará dentro de los campos COL_WORD
y COL_DEFINITION
con condición OR
, es decir que si la palabra a buscar se encuentra en un campo o otro o bien ambos, devuelve resultado.
Estoy mirando la documentación de sqlite, me parece que la solución recae aquí, pero no tengo suficientes conocimientos para trasladarlo a objeto SQLiteQueryBuilder
-- Query the database for documents for which the term "linux" appears in -- the document title, and the term "problems" appears in either the title -- or body of the document. SELECT * FROM docs WHERE docs MATCH 'title:linux problems';
-- Query the database for documents for which the term "linux" appears in -- the document title, and the term "driver" appears in the body of the document -- ("driver" may also appear in the title, but this alone will not satisfy the. -- query criteria). SELECT * FROM docs WHERE body MATCH 'title:linux driver';