lucene_rs/lib.rs
1//! A Rust port of the core of [Apache Lucene](https://lucene.apache.org/) 10.5: the
2//! Lucene104 postings format, BM25 scoring, Lucene's block-max top-k algorithms, segment-based
3//! indexing with deletes and merges, analyzers and the classic query parser.
4//!
5//! On the benchmark corpus (469k Wikipedia articles) it returns the same top-10 documents with
6//! bit-identical scores as Lucene 10.5.2, about 1.6–2x faster per query.
7//!
8//! # Quick start
9//!
10//! ```
11//! use lucene_rs::{
12//! DirectoryReader, Document, Field, IndexSearcher, IndexWriter, IndexWriterConfig, QueryParser,
13//! StandardAnalyzer, Store,
14//! };
15//!
16//! # fn main() -> lucene_rs::Result<()> {
17//! # let tmp = tempfile::tempdir()?;
18//! # let dir = tmp.path();
19//! let mut writer = IndexWriter::open(dir, IndexWriterConfig::default())?;
20//! writer.add_document(
21//! &Document::new()
22//! .with(Field::string("id", "1", Store::Yes))
23//! .with(Field::text("title", "Rust in Action", Store::Yes))
24//! .with(Field::text("body", "systems programming in rust", Store::No)),
25//! )?;
26//! writer.commit()?;
27//!
28//! let searcher = IndexSearcher::new(DirectoryReader::open(dir)?);
29//! let query = QueryParser::new("body", StandardAnalyzer::new()).parse("\"systems programming\" title:rust")?;
30//! let top = searcher.search(&query, 10)?;
31//! assert_eq!(top.total_hits.value, 1);
32//! let doc = searcher.doc(top.score_docs[0].doc)?;
33//! assert_eq!(doc.get_str("title"), Some("Rust in Action"));
34//! # Ok(())
35//! # }
36//! ```
37//!
38//! # Map
39//!
40//! - [`document`]: [`Document`], [`Field`], [`FieldType`] (text, keyword, stored fields).
41//! - [`analysis`]: [`Analyzer`] and the standard, whitespace, simple and keyword analyzers.
42//! - [`index`]: [`IndexWriter`] (add, update, delete, flush, merge, commit) and
43//! [`DirectoryReader`] (a point-in-time view of a commit).
44//! - [`search`]: [`Query`], [`BooleanQuery`], [`PhraseQuery`] and [`IndexSearcher`].
45//! - [`queryparser`]: Lucene's classic query syntax.
46//! - [`sim`]: BM25 and Lucene's one-byte norm encoding.
47//!
48//! The on-disk format follows Lucene104's postings layout but is not file-compatible with
49//! Lucene: indexes written by one cannot be read by the other.
50#![deny(unsafe_op_in_unsafe_fn)]
51
52pub mod analysis;
53mod codec;
54pub mod document;
55mod error;
56pub mod index;
57mod num;
58mod pool;
59pub mod queryparser;
60pub mod search;
61pub mod sim;
62
63pub use analysis::{Analyzer, StandardAnalyzer};
64pub use document::{Document, Field, FieldType, FieldValue, IndexOptions, Store};
65pub use error::{Error, Result};
66pub use index::doc_values::SortValue;
67pub use index::{DirectoryReader, IndexWriter, IndexWriterConfig, OpenMode, Term};
68pub use queryparser::QueryParser;
69pub use search::{BooleanQuery, IndexSearcher, Occur, PhraseQuery, Query, ScoreDoc, TopDocs};
70pub use search::{FieldDoc, MissingValue, Sort, SortField, SortOrder};