gpt4 book ai didi

android - SQLite中查找相似字符串的方法

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:38:33 26 4
gpt4 key购买 nike

<分区>

我想在表“TABLE_TOURS”中搜索“COLUMN_TITLE”列中与“query”相似的词,并返回一个列表“List”。请帮助我

public List<Tour> getWordMatches(String query, String[] columns) {
String selection = ToursDBOpenHelper.COLUMN_TITLE + " MATCH ?";
String[] selectionArgs = new String[] {query+"*"};
return query(selection, selectionArgs, columns);
}
public List<Tour> query(String selection, String[] selectionArgs, String[] columns) {
Log.i(LOGTAG, "getwordsmatches result"+ selection +" "+ selectionArgs);
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables(ToursDBOpenHelper.TABLE_TOURS);

Cursor cursor = builder.query(dbhelper.getReadableDatabase(),
columns, selection, selectionArgs, null, null, null);
Log.i(LOGTAG, "cursor of db result "+ cursor);
List<Tour> tours = cursorToList(cursor);
Log.i(LOGTAG, "tours are "+ tours);
if (cursor == null) {
return null;
} else if (!cursor.moveToFirst()) {
cursor.close();
return null;
}
return tours;
}

及其 cursorToList 方法:

private List<Tour> cursorToList(Cursor cursor) {
List<Tour> tours = new ArrayList<Tour>();
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
Tour tour = new Tour();
tour.setId(cursor.getLong(cursor.getColumnIndex(ToursDBOpenHelper.COLUMN_ID)));
tour.setTitle(cursor.getString(cursor.getColumnIndex(ToursDBOpenHelper.COLUMN_TITLE)));
tour.setCate(cursor.getString(cursor.getColumnIndex(ToursDBOpenHelper.COLUMN_CATE)));
tour.setDetail(cursor.getString(cursor.getColumnIndex(ToursDBOpenHelper.COLUMN_DETAIL)));
tour.setDescription(cursor.getString(cursor.getColumnIndex(ToursDBOpenHelper.COLUMN_DESC)));
tour.setImage(cursor.getString(cursor.getColumnIndex(ToursDBOpenHelper.COLUMN_IMAGE)));
tours.add(tour);
}
}
return tours;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com