Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/silas/dart-sqlite-bm25
BM25 implementation for the SQLite FTS4 extension
https://github.com/silas/dart-sqlite-bm25
Last synced: 21 days ago
JSON representation
BM25 implementation for the SQLite FTS4 extension
- Host: GitHub
- URL: https://github.com/silas/dart-sqlite-bm25
- Owner: silas
- License: mit
- Created: 2019-05-18T22:26:41.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-26T05:30:46.000Z (almost 2 years ago)
- Last Synced: 2024-10-10T14:28:31.279Z (about 1 month ago)
- Language: Dart
- Homepage: https://pub.dev/packages/sqlite_bm25
- Size: 8.79 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SQLite BM25
An [Okapi BM25][bm25] implementation for the SQLite [FTS4][fts4]
(full-text search) extension.## Example
``` dart
import 'package:sqflite/sqflite.dart';
import 'package:sqlite_bm25/sqlite_bm25.dart';example() async {
final table = 'bm25_test';final db = await openDatabase(':memory:', version: 1,
onCreate: (Database db, int version) async {
await db.execute('CREATE VIRTUAL TABLE $table USING fts4(name)');
});await db.insert(table, {'rowid': 1, 'name': 'Sam Rivers'});
await db.insert(table, {'rowid': 2, 'name': 'Samwise "Sam" Gamgee'});
await db.insert(table, {'rowid': 3, 'name': 'Sam'});
await db.insert(table, {'rowid': 4, 'name': 'Sam Seaborn'});
await db.insert(table, {'rowid': 5, 'name': 'Samwell "Sam" Tarly'});var rows = await db.query(
table,
columns: [
'name',
'matchinfo($table, \'$bm25FormatString\') as info',
],
where: '$table MATCH ?',
whereArgs: ['sam'],
);rows = rows.map((row) {
return {
'name': row['name'],
'rank': bm25(row['info']),
};
}).toList();rows.sort((a, b) => a['rank'].compareTo(b['rank']));
final names = rows.take(3).map((r) => r['name']).join(', ');
print(names);
await db.close();
}
```[bm25]: https://en.wikipedia.org/wiki/Okapi_BM25
[fts4]: https://www.sqlite.org/fts3.html