مكتبة بحث كاملة النص ، مكتوبة في الصدأ ، محسّنة لسرعة الإدراج ، توفر التحكم الكامل في حسابات التسجيل.
يبدأ هذا في البداية كمنفذ لمكتبة العقدة NDX.
وصفة (عنوان) ابحث مع 50 ألف مستندات.
https://quantleaf.github.io/probly-search-demo/
ثلاث طرق للقيام بالتسجيل
ScoreCalculator .فهرس ديناميكي مقلوب القائم على تري.
حقول متعددة فهرسة النص الكامل والبحث.
لكل حقل درجة تعزيز.
Tokenizer القابلة للتكوين.
استفسارات نص مجانية مع توسيع الاستعلام.
تخصيص سريع ، ولكن الحذف الكامن.
WASM متوافق
انظر اختبارات التكامل.
انظر مشروع تجريبي البحث عن الوصفة
إنشاء فهرس مع مستند يحتوي على حقلين. المستندات الاستعلام ، وإزالة وثيقة.
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 والتنفيذ صفر إلى واحد لمزيد من أمثلة الاستعلام.
تشغيل جميع الاختبارات مع
cargo testتشغيل كل المعايير مع
cargo benchمعهد ماساتشوستس للتكنولوجيا