pub mod advanced_query;
pub mod boolean;
pub mod collector;
pub mod fuzzy;
pub mod geo;
pub mod matcher;
pub mod multi_term;
pub mod parser;
pub mod phrase;
pub mod prefix;
pub mod range;
pub mod regexp;
pub mod scorer;
pub mod span;
pub mod term;
pub mod wildcard;
pub use advanced_query::AdvancedQuery;
pub use boolean::{BooleanQuery, BooleanQueryBuilder};
pub use fuzzy::FuzzyQuery;
pub use geo::{GeoBoundingBox, GeoBoundingBoxQuery, GeoDistanceQuery, GeoPoint, GeoQuery};
pub use multi_term::MultiTermQuery;
pub use parser::LexicalQueryParser;
pub use phrase::PhraseQuery;
pub use prefix::PrefixQuery;
pub use range::NumericRangeQuery;
pub use regexp::RegexpQuery;
pub use span::{SpanNearQuery, SpanQuery, SpanTermQuery};
pub use term::TermQuery;
pub use wildcard::WildcardQuery;
use std::any::Any;
use std::collections::HashMap;
use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use crate::error::Result;
#[allow(unused_imports)]
use crate::lexical::core::document::Document;
use crate::lexical::reader::LexicalIndexReader;
use self::matcher::Matcher;
use self::scorer::Scorer;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Hit {
pub doc_id: u64,
pub score: f32,
pub fields: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchHit {
pub doc_id: u64,
pub score: f32,
pub document: Option<Document>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LexicalSearchResults {
pub hits: Vec<SearchHit>,
pub total_hits: u64,
pub max_score: f32,
}
#[derive(Debug, Clone)]
pub struct QueryResult {
pub doc_id: u64,
pub score: f32,
}
pub trait Query: Send + Sync + Debug {
fn matcher(&self, reader: &dyn LexicalIndexReader) -> Result<Box<dyn Matcher>>;
fn scorer(&self, reader: &dyn LexicalIndexReader) -> Result<Box<dyn Scorer>>;
fn boost(&self) -> f32;
fn set_boost(&mut self, boost: f32);
fn description(&self) -> String;
fn clone_box(&self) -> Box<dyn Query>;
fn is_empty(&self, reader: &dyn LexicalIndexReader) -> Result<bool>;
fn cost(&self, reader: &dyn LexicalIndexReader) -> Result<u64>;
fn as_any(&self) -> &dyn Any;
fn field(&self) -> Option<&str> {
None
}
fn apply_field_boosts(&mut self, boosts: &HashMap<String, f32>) {
if let Some(f) = self.field()
&& let Some(&b) = boosts.get(f)
{
self.set_boost(self.boost() * b);
}
}
}