/node-sqlite3-okapi-bm25

Node module exposing a Okapi BM25 function extension for SQLite3's full text search

Primary LanguageJavaScriptMIT LicenseMIT

Okapi BM25 Full Text Search Ranking Function SQLite Extension

This NPM module is a simple repackaging of https://github.com/rads/sqlite-okapi-bm25 so that it can work out of the box with a simple npm install sqlite-okapi-bm25 instead of having to run the Makefile explicitly. The function is documented more explicitly in that repository.

This SQLite extension creates a SQL function called okapi_bm25 that returns the Okapi BM25 ranking for results of a full-text search. Okapi BM25 is a modern ranking function that calculates a score for each result based on its relevance to the search query. This extension only works with MATCH queries on FTS4 tables.

Usage

First, install the module via npm install sqlite3-okapi-bm25, then you can attach the extension to a sqlite connection.

var sqlite3 = require('sqlite3');

var db = new sqlite3.Database(':memory:')
require('sqlite3-fts4-rank')(db);

// Do stuff with the new rank UDF!
var sql = "SELECT docid, okapi_bm25(matchinfo(documents, 'pcnalx'), 0) AS rank " +
  "FROM documents " +
  "WHERE documents MATCH '\"serious mail\"' " +
  "ORDER BY rank DESC  " +
  " LIMIT 10 OFFSET 0;"
db.each(sql, function(err, row) {
  console.log(row.id + ": " + row.info);
});

See Also