Skip to main content

Crate lucene_rs

Crate lucene_rs 

Source
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

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, StringField and StoredField.
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
SmallFloat norm encoding and BM25Similarity, ported from Lucene 10.5.

Enums§

Error
Errors returned by indexing and searching.

Type Aliases§

Result