Skip to content

Searching Dictionaries

Full-text search lets you find entries by matching against their definitions, not just their headwords. Unlike lookup which requires an exact term match, search uses a Tantivy-powered full-text index.

Before you can search, you need to create a full-text index. This only needs to be done once per dictionary (the index is persisted to disk).

use odict::{OpenDictionary, index::IndexOptions};
fn main() -> odict::Result<()> {
let file = OpenDictionary::from_path("my-dictionary.odict")?;
let dict = file.contents()?;
dict.index(IndexOptions::default())?;
Ok(())
}

You can configure the indexing behavior.

use odict::index::IndexOptions;
let options = IndexOptions::default()
.dir("./my-index") // Custom index directory
.overwrite(true) // Overwrite existing index
.memory(50_000_000); // 50MB memory arena per thread
dict.index(options)?;

Once indexed, you can search across all definitions in the dictionary.

use odict::search::SearchOptions;
let results = dict.search("domesticated mammal", SearchOptions::default())?;
for entry in &results {
println!("{}", entry.term);
}
use odict::search::SearchOptions;
let options = SearchOptions::default()
.dir("./my-index") // Custom index directory
.autoindex(true) // Auto-create index if missing
.limit(10) // Max results to return
.threshold(50); // Relevance threshold
let results = dict.search("greeting", options)?;
LookupSearch
Matches againstEntry terms (headwords)Definition text
Requires indexNoYes
SpeedO(1) per termDepends on index size
Use caseYou know the exact wordYou’re searching by meaning
Supports splittingYesNo
Supports followYesNo

In most applications you’ll use both: lookup for direct dictionary access, and search for discovery.