[][src]Struct tantivy::query::FuzzyTermQuery

pub struct FuzzyTermQuery { /* fields omitted */ }

A Fuzzy Query matches all of the documents containing a specific term that is within Levenshtein distance

use tantivy::collector::{Count, TopDocs};
use tantivy::query::FuzzyTermQuery;
use tantivy::schema::{Schema, TEXT};
use tantivy::{doc, Index, Result, Term};

fn example() -> Result<()> {
    let mut schema_builder = Schema::builder();
    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();
    }
    let reader = index.reader()?;
    let searcher = reader.searcher();

    {
        let term = Term::from_field_text(title, "Diary");
        let query = FuzzyTermQuery::new(term, 1, true);
        let (top_docs, count) = searcher.search(&query, &(TopDocs::with_limit(2), Count)).unwrap();
        assert_eq!(count, 2);
        assert_eq!(top_docs.len(), 2);
    }

    Ok(())
}

Methods

impl FuzzyTermQuery[src]

pub fn new(
    term: Term,
    distance: u8,
    transposition_cost_one: bool
) -> FuzzyTermQuery
[src]

Creates a new Fuzzy Query

pub fn new_prefix(
    term: Term,
    distance: u8,
    transposition_cost_one: bool
) -> FuzzyTermQuery
[src]

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

Trait Implementations

impl Clone for FuzzyTermQuery[src]

impl Debug for FuzzyTermQuery[src]

impl Query for FuzzyTermQuery[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Send + Sync + Any
[src]

impl<T> Erased for T[src]

impl<T> From<T> for T[src]

impl<T> Fruit for T where
    T: Send + Downcast
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,