Rename the FacetCondition into FilterCondition
This commit is contained in:
parent
c2afdbb1fb
commit
3b1cd4c4b4
|
@ -29,7 +29,7 @@ use tokio::sync::broadcast;
|
|||
use warp::{Filter, http::Response};
|
||||
use warp::filters::ws::Message;
|
||||
|
||||
use milli::{FacetCondition, Index, MatchingWords, obkv_to_json, SearchResult, UpdateStore};
|
||||
use milli::{FilterCondition, Index, MatchingWords, obkv_to_json, SearchResult, UpdateStore};
|
||||
use milli::update::{IndexDocumentsMethod, Setting, UpdateBuilder, UpdateFormat};
|
||||
use milli::update::UpdateIndexingStep::*;
|
||||
|
||||
|
@ -690,7 +690,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
|
||||
let filters = match query.filters {
|
||||
Some(condition) if !condition.trim().is_empty() => {
|
||||
Some(FacetCondition::from_str(&rtxn, &index, &condition).unwrap())
|
||||
Some(FilterCondition::from_str(&rtxn, &index, &condition).unwrap())
|
||||
}
|
||||
_otherwise => None,
|
||||
};
|
||||
|
@ -698,21 +698,21 @@ async fn main() -> anyhow::Result<()> {
|
|||
let facet_filters = match query.facet_filters {
|
||||
Some(array) => {
|
||||
let eithers = array.into_iter().map(Into::into);
|
||||
FacetCondition::from_array(&rtxn, &index, eithers).unwrap()
|
||||
FilterCondition::from_array(&rtxn, &index, eithers).unwrap()
|
||||
}
|
||||
_otherwise => None,
|
||||
};
|
||||
|
||||
let condition = match (filters, facet_filters) {
|
||||
(Some(filters), Some(facet_filters)) => {
|
||||
Some(FacetCondition::And(Box::new(filters), Box::new(facet_filters)))
|
||||
Some(FilterCondition::And(Box::new(filters), Box::new(facet_filters)))
|
||||
}
|
||||
(Some(condition), None) | (None, Some(condition)) => Some(condition),
|
||||
_otherwise => None,
|
||||
};
|
||||
|
||||
if let Some(condition) = condition {
|
||||
search.facet_condition(condition);
|
||||
search.filter(condition);
|
||||
}
|
||||
|
||||
let SearchResult { matching_words, candidates, documents_ids } = search.execute().unwrap();
|
||||
|
|
|
@ -27,7 +27,7 @@ pub use self::heed_codec::{BEU32StrCodec, StrStrU8Codec, StrLevelPositionCodec,
|
|||
pub use self::heed_codec::{RoaringBitmapCodec, BoRoaringBitmapCodec, CboRoaringBitmapCodec};
|
||||
pub use self::heed_codec::{RoaringBitmapLenCodec, BoRoaringBitmapLenCodec, CboRoaringBitmapLenCodec};
|
||||
pub use self::index::Index;
|
||||
pub use self::search::{Search, FacetDistribution, FacetCondition, SearchResult, MatchingWords};
|
||||
pub use self::search::{Search, FacetDistribution, FilterCondition, SearchResult, MatchingWords};
|
||||
pub use self::tree_level::TreeLevel;
|
||||
pub use self::update_store::UpdateStore;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ use super::FacetRange;
|
|||
use super::parser::Rule;
|
||||
use super::parser::{PREC_CLIMBER, FilterParser};
|
||||
|
||||
use self::FacetCondition::*;
|
||||
use self::FilterCondition::*;
|
||||
use self::Operator::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -49,18 +49,18 @@ impl Operator {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum FacetCondition {
|
||||
pub enum FilterCondition {
|
||||
Operator(FieldId, Operator),
|
||||
Or(Box<Self>, Box<Self>),
|
||||
And(Box<Self>, Box<Self>),
|
||||
}
|
||||
|
||||
impl FacetCondition {
|
||||
impl FilterCondition {
|
||||
pub fn from_array<I, J, A, B>(
|
||||
rtxn: &heed::RoTxn,
|
||||
index: &Index,
|
||||
array: I,
|
||||
) -> anyhow::Result<Option<FacetCondition>>
|
||||
) -> anyhow::Result<Option<FilterCondition>>
|
||||
where I: IntoIterator<Item=Either<J, B>>,
|
||||
J: IntoIterator<Item=A>,
|
||||
A: AsRef<str>,
|
||||
|
@ -73,7 +73,7 @@ impl FacetCondition {
|
|||
Either::Left(array) => {
|
||||
let mut ors = None;
|
||||
for rule in array {
|
||||
let condition = FacetCondition::from_str(rtxn, index, rule.as_ref())?;
|
||||
let condition = FilterCondition::from_str(rtxn, index, rule.as_ref())?;
|
||||
ors = match ors.take() {
|
||||
Some(ors) => Some(Or(Box::new(ors), Box::new(condition))),
|
||||
None => Some(condition),
|
||||
|
@ -88,7 +88,7 @@ impl FacetCondition {
|
|||
}
|
||||
},
|
||||
Either::Right(rule) => {
|
||||
let condition = FacetCondition::from_str(rtxn, index, rule.as_ref())?;
|
||||
let condition = FilterCondition::from_str(rtxn, index, rule.as_ref())?;
|
||||
ands = match ands.take() {
|
||||
Some(ands) => Some(And(Box::new(ands), Box::new(condition))),
|
||||
None => Some(condition),
|
||||
|
@ -104,12 +104,12 @@ impl FacetCondition {
|
|||
rtxn: &heed::RoTxn,
|
||||
index: &Index,
|
||||
expression: &str,
|
||||
) -> anyhow::Result<FacetCondition>
|
||||
) -> anyhow::Result<FilterCondition>
|
||||
{
|
||||
let fields_ids_map = index.fields_ids_map(rtxn)?;
|
||||
let filterable_fields = index.filterable_fields_ids(rtxn)?;
|
||||
let lexed = FilterParser::parse(Rule::prgm, expression)?;
|
||||
FacetCondition::from_pairs(&fields_ids_map, &filterable_fields, lexed)
|
||||
FilterCondition::from_pairs(&fields_ids_map, &filterable_fields, lexed)
|
||||
}
|
||||
|
||||
fn from_pairs(
|
||||
|
@ -143,7 +143,7 @@ impl FacetCondition {
|
|||
)
|
||||
}
|
||||
|
||||
fn negate(self) -> FacetCondition {
|
||||
fn negate(self) -> FilterCondition {
|
||||
match self {
|
||||
Operator(fid, op) => match op.negate() {
|
||||
(op, None) => Operator(fid, op),
|
||||
|
@ -158,7 +158,7 @@ impl FacetCondition {
|
|||
fields_ids_map: &FieldsIdsMap,
|
||||
filterable_fields: &HashSet<FieldId>,
|
||||
item: Pair<Rule>,
|
||||
) -> anyhow::Result<FacetCondition>
|
||||
) -> anyhow::Result<FilterCondition>
|
||||
{
|
||||
let mut items = item.into_inner();
|
||||
let fid = field_id(fields_ids_map, filterable_fields, &mut items)?;
|
||||
|
@ -176,7 +176,7 @@ impl FacetCondition {
|
|||
fields_ids_map: &FieldsIdsMap,
|
||||
filterable_fields: &HashSet<FieldId>,
|
||||
item: Pair<Rule>,
|
||||
) -> anyhow::Result<FacetCondition>
|
||||
) -> anyhow::Result<FilterCondition>
|
||||
{
|
||||
let mut items = item.into_inner();
|
||||
let fid = field_id(fields_ids_map, filterable_fields, &mut items)?;
|
||||
|
@ -192,7 +192,7 @@ impl FacetCondition {
|
|||
fields_ids_map: &FieldsIdsMap,
|
||||
filterable_fields: &HashSet<FieldId>,
|
||||
item: Pair<Rule>,
|
||||
) -> anyhow::Result<FacetCondition>
|
||||
) -> anyhow::Result<FilterCondition>
|
||||
{
|
||||
let mut items = item.into_inner();
|
||||
let fid = field_id(fields_ids_map, filterable_fields, &mut items)?;
|
||||
|
@ -207,7 +207,7 @@ impl FacetCondition {
|
|||
fields_ids_map: &FieldsIdsMap,
|
||||
filterable_fields: &HashSet<FieldId>,
|
||||
item: Pair<Rule>,
|
||||
) -> anyhow::Result<FacetCondition>
|
||||
) -> anyhow::Result<FilterCondition>
|
||||
{
|
||||
let mut items = item.into_inner();
|
||||
let fid = field_id(fields_ids_map, filterable_fields, &mut items)?;
|
||||
|
@ -222,7 +222,7 @@ impl FacetCondition {
|
|||
fields_ids_map: &FieldsIdsMap,
|
||||
filterable_fields: &HashSet<FieldId>,
|
||||
item: Pair<Rule>,
|
||||
) -> anyhow::Result<FacetCondition>
|
||||
) -> anyhow::Result<FilterCondition>
|
||||
{
|
||||
let mut items = item.into_inner();
|
||||
let fid = field_id(fields_ids_map, filterable_fields, &mut items)?;
|
||||
|
@ -237,7 +237,7 @@ impl FacetCondition {
|
|||
fields_ids_map: &FieldsIdsMap,
|
||||
filterable_fields: &HashSet<FieldId>,
|
||||
item: Pair<Rule>,
|
||||
) -> anyhow::Result<FacetCondition>
|
||||
) -> anyhow::Result<FilterCondition>
|
||||
{
|
||||
let mut items = item.into_inner();
|
||||
let fid = field_id(fields_ids_map, filterable_fields, &mut items)?;
|
||||
|
@ -249,7 +249,7 @@ impl FacetCondition {
|
|||
}
|
||||
}
|
||||
|
||||
impl FacetCondition {
|
||||
impl FilterCondition {
|
||||
/// Aggregates the documents ids that are part of the specified range automatically
|
||||
/// going deeper through the levels.
|
||||
fn explore_facet_number_levels(
|
||||
|
@ -502,15 +502,15 @@ mod tests {
|
|||
|
||||
// Test that the facet condition is correctly generated.
|
||||
let rtxn = index.read_txn().unwrap();
|
||||
let condition = FacetCondition::from_str(&rtxn, &index, "channel = Ponce").unwrap();
|
||||
let condition = FilterCondition::from_str(&rtxn, &index, "channel = Ponce").unwrap();
|
||||
let expected = Operator(0, Operator::Equal(None, S("ponce")));
|
||||
assert_eq!(condition, expected);
|
||||
|
||||
let condition = FacetCondition::from_str(&rtxn, &index, "channel != ponce").unwrap();
|
||||
let condition = FilterCondition::from_str(&rtxn, &index, "channel != ponce").unwrap();
|
||||
let expected = Operator(0, Operator::NotEqual(None, S("ponce")));
|
||||
assert_eq!(condition, expected);
|
||||
|
||||
let condition = FacetCondition::from_str(&rtxn, &index, "NOT channel = ponce").unwrap();
|
||||
let condition = FilterCondition::from_str(&rtxn, &index, "NOT channel = ponce").unwrap();
|
||||
let expected = Operator(0, Operator::NotEqual(None, S("ponce")));
|
||||
assert_eq!(condition, expected);
|
||||
}
|
||||
|
@ -531,11 +531,11 @@ mod tests {
|
|||
|
||||
// Test that the facet condition is correctly generated.
|
||||
let rtxn = index.read_txn().unwrap();
|
||||
let condition = FacetCondition::from_str(&rtxn, &index, "timestamp 22 TO 44").unwrap();
|
||||
let condition = FilterCondition::from_str(&rtxn, &index, "timestamp 22 TO 44").unwrap();
|
||||
let expected = Operator(0, Between(22.0, 44.0));
|
||||
assert_eq!(condition, expected);
|
||||
|
||||
let condition = FacetCondition::from_str(&rtxn, &index, "NOT timestamp 22 TO 44").unwrap();
|
||||
let condition = FilterCondition::from_str(&rtxn, &index, "NOT timestamp 22 TO 44").unwrap();
|
||||
let expected = Or(
|
||||
Box::new(Operator(0, LowerThan(22.0))),
|
||||
Box::new(Operator(0, GreaterThan(44.0))),
|
||||
|
@ -560,7 +560,7 @@ mod tests {
|
|||
|
||||
// Test that the facet condition is correctly generated.
|
||||
let rtxn = index.read_txn().unwrap();
|
||||
let condition = FacetCondition::from_str(
|
||||
let condition = FilterCondition::from_str(
|
||||
&rtxn, &index,
|
||||
"channel = gotaga OR (timestamp 22 TO 44 AND channel != ponce)",
|
||||
).unwrap();
|
||||
|
@ -573,7 +573,7 @@ mod tests {
|
|||
);
|
||||
assert_eq!(condition, expected);
|
||||
|
||||
let condition = FacetCondition::from_str(
|
||||
let condition = FilterCondition::from_str(
|
||||
&rtxn, &index,
|
||||
"channel = gotaga OR NOT (timestamp 22 TO 44 AND channel != ponce)",
|
||||
).unwrap();
|
||||
|
@ -607,11 +607,11 @@ mod tests {
|
|||
|
||||
// Test that the facet condition is correctly generated.
|
||||
let rtxn = index.read_txn().unwrap();
|
||||
let condition = FacetCondition::from_array(
|
||||
let condition = FilterCondition::from_array(
|
||||
&rtxn, &index,
|
||||
vec![Either::Right("channel = gotaga"), Either::Left(vec!["timestamp = 44", "channel != ponce"])],
|
||||
).unwrap().unwrap();
|
||||
let expected = FacetCondition::from_str(
|
||||
let expected = FilterCondition::from_str(
|
||||
&rtxn, &index,
|
||||
"channel = gotaga AND (timestamp = 44 OR channel != ponce)",
|
||||
).unwrap();
|
|
@ -9,10 +9,10 @@ use crate::heed_codec::CboRoaringBitmapCodec;
|
|||
use crate::heed_codec::facet::FacetLevelValueF64Codec;
|
||||
use crate::{Index, FieldId};
|
||||
|
||||
pub use self::facet_condition::{FacetCondition, Operator};
|
||||
pub use self::filter_condition::{FilterCondition, Operator};
|
||||
pub use self::facet_distribution::FacetDistribution;
|
||||
|
||||
mod facet_condition;
|
||||
mod filter_condition;
|
||||
mod facet_distribution;
|
||||
mod parser;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ use distinct::{Distinct, DocIter, FacetDistinct, NoopDistinct};
|
|||
use crate::search::criteria::r#final::{Final, FinalResult};
|
||||
use crate::{Index, DocumentId};
|
||||
|
||||
pub use self::facet::{FacetCondition, FacetDistribution, FacetIter, Operator};
|
||||
pub use self::facet::{FilterCondition, FacetDistribution, FacetIter, Operator};
|
||||
pub use self::matching_words::MatchingWords;
|
||||
use self::query_tree::QueryTreeBuilder;
|
||||
|
||||
|
@ -33,7 +33,7 @@ mod matching_words;
|
|||
|
||||
pub struct Search<'a> {
|
||||
query: Option<String>,
|
||||
facet_condition: Option<FacetCondition>,
|
||||
filter: Option<FilterCondition>,
|
||||
offset: usize,
|
||||
limit: usize,
|
||||
optional_words: bool,
|
||||
|
@ -47,7 +47,7 @@ impl<'a> Search<'a> {
|
|||
pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index) -> Search<'a> {
|
||||
Search {
|
||||
query: None,
|
||||
facet_condition: None,
|
||||
filter: None,
|
||||
offset: 0,
|
||||
limit: 20,
|
||||
optional_words: true,
|
||||
|
@ -88,8 +88,8 @@ impl<'a> Search<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn facet_condition(&mut self, condition: FacetCondition) -> &mut Search<'a> {
|
||||
self.facet_condition = Some(condition);
|
||||
pub fn filter(&mut self, condition: FilterCondition) -> &mut Search<'a> {
|
||||
self.filter = Some(condition);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -121,12 +121,12 @@ impl<'a> Search<'a> {
|
|||
|
||||
// We create the original candidates with the facet conditions results.
|
||||
let before = Instant::now();
|
||||
let facet_candidates = match &self.facet_condition {
|
||||
let filtered_candidates = match &self.filter {
|
||||
Some(condition) => Some(condition.evaluate(self.rtxn, self.index)?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
debug!("facet candidates: {:?} took {:.02?}", facet_candidates, before.elapsed());
|
||||
debug!("facet candidates: {:?} took {:.02?}", filtered_candidates, before.elapsed());
|
||||
|
||||
let matching_words = match query_tree.as_ref() {
|
||||
Some(query_tree) => MatchingWords::from_query_tree(&query_tree),
|
||||
|
@ -134,7 +134,7 @@ impl<'a> Search<'a> {
|
|||
};
|
||||
|
||||
let criteria_builder = criteria::CriteriaBuilder::new(self.rtxn, self.index)?;
|
||||
let criteria = criteria_builder.build(query_tree, primitive_query, facet_candidates)?;
|
||||
let criteria = criteria_builder.build(query_tree, primitive_query, filtered_candidates)?;
|
||||
|
||||
match self.index.distinct_attribute(self.rtxn)? {
|
||||
None => self.perform_sort(NoopDistinct, matching_words, criteria),
|
||||
|
@ -188,7 +188,7 @@ impl fmt::Debug for Search<'_> {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let Search {
|
||||
query,
|
||||
facet_condition,
|
||||
filter,
|
||||
offset,
|
||||
limit,
|
||||
optional_words,
|
||||
|
@ -199,7 +199,7 @@ impl fmt::Debug for Search<'_> {
|
|||
} = self;
|
||||
f.debug_struct("Search")
|
||||
.field("query", query)
|
||||
.field("facet_condition", facet_condition)
|
||||
.field("filter", filter)
|
||||
.field("offset", offset)
|
||||
.field("limit", limit)
|
||||
.field("optional_words", optional_words)
|
||||
|
|
Loading…
Reference in New Issue