Expand description
A Rust port of the core of Apache Lucene 10.5: the Lucene104 postings format, BM25 scoring, Lucene’s block-max top-k algorithms, segment-based indexing with deletes and merges, analyzers and the classic query parser.
On the benchmark corpus (469k Wikipedia articles) it returns the same top-10 documents with bit-identical scores as Lucene 10.5.2, about 1.6–2x faster per query.
§Quick start
use lucene_rs::{
DirectoryReader, Document, Field, IndexSearcher, IndexWriter, IndexWriterConfig, QueryParser,
StandardAnalyzer, Store,
};
let mut writer = IndexWriter::open(dir, IndexWriterConfig::default())?;
writer.add_document(
&Document::new()
.with(Field::string("id", "1", Store::Yes))
.with(Field::text("title", "Rust in Action", Store::Yes))
.with(Field::text("body", "systems programming in rust", Store::No)),
)?;
writer.commit()?;
let searcher = IndexSearcher::new(DirectoryReader::open(dir)?);
let query = QueryParser::new("body", StandardAnalyzer::new()).parse("\"systems programming\" title:rust")?;
let top = searcher.search(&query, 10)?;
assert_eq!(top.total_hits.value, 1);
let doc = searcher.doc(top.score_docs[0].doc)?;
assert_eq!(doc.get_str("title"), Some("Rust in Action"));§Map
document:Document,Field,FieldType(text, keyword, stored fields).analysis:Analyzerand the standard, whitespace, simple and keyword analyzers.index:IndexWriter(add, update, delete, flush, merge, commit) andDirectoryReader(a point-in-time view of a commit).search:Query,BooleanQuery,PhraseQueryandIndexSearcher.queryparser: Lucene’s classic query syntax.sim: BM25 and Lucene’s one-byte norm encoding.
The on-disk format follows Lucene104’s postings layout but is not file-compatible with Lucene: indexes written by one cannot be read by the other.
Re-exports§
pub use analysis::Analyzer;pub use analysis::StandardAnalyzer;pub use document::Document;pub use document::Field;pub use document::FieldType;pub use document::FieldValue;pub use document::IndexOptions;pub use document::Store;pub use index::doc_values::SortValue;pub use index::DirectoryReader;pub use index::IndexWriter;pub use index::IndexWriterConfig;pub use index::OpenMode;pub use index::Term;pub use queryparser::QueryParser;pub use search::BooleanQuery;pub use search::IndexSearcher;pub use search::Occur;pub use search::PhraseQuery;pub use search::Query;pub use search::ScoreDoc;pub use search::TopDocs;pub use search::FieldDoc;pub use search::MissingValue;pub use search::Sort;pub use search::SortField;pub use search::SortOrder;
Modules§
- analysis
- Text analysis: turning field values into terms with positions.
- document
- Documents and fields, mirroring Lucene’s
Document,Field,FieldType,TextField,StringFieldandStoredField. - index
- Writing and reading indexes: documents are buffered and inverted in memory, flushed as immutable segments, merged in the background of commits, and published atomically.
- queryparser
- Lucene “classic” query syntax:
title:rust +"exact phrase" -draft (a OR b)^2. - search
- Searching: queries, scoring (BM25) and top-k collection.
- sim
SmallFloatnorm encoding andBM25Similarity, ported from Lucene 10.5.
Enums§
- Error
- Errors returned by indexing and searching.