2024-10-15 17:48:11 +02:00
import b from 'benny'
import { create , insertMultiple , search } from 'orama_latest'
import { pluginPT15 } from '@orama/plugin-pt15'
2024-10-16 11:15:00 +02:00
import { pluginQPS } from '@orama/plugin-qps'
2024-10-15 17:48:11 +02:00
import dataset from './src/dataset.json' assert { type : 'json' }
import { stopwords } from '@orama/stopwords/english'
const dbBM25 = create ( {
schema : {
description : 'string'
} ,
components : {
tokenizer : {
stopWords : stopwords ,
} ,
}
} )
2024-10-16 11:15:00 +02:00
2024-10-15 17:48:11 +02:00
const dbWithPT15 = create ( {
schema : {
description : 'string'
} ,
plugins : [ pluginPT15 ( ) ] ,
components : {
tokenizer : {
stopWords : stopwords ,
} ,
}
} )
2024-10-16 11:15:00 +02:00
const dbWithQPS = create ( {
schema : {
description : 'string'
} ,
plugins : [ pluginQPS ( ) ] ,
components : {
tokenizer : {
stopWords : stopwords ,
} ,
}
} )
2024-10-15 17:48:11 +02:00
await insertMultiple ( dbBM25 , dataset )
await insertMultiple ( dbWithPT15 , dataset )
2024-10-16 11:15:00 +02:00
await insertMultiple ( dbWithQPS , dataset )
2024-10-15 17:48:11 +02:00
2024-10-16 11:15:00 +02:00
b . suite ( 'search-algorithms - single-term prefix' ,
b . add ( 'search bm25 - single-term prefix' , ( ) => {
2024-10-15 17:48:11 +02:00
search ( dbBM25 , { term : 'L' } )
} ) ,
2024-10-16 11:15:00 +02:00
b . add ( 'search pt15 - single-term prefix' , ( ) => {
2024-10-15 17:48:11 +02:00
search ( dbWithPT15 , { term : 'L' } )
} ) ,
2024-10-16 11:15:00 +02:00
b . add ( 'search qps - single-term prefix' , ( ) => {
search ( dbWithQPS , { term : 'L' } )
} ) ,
b . cycle ( ) ,
b . complete ( ) ,
b . save ( { file : 'insert' , version : '1.0.0' } ) ,
b . save ( { file : 'search-algorithms-single-term-prefix' , format : 'chart.html' } ) ,
)
b . suite ( 'search-algorithms - entire words' ,
b . add ( 'search bm25 - entire words' , ( ) => {
search ( dbBM25 , { term : 'Legend of Zelda' } )
} ) ,
b . add ( 'search pt15 - entire words' , ( ) => {
search ( dbWithPT15 , { term : 'Legend of Zelda' } )
} ) ,
b . add ( 'search qps - entire words' , ( ) => {
search ( dbWithQPS , { term : 'Legend of Zelda' } )
} ) ,
2024-10-15 17:48:11 +02:00
b . cycle ( ) ,
b . complete ( ) ,
b . save ( { file : 'insert' , version : '1.0.0' } ) ,
2024-10-16 11:15:00 +02:00
b . save ( { file : 'search-algorithms-entire-words' , format : 'chart.html' } ) ,
2024-10-15 17:48:11 +02:00
)