Project

bm25f

0.0
The project is in a healthy, maintained state
A fast implementation of the BM25F ranking algorithm for information retrieval systems, written in Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 10.4.2

Runtime

 Project Readme

bm25f-ruby

A fast implementation of the BM25F ranking algorithm for information retrieval systems, written in Ruby.

Installation

If you use bundler, add this to your Gemfile:

gem 'bm25f', '~> 0.2.0'

Otherwise, you can install it using gem:

$ gem install bm25f

Usage

require 'bm25f'

# Example data
data = [
  { url: 'https://example.site', title: 'Example Site', description: 'Lorem ipsum dolor sit amet.' },
  { url: 'https://test.website', title: 'Test Website', description: 'A site for testing stuff.' }
]

query = 'test site'

# Create a new BM25F model
bm25f = BM25F.new

# Load the document data in the model using custom weights
bm25f.fit data, { url: 0.5, title: 1, description: 0.8 }

# Calculate the score of the data
score = bm25f.score query

score.each do |k, v|
  # Print out the URL, the query and the score
  puts "#{data[k][:url]} is similar to '#{query}' by #{v}"
end