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

impl Index[src]

pub fn new<I>(fields: I) -> Self where
    I: IntoIterator,
    I::Item: AsRef<str>, 
[src]

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.

pub fn with_language<I>(lang: Language, fields: I) -> Self where
    I: IntoIterator,
    I::Item: AsRef<str>, 
[src]

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.

pub fn add_doc<I>(&mut self, doc_ref: &str, data: I) where
    I: IntoIterator,
    I::Item: AsRef<str>, 
[src]

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"]);

pub fn add_doc_with_tokenizer<I>(
    &mut self,
    doc_ref: &str,
    data: I,
    tokenizer: TokenizerFn
) where
    I: IntoIterator,
    I::Item: AsRef<str>, 
[src]

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);

pub fn add_doc_with_tokenizers<I, T>(
    &mut self,
    doc_ref: &str,
    data: I,
    tokenizers: T
) where
    I: IntoIterator,
    I::Item: AsRef<str>,
    T: IntoIterator<Item = TokenizerFn>, 
[src]

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);

pub fn get_fields(&self) -> &[String][src]

pub fn to_json_pretty(&self) -> String[src]

Returns the index, serialized to pretty-printed JSON.

pub fn to_json(&self) -> String[src]

Returns the index, serialized to JSON.

Trait Implementations

impl Debug for Index[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Deserialize<'static> for Index[src]

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'static>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Serialize for Index[src]

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
    __S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

impl RefUnwindSafe for Index

impl Send for Index

impl Sync for Index

impl Unpin for Index

impl UnwindSafe for Index

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.