Struct elasticlunr::Index
source · pub struct Index { /* private fields */ }
Expand description
An elasticlunr search index.
Implementations§
source§impl Index
impl Index
sourcepub fn with_language<I>(lang: Box<dyn Language>, fields: I) -> Selfwhere
I: IntoIterator,
I::Item: AsRef<str>,
pub fn with_language<I>(lang: Box<dyn Language>, fields: I) -> Selfwhere I: IntoIterator, I::Item: AsRef<str>,
Create a new index with the provided fields for the given
Language
.
Example
use elasticlunr::{Index, lang::English};
let mut index = Index::with_language(Box::new(English::new()), &["title", "body"]);
index.add_doc("1", &["this is a title", "this is body text"]);
Panics
Panics if a field with the name already exists.
sourcepub fn add_doc<I>(&mut self, doc_ref: &str, data: I)where
I: IntoIterator,
I::Item: AsRef<str>,
pub fn add_doc<I>(&mut self, doc_ref: &str, data: I)where I: IntoIterator, I::Item: AsRef<str>,
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 get_fields(&self) -> &[String]
sourcepub fn to_json_pretty(&self) -> String
pub fn to_json_pretty(&self) -> String
Returns the index, serialized to pretty-printed JSON.
Trait Implementations§
source§impl Deserialize<'static> for Index
impl Deserialize<'static> for Index
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'static>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'static>,
Deserialize this value from the given Serde deserializer. Read more