Struct elasticlunr::Index[][src]

pub struct Index {
    pub fields: Vec<String>,
    pub pipeline: Pipeline,
    pub ref_field: String,
    pub version: &'static str,
    pub document_store: DocumentStore,
    // some fields omitted
}
Expand description

An elasticlunr search index.

Fields

fields: Vec<String>pipeline: Pipelineref_field: Stringversion: &'static strdocument_store: DocumentStore

Implementations

Create a new index with the provided fields.

Example

let mut index = Index::new(&["title", "body", "breadcrumbs"]);
index.add_doc("1", &["How to Foo", "First, you need to `bar`.", "Chapter 1 > How to Foo"]);

Panics

Panics if multiple given fields are identical.

Create a new index with the provided fields for the given Language.

Example

let mut index = Index::with_language(Language::English, &["title", "body"]);
index.add_doc("1", &["this is a title", "this is body text"]);

Panics

Panics if multiple given fields are identical.

Add the data from a document to the index.

NOTE: The elements of data should be provided in the same order as the fields used to create the index.

Example

let mut index = Index::new(&["title", "body"]);
index.add_doc("1", &["this is a title", "this is body text"]);

Add the data from a document to the index.

NOTE: The elements of data should be provided in the same order as the fields used to create the index.

Example

fn css_tokenizer(text: &str) -> Vec<String> {
    text.split(|c: char| c.is_whitespace())
        .filter(|s| !s.is_empty())
        .map(|s| s.trim().to_lowercase())
        .collect()
}
let mut index = Index::new(&["title", "body"]);
index.add_doc_with_tokenizer("1", &["this is a title", "this is body text"], css_tokenizer);

Add the data from a document to the index.

NOTE: The elements of data and tokenizers should be provided in the same order as the fields used to create the index.

Example

use elasticlunr::pipeline::{tokenize, TokenizerFn};
fn css_tokenizer(text: &str) -> Vec<String> {
    text.split(|c: char| c.is_whitespace())
        .filter(|s| !s.is_empty())
        .map(|s| s.trim().to_lowercase())
        .collect()
}
let mut index = Index::new(&["title", "body"]);
let tokenizers: Vec<TokenizerFn> = vec![tokenize, css_tokenizer];
index.add_doc_with_tokenizers("1", &["this is a title", "this is body text"], tokenizers);

Returns the index, serialized to pretty-printed JSON.

Returns the index, serialized to JSON.

Trait Implementations

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.