Struct tantivy::query::FuzzyTermQuery [−][src]
pub struct FuzzyTermQuery { /* fields omitted */ }
A Fuzzy Query matches all of the documents containing a specific term that is within Levenshtein distance
#[macro_use] extern crate tantivy; use tantivy::schema::{SchemaBuilder, TEXT}; use tantivy::{Index, Result, Term}; use tantivy::collector::{CountCollector, TopCollector, chain}; use tantivy::query::FuzzyTermQuery; fn example() -> Result<()> { let mut schema_builder = SchemaBuilder::new(); let title = schema_builder.add_text_field("title", TEXT); let schema = schema_builder.build(); let index = Index::create_in_ram(schema); { let mut index_writer = index.writer(3_000_000)?; index_writer.add_document(doc!( title => "The Name of the Wind", )); index_writer.add_document(doc!( title => "The Diary of Muadib", )); index_writer.add_document(doc!( title => "A Dairy Cow", )); index_writer.add_document(doc!( title => "The Diary of a Young Girl", )); index_writer.commit().unwrap(); } index.load_searchers()?; let searcher = index.searcher(); { let mut top_collector = TopCollector::with_limit(2); let mut count_collector = CountCollector::default(); { let mut collectors = chain().push(&mut top_collector).push(&mut count_collector); let term = Term::from_field_text(title, "Diary"); let query = FuzzyTermQuery::new(term, 1, true); searcher.search(&query, &mut collectors).unwrap(); } assert_eq!(count_collector.count(), 2); assert!(top_collector.at_capacity()); } Ok(()) }
Methods
impl FuzzyTermQuery
[src]
impl FuzzyTermQuery
pub fn new(
term: Term,
distance: u8,
transposition_cost_one: bool
) -> FuzzyTermQuery
[src]
pub fn new(
term: Term,
distance: u8,
transposition_cost_one: bool
) -> FuzzyTermQuery
Creates a new Fuzzy Query
pub fn new_prefix(
term: Term,
distance: u8,
transposition_cost_one: bool
) -> FuzzyTermQuery
[src]
pub fn new_prefix(
term: Term,
distance: u8,
transposition_cost_one: bool
) -> FuzzyTermQuery
Creates a new Fuzzy Query that treats transpositions as cost one rather than two
Trait Implementations
impl Debug for FuzzyTermQuery
[src]
impl Debug for FuzzyTermQuery
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for FuzzyTermQuery
[src]
impl Clone for FuzzyTermQuery
fn clone(&self) -> FuzzyTermQuery
[src]
fn clone(&self) -> FuzzyTermQuery
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0
[src]Performs copy-assignment from source
. Read more
impl Query for FuzzyTermQuery
[src]
impl Query for FuzzyTermQuery
fn weight(
&self,
_searcher: &Searcher,
_scoring_enabled: bool
) -> Result<Box<Weight>>
[src]
fn weight(
&self,
_searcher: &Searcher,
_scoring_enabled: bool
) -> Result<Box<Weight>>
Create the weight associated to a query. Read more
fn count(&self, searcher: &Searcher) -> Result<usize>
[src]
fn count(&self, searcher: &Searcher) -> Result<usize>
Returns the number of documents matching the query.
fn query_terms(&self, _term_set: &mut BTreeSet<Term>)
[src]
fn query_terms(&self, _term_set: &mut BTreeSet<Term>)
Extract all of the terms associated to the query and insert them in the term set given in arguments. Read more
fn search(&self, searcher: &Searcher, collector: &mut Collector) -> Result<()>
[src]
fn search(&self, searcher: &Searcher, collector: &mut Collector) -> Result<()>
Search works as follows : Read more
Auto Trait Implementations
impl Send for FuzzyTermQuery
impl Send for FuzzyTermQuery
impl Sync for FuzzyTermQuery
impl Sync for FuzzyTermQuery