All Projects → rads → sqlite-okapi-bm25

rads / sqlite-okapi-bm25

Licence: MIT License
📑 SQLite extension to add the Okapi BM25 ranking algorithm

Programming Languages

c
50402 projects - #5 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sqlite-okapi-bm25

gorest
Go RESTful API starter kit with Gin, JWT, GORM (MySQL, PostgreSQL, SQLite), Redis, Mongo, 2FA, email verification, password recovery
Stars: ✭ 135 (+350%)
Mutual labels:  sqlite3, mit-license
react-native-quick-sqlite
Fast SQLite for react-native.
Stars: ✭ 239 (+696.67%)
Mutual labels:  sqlite, sqlite3
LoginToASqlite3DatabaseWithoutCredentialsWithAdminer
✔️ An Adminer plugin to use SQLite databases without credentials (no username and no password)
Stars: ✭ 30 (+0%)
Mutual labels:  sqlite, sqlite3
VVSequelize
数据库模型映射,自动建表, 自动更新表,数据增删改查, FTS全文搜索, 支持自定义fts3,4,5分词器,可拼音分词. sql,fmdb,wcdb,sqlite3,orm,fts,fts3,fts4,fts5
Stars: ✭ 16 (-46.67%)
Mutual labels:  sqlite, sqlite3
sqlite zstd vfs
SQLite3 extension for read/write storage compression with Zstandard
Stars: ✭ 42 (+40%)
Mutual labels:  sqlite, sqlite3
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+12813.33%)
Mutual labels:  sqlite, sqlite3
nim-gatabase
Connection-Pooling Compile-Time ORM for Nim
Stars: ✭ 103 (+243.33%)
Mutual labels:  sqlite, sqlite3
Pydbgen
Random dataframe and database table generator
Stars: ✭ 191 (+536.67%)
Mutual labels:  sqlite, sqlite3
PokeChat
UNIX compatible, Discord and Telegram inspired, Pokémon-themed instant messaging service.
Stars: ✭ 11 (-63.33%)
Mutual labels:  sqlite, sqlite3
selekt
A Kotlin and Android wrapper over SQLCipher, providing 256-bit AES encryption of database files.
Stars: ✭ 26 (-13.33%)
Mutual labels:  sqlite, sqlite3
Sqleet
SQLite3 encryption that sucks less
Stars: ✭ 244 (+713.33%)
Mutual labels:  sqlite, sqlite3
mdb2sqlite
Conversion tool used to convert microsoft access database to sqlite.
Stars: ✭ 79 (+163.33%)
Mutual labels:  sqlite, sqlite3
React Native Sqlite 2
SQLite3 Native Plugin for React Native for iOS, Android, Windows and macOS.
Stars: ✭ 217 (+623.33%)
Mutual labels:  sqlite, sqlite3
Scout
RESTful search server written in Python, powered by SQLite.
Stars: ✭ 213 (+610%)
Mutual labels:  search, sqlite
Better Sqlite3
The fastest and simplest library for SQLite3 in Node.js.
Stars: ✭ 2,778 (+9160%)
Mutual labels:  sqlite, sqlite3
go-sqlite
Low-level Go interface to SQLite 3
Stars: ✭ 268 (+793.33%)
Mutual labels:  sqlite, sqlite3
Sqlittle
Pure Go SQLite file reader
Stars: ✭ 171 (+470%)
Mutual labels:  sqlite, sqlite3
Choochoo
Training Diary
Stars: ✭ 186 (+520%)
Mutual labels:  sqlite, sqlite3
python-sqlite3-backup
Sqlite3 online API CPython implementation module
Stars: ✭ 44 (+46.67%)
Mutual labels:  sqlite, sqlite3
lighthouse
Easy clojure relational database queries, migrations and connection pooling
Stars: ✭ 19 (-36.67%)
Mutual labels:  sqlite, sqlite3

Okapi BM25 for SQLite3

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.

Installation

The extension must first be compiled from the source:

$ make
gcc -Wall -Werror -bundle -fPIC -Isqlite3 -o okapi_bm25.sqlext okapi_bm25.c

The compiled okapi_bm25.sqlext file can then be loaded as a SQLite extension. The way you do this depends on the language you're using. For example, the node-sqlite3 bindings have a special extension API you can call at the start of your program. If you're using SQLite from the console, you use the .load command to load the extension for the current session:

sqlite> .load ./okapi_bm25.sqlext

Usage

okapi_bm25(matchinfo, searchColumn [, k1] [, b])

The ranking function uses the built-in matchinfo function to obtain the data necessary to calculate the scores. A simple search query might look like this:

SELECT title FROM documents
  WHERE title MATCH <query>
  ORDER BY okapi_bm25(matchinfo(documents, 'pcnalx'), 0) DESC

The matchinfo function must be called with 'pcnalx' as the second argument. This argument defines the structure of the data given to the okapi_bm25 function, which accepts the data in only one form. If the matchinfo function is called with a different second argument, the extension may provide incorrect results or fail to work entirely.

The okapi_bm25 function only calculates the score for one column at a time. The searchColumn argument, provided as 0 in the example above, specifies the column it will use. The number is the index of the column within the FTS table. Here's a schema for the example above:

CREATE VIRTUAL TABLE documents USING fts4(title, content);

In this schema, the title column is at index 0 because it is the first column listed. If the order were reversed, the correct index for title would be 1.

The last two optional arguments, k1 and b, are free parameters specific to the Okapi BM25 algorithm. The default values are k1 = 1.2 and b = 0.75. You can tweak these for advanced optimization, but the defaults will probably work fine.

License

Okapi BM25 for SQLite3 is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].