[−][src]Struct tantivy::query::TermQuery
A Term query matches all of the documents containing a specific term.
The score associated is defined as
idf
* sqrt(term_freq
/ field norm
)
in which :
idf
- inverse document frequency.term_freq
- number of occurrences of the term in the fieldfield norm
- number of tokens in the field.
#[macro_use] extern crate tantivy; use tantivy::schema::{Schema, TEXT, IndexRecordOption}; use tantivy::{Index, Result, Term}; use tantivy::collector::{Count, TopDocs}; use tantivy::query::TermQuery; fn example() -> Result<()> { let mut schema_builder = Schema::builder(); let title = schema_builder.add_text_field("title", TEXT); let schema = schema_builder.build(); let index = Index::create_in_ram(schema); { let mut index_writer = index.writer(3_000_000)?; index_writer.add_document(doc!( title => "The Name of the Wind", )); index_writer.add_document(doc!( title => "The Diary of Muadib", )); index_writer.add_document(doc!( title => "A Dairy Cow", )); index_writer.add_document(doc!( title => "The Diary of a Young Girl", )); index_writer.commit()?; } let reader = index.reader()?; let searcher = reader.searcher(); let query = TermQuery::new( Term::from_field_text(title, "diary"), IndexRecordOption::Basic, ); let (top_docs, count) = searcher.search(&query, &(TopDocs::with_limit(2), Count)).unwrap(); assert_eq!(count, 2); Ok(()) }
Methods
impl TermQuery
[src]
pub fn new(term: Term, segment_postings_options: IndexRecordOption) -> TermQuery
[src]
Creates a new term query.
pub fn term(&self) -> &Term
[src]
The Term
this query is built out of.
pub fn specialized_weight(
&self,
searcher: &Searcher,
scoring_enabled: bool
) -> TermWeight
[src]
&self,
searcher: &Searcher,
scoring_enabled: bool
) -> TermWeight
Returns a weight object.
While .weight(...)
returns a boxed trait object,
this method return a specific implementation.
This is useful for optimization purpose.
Trait Implementations
impl Query for TermQuery
[src]
fn weight(
&self,
searcher: &Searcher,
scoring_enabled: bool
) -> Result<Box<dyn Weight>>
[src]
&self,
searcher: &Searcher,
scoring_enabled: bool
) -> Result<Box<dyn Weight>>
fn query_terms(&self, term_set: &mut BTreeSet<Term>)
[src]
fn explain(
&self,
searcher: &Searcher,
doc_address: DocAddress
) -> Result<Explanation>
[src]
&self,
searcher: &Searcher,
doc_address: DocAddress
) -> Result<Explanation>
fn count(&self, searcher: &Searcher) -> Result<usize>
[src]
impl Clone for TermQuery
[src]
impl Debug for TermQuery
[src]
Auto Trait Implementations
impl Send for TermQuery
impl Sync for TermQuery
impl Unpin for TermQuery
impl UnwindSafe for TermQuery
impl RefUnwindSafe for TermQuery
Blanket Implementations
impl<T> Fruit for T where
T: Send + Downcast,
[src]
T: Send + Downcast,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Erased for T
[src]
impl<T> Downcast for T where
T: Any,
[src]
T: Any,