probly-search · GitHub license Coverage Status ![Latest Version] PRs Welcome

A lightweight and thread-safe, full-text search library that provides full control over the scoring calculations.

This start initially as a port of the Node library NDX.

Features

Documentation

Documentation is under development. For now read the source tests.

Example

Creating an index with a document that has 2 fields. Query documents, and remove a document. ```rust use std::collections::HashSet; use problysearch::{ index::{adddocumenttoindex, createindex, removedocumentfromindex, Index}, query::{ query, score::default::{bm25, zerotoone}, QueryResult, }, };

// Create index with two fields let mut idx: Index = create_index(2);

// Create docs from a custom Doc struct struct Doc { id: usize, title: String, description: String, }

let doc1 = Doc { id: 0, title: "abc".tostring(), description: "dfg".to_string(), };

let doc2 = Doc { id: 1, title: "dfgh".tostring(), description: "abcd".to_string(), };

// Add documents to index fn tokenizer(s: &str) -> Vec { s.split(' ') .map(|slice| slice.toowned()) .collect::>() } fn titleextract(d: &Doc) -> Option<&str> { Some(d.title.as_str()) }

fn descriptionextract(d: &Doc) -> Option<&str> { Some(d.description.asstr()) }

fn filter(s: &String) -> String { s.to_owned() }

adddocumenttoindex( &mut idx, &[titleextract, descriptionextract], tokenizer, filter, doc1.id, doc_1.clone(), );

adddocumenttoindex( &mut idx, &[titleextract, descriptionextract], tokenizer, filter, doc2.id, doc_2, );

// Search, expect 2 results let mut result = query( &mut idx, &"abc", &mut bm25::new(), tokenizer, filter, &[1., 1.], None, ); asserteq!(result.len(), 2); asserteq!( result[0], QueryResult { key: 0, score: 0.6931471805599453 } ); assert_eq!( result[1], QueryResult { key: 1, score: 0.28104699650060755 } ); ```

Go through source tests in for the BM25 implementation and zero-to-one implementation for more query examples.

License

MIT