-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
android 如何自行加载扩展? #1
Comments
看demo 是针对 Flutter 的,如果我集成 sqlite-android 后,如何在使用时将 Simple 分词器 与 sqlite-android 支持FTS 5 关联在一起呢?在C++ native侧建立连接吗? |
原理和 https://github.com/SageMik/sqlite3_simple/blob/master/lib/src/sqlite3_simple.dart 加载扩展差不多,只要 Android 这边找到等价于 以 sqlite-android 为例,在引入 sqlite-android 和 simple-native-android 依赖后,通过前者提供的方法加载自定义扩展: private fun createSQLiteOpenHelper(): SupportSQLiteOpenHelper {
val extensionConfigs = mutableListOf(
RequerySQLiteOpenHelperFactory.ConfigurationOptions {
it.apply {
customExtensions.add(
SQLiteCustomExtension("libsimple.so", "sqlite3_simple_init") // 加载 Simple 扩展
)
}
}
)
return RequerySQLiteOpenHelperFactory(extensionConfigs).create(
SupportSQLiteOpenHelper.Configuration(
this, ":memory:", object : SupportSQLiteOpenHelper.Callback(1) {
override fun onCreate(db: SupportSQLiteDatabase) {
db.execSQL(
"CREATE VIRTUAL TABLE t1 USING fts5(text, tokenize = 'simple');" +
"INSERT INTO t1 VALUES ('中华人民共和国国歌');"
)
}
override fun onUpgrade(
db: SupportSQLiteDatabase,
oldVersion: Int,
newVersion: Int
) {}
}
)
)
} 然后在需要的地方进行查询即可: val dbHelper = createSQLiteOpenHelper()
val db = dbHelper.writableDatabase
val result = db.query("SELECT simple_highlight(t1, 0, '[', ']') FROM t1 WHERE text MATCH simple_query('中华国歌');")
result.moveToFirst()
println(result.getString(0)) // 打印结果:[中华]人民共和[国国歌] 如果需要结巴分词,同样要像 Flutter 这边将 字典文件 保存到可以访问的位置,然后参照 Simple 的说明 通过 |
Ok, 感谢 试了一下是可以的。 |
@Edison0716 看报错似乎是没有加载字典文件,这个需要按我前面所说的,可以参考 |
ok, 我理解 WCDB 的库 也是可以用我们的simple分词器吧 |
@Edison0716 我粗略地看了一下 WCDB ,不确定是否能用,你可以询问一下原作者:Simple |
No description provided.
The text was updated successfully, but these errors were encountered: