我正在写一本字典应用程序。我有一个大的静态SQLite数据库,其中包含一个表(100k +行)和一个»_id«,»word«和»description«列。条目按字典顺序排列为“word”。我使用下面的代码和afterTextChanged(可编辑的searchText)在数据库中进行即时搜索,将选择的行加载到ArrayList中,然后从那里加载到列表适配器。 但是,代码有效,它不是很有效,即:
我是否有办法优化这些属性?是否有现成的词典解决方案?对不起,我是新来的。
我可以用»> =«替换»LIKE«,因为单词也包含一些非ASCII字符,而»> =«查询不适用于它们。
//---retrieves a database subset in the range (MATCH-RowsBefore, MATCH+RowsAfter)---
public Cursor getSearch(Editable typedKeys) throws SQLException
{
Cursor sCursor =
db.rawQuery("SELECT _id, word FROM dict WHERE word LIKE ? LIMIT 1",
new String[]{typedKeys + "%"});
if (sCursor.moveToFirst()) {
SearchedRow = Integer.parseInt(sCursor.getString(0));
int newstart = SearchedRow - RowsBefore;
String curlen = Integer.toString(RowsBefore + RowsAfter + 1);
sCursor = db.query(true, DB_TABLE, new String[] {_id,
word}, _id + ">=" + newstart, null, null, null, null, curlen);
}
return sCursor;
}