Struct tantivy::SnippetGenerator
source · [−]pub struct SnippetGenerator { /* private fields */ }
Expand description
SnippetGenerator
Example
use tantivy::SnippetGenerator;
// ...
let query = query_parser.parse_query("haleurs flamands").unwrap();
let mut snippet_generator = SnippetGenerator::create(&searcher, &*query, text_field)?;
snippet_generator.set_max_num_chars(100);
let snippet = snippet_generator.snippet_from_doc(&doc);
let snippet_html: String = snippet.to_html();
assert_eq!(snippet_html, "Comme je descendais des Fleuves impassibles,\n Je ne me sentis plus guidé par les <b>haleurs</b> :\n Des");
Implementations
sourceimpl SnippetGenerator
impl SnippetGenerator
sourcepub fn create(
searcher: &Searcher,
query: &dyn Query,
field: Field
) -> Result<SnippetGenerator>
pub fn create(
searcher: &Searcher,
query: &dyn Query,
field: Field
) -> Result<SnippetGenerator>
Creates a new snippet generator
sourcepub fn set_max_num_chars(&mut self, max_num_chars: usize)
pub fn set_max_num_chars(&mut self, max_num_chars: usize)
Sets a maximum number of chars.
sourcepub fn snippet_from_doc(&self, doc: &Document) -> Snippet
pub fn snippet_from_doc(&self, doc: &Document) -> Snippet
Generates a snippet for the given Document
.
This method extract the text associated to the SnippetGenerator
’s field
and computes a snippet.
Auto Trait Implementations
impl !RefUnwindSafe for SnippetGenerator
impl Send for SnippetGenerator
impl Sync for SnippetGenerator
impl Unpin for SnippetGenerator
impl !UnwindSafe for SnippetGenerator
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more