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]

Creates a new Fuzzy Query

Creates a new Fuzzy Query that treats transpositions as cost one rather than two

Trait Implementations

impl Debug for FuzzyTermQuery
[src]

Formats the value using the given formatter. Read more

impl Clone for FuzzyTermQuery
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Query for FuzzyTermQuery
[src]

Create the weight associated to a query. Read more

Returns the number of documents matching the query.

Extract all of the terms associated to the query and insert them in the term set given in arguments. Read more

Search works as follows : Read more

Auto Trait Implementations