sqlite_bm25 0.2.0

SQLite BM25 #

An Okapi BM25 implementation for the SQLite FTS4 (full-text search) extension.

Example #

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();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  sqlite_bm25: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:sqlite_bm25/sqlite_bm25.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
19
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
64
Overall:
Weighted score of the above. [more]
52
Learn more about scoring.

We analyzed this package on Aug 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:sqlite_bm25/sqlite_bm25.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and sqlite_bm25.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

The package description is too short. (-1 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
convert ^2.1.1
test ^1.6.3