Oihana PHP Arango

bm25.php

Table of Contents

Functions

bm25()  : string
Score documents with the Best Matching 25 algorithm (Okapi BM25).

Functions

bm25()

Score documents with the Best Matching 25 algorithm (Okapi BM25).

bm25(string $doc[, float|null $k = null ][, float|null $b = null ]) : string

Wraps the ArangoDB AQL scoring function BM25(doc, k, b). The first argument must be the document variable emitted by a FOR … IN viewName operation, and the function can only be used together with a SEARCH. Sort descending by the score to get the most relevant documents first.

AQL arguments are positional: when $b is provided without $k, the helper fills $k with the official server default (1.2). The Analyzers used for indexing must have the "frequency" feature enabled (and "norm" for meaningful length normalization), otherwise the score is 0.

Example AQL usage:

FOR doc IN viewName
  SEARCH ...
  SORT BM25(doc) DESC
  RETURN doc
Parameters
$doc : string

The document variable emitted by FOR … IN viewName (kept raw).

$k : float|null = null

Optional term-frequency calibration, >= 0.0 (server default 1.2; 0 = binary model).

$b : float|null = null

Optional text-length scaling in [0.0, 1.0] (server default 0.75; 1 = BM11, 0 = BM15).

Tags
example
use function oihana\arango\db\functions\search\bm25;

echo bm25( 'doc' ) ;              // 'BM25(doc)'
echo bm25( 'doc' , 2.4 , 1.0 ) ;  // 'BM25(doc,2.4,1)'
echo bm25( 'doc' , b: 0.5 ) ;     // 'BM25(doc,1.2,0.5)'
see
https://docs.arangodb.com/stable/aql/functions/arangosearch/#bm25
tfidf()
boost()
since
1.2.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results