Struct perlin::index::boolean_index::QueryBuilder [] [src]

pub struct QueryBuilder<TTerm> { /* fields omitted */ }

This struct provides a flexible and ergonomic was to build BooleanQueries

Examples

Simple Atom-Queries

Querying an Atom:

use perlin::index::boolean_index::QueryBuilder;
//Would return all document ids of documents that contain '4'
let query = QueryBuilder::atom(4).build();Run

Boolean Operators

Querying for two Atoms:

use perlin::index::boolean_index::QueryBuilder;
//Would return all document ids of documents that contain '4' AND '8'
let and_query = QueryBuilder::and(QueryBuilder::atoms(vec![4, 8])).build();

//Would return all document ids of documents that contain '4' OR '8'
let or_query = QueryBuilder::or(QueryBuilder::atoms(vec![4, 8])).build();Run

Positional Operators

Querying for phrases:

use perlin::index::boolean_index::QueryBuilder;

//Would return all document ids of documents that contain '1 2 3'
let phrase_query = QueryBuilder::in_order(
               vec![Some(1), Some(2), Some(3)]).build();

//Would match any phrase in following form "this is a * house"
//Where '*' can be any term
//i.e. "this is a blue house" or "this is a small house"
//It would not match "this is a house" though.
let placeholder_query = QueryBuilder::in_order(
    vec![Some("this"),Some("is"), Some("a"), None, Some("house")]).build();Run

Query Filters

use perlin::index::boolean_index::QueryBuilder;

//Would return all document ids of documents that contain '4' but NOT '8'
let filtered_query =
QueryBuilder::atom(4).not(QueryBuilder::atom(8)).build();Run

Nested Queries

Query objects can be nested in arbitrary depth:

use perlin::index::boolean_index::QueryBuilder;

let nested_query = QueryBuilder::and(vec![
                        QueryBuilder::or(QueryBuilder::atoms(vec![0, 4])),
                        QueryBuilder::in_order(
                                   vec![Some(9),
                                        Some(7)])
                                   .not(QueryBuilder::atom(3))]).build();Run

Methods

impl<TTerm> QueryBuilder<TTerm>
[src]

Operands are connected by the AND-Operator. All operands have to occur in a document for it to match

Operands are connected by the OR-Operator. Any operand can occur in a docment for it to match

Turns a vector of terms into a vector of QueryBuilder objects.

Useful utility function to be used with other methods in this struct. See module level documentation for examples.

Most simple query for just a term. Documents containing the term match, all others do not.

Use this method to build phrase queries.

Operands must occur in the same order as passed to the method in the document. Operands are wrapped inside Option to allow for placeholders in phrase queries.

I.e. Some(A): A has to occur at that position None: Any term can occur at that position. See module level documentation for examples

Applies the NOT operator between to queries. E.g. returns all document ids that match self and NOT filter See module level documentation for example

Final method to be called in the query building process. Returns the actual BooleanQuery object to be passed to the index.