[][src]Struct tantivy::query::QueryParser

pub struct QueryParser { /* fields omitted */ }

Tantivy's Query parser

The language covered by the current parser is extremely simple.

  • simple terms: "e.g.: Barack Obama are simply tokenized using tantivy's StandardTokenizer, hence becoming ["barack", "obama"]. The terms are then searched within the default terms of the query parser.

    e.g. If body and title are default fields, our example terms are ["title:barack", "body:barack", "title:obama", "body:obama"]. By default, all tokenized and indexed fields are default fields.

    Multiple terms are handled as an OR : any document containing at least one of the term will go through the scoring.

    This behavior is slower, but is not a bad idea if the user is sorting by relevance : The user typically just scans through the first few documents in order of decreasing relevance and will stop when the documents are not relevant anymore.

    Switching to a default of AND can be done by calling .set_conjunction_by_default().

  • boolean operators AND, OR. AND takes precedence over OR, so that a AND b OR c is interpreted as (a AND b) OR c.

  • In addition to the boolean operators, the -, + can help define. These operators are sufficient to express all queries using boolean operators. For instance x AND y OR z can be written ((+x +y) z). In addition, these operators can help define "required optional" queries. (+x y) matches the same document set as simply x, but y will help refining the score.

  • negative terms: By prepending a term by a -, a term can be excluded from the search. This is useful for disambiguating a query. e.g. apple -fruit

  • must terms: By prepending a term by a +, a term can be made required for the search.

  • phrase terms: Quoted terms become phrase searches on fields that have positions indexed. e.g., title:"Barack Obama" will only find documents that have "barack" immediately followed by "obama".

  • range terms: Range searches can be done by specifying the start and end bound. These can be inclusive or exclusive. e.g., title:[a TO c} will find all documents whose title contains a word lexicographically between a and c (inclusive lower bound, exclusive upper bound). Inclusive bounds are [], exclusive are {}.

  • date values: The query parser supports rfc3339 formatted dates. For example "2002-10-02T15:00:00.05Z"

  • all docs query: A plain * will match all documents in the index.


impl QueryParser[src]

pub fn new(
    schema: Schema,
    default_fields: Vec<Field>,
    tokenizer_manager: TokenizerManager
) -> QueryParser

Creates a QueryParser, given

  • schema - index Schema
  • default_fields - fields used to search if no field is specifically defined in the query.

pub fn for_index(index: &Index, default_fields: Vec<Field>) -> QueryParser[src]

Creates a QueryParser, given

  • an index
  • a set of default - fields used to search if no field is specifically defined in the query.

pub fn set_conjunction_by_default(&mut self)[src]

Set the default way to compose queries to a conjunction.

By default, the query happy tax payer is equivalent to the query happy OR tax OR payer. After calling .set_conjunction_by_default() happy tax payer will be interpreted by the parser as happy AND tax AND payer.

pub fn parse_query(
    query: &str
) -> Result<Box<dyn Query>, QueryParserError>

Parse a query

Note that parse_query returns an error if the input is not a valid query.

There is currently no lenient mode for the query parser which makes it a bad choice for a public/broad user search engine.

Implementing a lenient mode for this query parser is tracked in Issue 5

Trait Implementations

impl Clone for QueryParser[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> Fruit for T where
    T: Send + Downcast

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

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

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

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

impl<T> Erased for T[src]

impl<T> Downcast for T where
    T: Any