probly search
2.0.1
スコアリングの計算を完全に制御できる挿入速度のために最適化された錆で記述されたフルテキスト検索ライブラリ。
これは、最初はノードライブラリNDXのポートとして開始されます。
レシピ(タイトル)50Kドキュメントを使用した検索。
https://quantleaf.github.io/probly-search-demo/
得点をするための3つの方法
ScoreCalculator特性を埋めて、独自のスコアリング機能を完全にカスタマイズする機能。TRIEベースの動的逆インデックス。
複数のフィールドフルテキストインデックス作成と検索。
フィールドごとのスコアブースト。
構成可能なトークンザー。
クエリ拡張を備えた無料のテキストクエリ。
高速割り当て、しかし潜在的な削除。
WASM互換性
統合テストを参照してください。
レシピ検索デモプロジェクトを参照してください
2つのフィールドを持つドキュメントを使用してインデックスを作成します。ドキュメントをクエリし、ドキュメントを削除します。
use std :: collections :: HashSet ;
use probly_search :: {
index :: Index ,
query :: {
score :: default :: { bm25 , zero_to_one } ,
QueryResult ,
} ,
} ;
// A white space tokenizer
fn tokenizer ( s : & str ) -> Vec < Cow < str > > {
s . split ( ' ' ) . map ( Cow :: from ) . collect :: < Vec < _ > > ( )
}
// We have to provide extraction functions for the fields we want to index
// Title
fn title_extract ( d : & Doc ) -> Vec < & str > {
vec ! [ d.title.as_str ( ) ]
}
// Description
fn description_extract ( d : & Doc ) -> Vec < & str > {
vec ! [ d.description.as_str ( ) ]
}
// Create index with 2 fields
let mut index = Index :: < usize > :: new ( 2 ) ;
// Create docs from a custom Doc struct
let doc_1 = Doc {
id : 0 ,
title : "abc" . to_string ( ) ,
description : "dfg" . to_string ( ) ,
} ;
let doc_2 = Doc {
id : 1 ,
title : "dfgh" . to_string ( ) ,
description : "abcd" . to_string ( ) ,
} ;
// Add documents to index
index . add_document (
& [ title_extract , description_extract ] ,
tokenizer ,
doc_1 . id ,
& doc_1 ,
) ;
index . add_document (
& [ title_extract , description_extract ] ,
tokenizer ,
doc_2 . id ,
& doc_2 ,
) ;
// Search, expected 2 results
let mut result = index . query (
& "abc" ,
& mut bm25 :: new ( ) ,
tokenizer ,
& [ 1. , 1. ] ,
) ;
assert_eq ! ( result.len ( ) , 2 ) ;
assert_eq ! (
result [ 0 ] ,
QueryResult {
key: 0 ,
score: 0.6931471805599453
}
) ;
assert_eq ! (
result [ 1 ] ,
QueryResult {
key: 1 ,
score: 0.28104699650060755
}
) ;
// Remove documents from index
index . remove_document ( doc_1 . id ) ;
// Vacuum to remove completely
index . vacuum ( ) ;
// Search, expect 1 result
result = index . query (
& "abc" ,
& mut bm25 :: new ( ) ,
tokenizer ,
& [ 1. , 1. ] ,
) ;
assert_eq ! ( result.len ( ) , 1 ) ;
assert_eq ! (
result [ 0 ] ,
QueryResult {
key: 1 ,
score: 0.1166450426074421
}
) ;BM25実装のソーステストと、その他のクエリの例のためにゼロから1つの実装を使用してください。
すべてのテストを実行します
cargo testすべてのベンチマークを実行します
cargo benchmit