Struct tantivy::snippet::SnippetGenerator
source · pub struct SnippetGenerator { /* private fields */ }
Expand description
SnippetGenerator
§Example
use tantivy::snippet::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§
source§impl SnippetGenerator
impl SnippetGenerator
sourcepub fn new(
terms_text: BTreeMap<String, Score>,
tokenizer: TextAnalyzer,
field: Field,
max_num_chars: usize
) -> Self
pub fn new( terms_text: BTreeMap<String, Score>, tokenizer: TextAnalyzer, field: Field, max_num_chars: usize ) -> Self
Creates a new snippet generator
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. Default is 150.
sourcepub fn snippet_from_doc<D: Document>(&self, doc: &D) -> Snippet
pub fn snippet_from_doc<D: Document>(&self, doc: &D) -> Snippet
Generates a snippet for the given Document
.
This method extract the text associated with the SnippetGenerator
’s field
and computes a snippet.
Auto Trait Implementations§
impl Freeze for SnippetGenerator
impl !RefUnwindSafe for SnippetGenerator
impl Send for SnippetGenerator
impl Sync for SnippetGenerator
impl Unpin for SnippetGenerator
impl !UnwindSafe for SnippetGenerator
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn 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.source§fn 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.