start updating the exposed function to makes other modules happy

This commit is contained in:
Tamo 2021-10-22 17:23:22 +02:00
parent 6c9165b6a8
commit e25ca9776f
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69
7 changed files with 24 additions and 12 deletions

View File

@ -262,7 +262,7 @@ impl Search {
} }
if let Some(ref filter) = self.filter { if let Some(ref filter) = self.filter {
let condition = milli::FilterCondition::from_str(&txn, &index, filter)?; let condition = milli::Filter::from_str(filter)?;
search.filter(condition); search.filter(condition);
} }

View File

@ -24,7 +24,8 @@ use milli::documents::DocumentBatchReader;
use milli::update::UpdateIndexingStep::*; use milli::update::UpdateIndexingStep::*;
use milli::update::{IndexDocumentsMethod, Setting, UpdateBuilder}; use milli::update::{IndexDocumentsMethod, Setting, UpdateBuilder};
use milli::{ use milli::{
obkv_to_json, CompressionType, FilterCondition, Index, MatchingWords, SearchResult, SortError, obkv_to_json, CompressionType, Filter as MilliFilter, FilterCondition, Index, MatchingWords,
SearchResult, SortError,
}; };
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use rayon::ThreadPool; use rayon::ThreadPool;
@ -739,7 +740,7 @@ async fn main() -> anyhow::Result<()> {
let filters = match query.filters { let filters = match query.filters {
Some(condition) if !condition.trim().is_empty() => { Some(condition) if !condition.trim().is_empty() => {
Some(FilterCondition::from_str(&rtxn, &index, &condition).unwrap()) Some(MilliFilter::from_str(&condition).unwrap())
} }
_otherwise => None, _otherwise => None,
}; };
@ -747,7 +748,7 @@ async fn main() -> anyhow::Result<()> {
let facet_filters = match query.facet_filters { let facet_filters = match query.facet_filters {
Some(array) => { Some(array) => {
let eithers = array.into_iter().map(Into::into); let eithers = array.into_iter().map(Into::into);
FilterCondition::from_array(&rtxn, &index, eithers).unwrap() MilliFilter::from_array(eithers).unwrap()
} }
_otherwise => None, _otherwise => None,
}; };

View File

@ -2,5 +2,7 @@ mod facet_type;
mod facet_value; mod facet_value;
pub mod value_encoding; pub mod value_encoding;
pub use filter_parser::{Condition, FilterCondition, FilterParserError, Span, Token};
pub use self::facet_type::FacetType; pub use self::facet_type::FacetType;
pub use self::facet_value::FacetValue; pub use self::facet_value::FacetValue;

View File

@ -34,7 +34,9 @@ pub use self::heed_codec::{
RoaringBitmapLenCodec, StrBEU32Codec, StrStrU8Codec, RoaringBitmapLenCodec, StrBEU32Codec, StrStrU8Codec,
}; };
pub use self::index::Index; pub use self::index::Index;
pub use self::search::{FacetDistribution, Filter, MatchingWords, Search, SearchResult}; pub use self::search::{
Condition, FacetDistribution, Filter, FilterCondition, MatchingWords, Search, SearchResult,
};
pub type Result<T> = std::result::Result<T, error::Error>; pub type Result<T> = std::result::Result<T, error::Error>;

View File

@ -3,7 +3,7 @@ use std::ops::Bound::{self, Excluded, Included};
use std::str::FromStr; use std::str::FromStr;
use either::Either; use either::Either;
use filter_parser::{Condition, FilterCondition, FilterParserError, Span, Token}; pub use filter_parser::{Condition, FilterCondition, FilterParserError, Span, Token};
use heed::types::DecodeIgnore; use heed::types::DecodeIgnore;
use log::debug; use log::debug;
use nom::error::{ErrorKind, VerboseError}; use nom::error::{ErrorKind, VerboseError};
@ -209,7 +209,7 @@ impl<'a> Filter<'a> {
// Make sure we always bound the ranges with the field id and the level, // Make sure we always bound the ranges with the field id and the level,
// as the facets values are all in the same database and prefixed by the // as the facets values are all in the same database and prefixed by the
// field id and the level. // field id and the level.
// TODO TAMO: return good error when we can't parse a span
let (left, right) = match operator { let (left, right) = match operator {
Condition::GreaterThan(val) => (Excluded(parse(val)?), Included(f64::MAX)), Condition::GreaterThan(val) => (Excluded(parse(val)?), Included(f64::MAX)),
Condition::GreaterThanOrEqual(val) => (Included(parse(val)?), Included(f64::MAX)), Condition::GreaterThanOrEqual(val) => (Included(parse(val)?), Included(f64::MAX)),
@ -315,10 +315,15 @@ impl<'a> Filter<'a> {
match &self.condition { match &self.condition {
FilterCondition::Condition { fid, op } => { FilterCondition::Condition { fid, op } => {
// TODO: parse fid let filterable_fields = index.fields_ids_map(rtxn)?;
let _ = fid; if let Some(fid) = filterable_fields.id(fid.inner) {
let fid = 42;
Self::evaluate_operator(rtxn, index, numbers_db, strings_db, fid, &op) Self::evaluate_operator(rtxn, index, numbers_db, strings_db, fid, &op)
} else {
// TODO TAMO: update the error message
return Err(UserError::InvalidFilter {
input: format!("Bad filter, available filters are {:?}", filterable_fields),
})?;
}
} }
FilterCondition::Or(lhs, rhs) => { FilterCondition::Or(lhs, rhs) => {
let lhs = Self::evaluate(&(lhs.as_ref().clone()).into(), rtxn, index)?; let lhs = Self::evaluate(&(lhs.as_ref().clone()).into(), rtxn, index)?;

View File

@ -1,3 +1,5 @@
pub use filter_parser::{Condition, FilterCondition};
pub use self::facet_distribution::FacetDistribution; pub use self::facet_distribution::FacetDistribution;
pub use self::facet_number::{FacetNumberIter, FacetNumberRange, FacetNumberRevRange}; pub use self::facet_number::{FacetNumberIter, FacetNumberRange, FacetNumberRevRange};
pub use self::facet_string::FacetStringIter; pub use self::facet_string::FacetStringIter;

View File

@ -14,7 +14,7 @@ use meilisearch_tokenizer::{Analyzer, AnalyzerConfig};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use roaring::bitmap::RoaringBitmap; use roaring::bitmap::RoaringBitmap;
pub use self::facet::{FacetDistribution, FacetNumberIter, Filter}; pub use self::facet::{Condition, FacetDistribution, FacetNumberIter, Filter, FilterCondition};
pub use self::matching_words::MatchingWords; pub use self::matching_words::MatchingWords;
use self::query_tree::QueryTreeBuilder; use self::query_tree::QueryTreeBuilder;
use crate::error::UserError; use crate::error::UserError;