mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-19 01:18:31 +08:00
Print the Asc/Desc criterion field name in the debug prints
This commit is contained in:
parent
08a0ff7091
commit
a58d2b6137
@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::mem::take;
|
use std::mem::take;
|
||||||
|
|
||||||
use anyhow::bail;
|
use anyhow::{bail, Context as _};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use ordered_float::OrderedFloat;
|
use ordered_float::OrderedFloat;
|
||||||
@ -13,12 +13,13 @@ use crate::heed_codec::facet::{FieldDocIdFacetI64Codec, FieldDocIdFacetF64Codec}
|
|||||||
use crate::search::criteria::{resolve_query_tree, CriteriaBuilder};
|
use crate::search::criteria::{resolve_query_tree, CriteriaBuilder};
|
||||||
use crate::search::facet::FacetIter;
|
use crate::search::facet::FacetIter;
|
||||||
use crate::search::query_tree::Operation;
|
use crate::search::query_tree::Operation;
|
||||||
use crate::{FieldId, Index};
|
use crate::{FieldsIdsMap, FieldId, Index};
|
||||||
use super::{Criterion, CriterionResult};
|
use super::{Criterion, CriterionResult};
|
||||||
|
|
||||||
pub struct AscDesc<'t> {
|
pub struct AscDesc<'t> {
|
||||||
index: &'t Index,
|
index: &'t Index,
|
||||||
rtxn: &'t heed::RoTxn<'t>,
|
rtxn: &'t heed::RoTxn<'t>,
|
||||||
|
field_name: String,
|
||||||
field_id: FieldId,
|
field_id: FieldId,
|
||||||
facet_type: FacetType,
|
facet_type: FacetType,
|
||||||
ascending: bool,
|
ascending: bool,
|
||||||
@ -35,11 +36,10 @@ impl<'t> AscDesc<'t> {
|
|||||||
rtxn: &'t heed::RoTxn,
|
rtxn: &'t heed::RoTxn,
|
||||||
query_tree: Option<Operation>,
|
query_tree: Option<Operation>,
|
||||||
candidates: Option<RoaringBitmap>,
|
candidates: Option<RoaringBitmap>,
|
||||||
field_id: FieldId,
|
field_name: String,
|
||||||
facet_type: FacetType,
|
|
||||||
) -> anyhow::Result<Self>
|
) -> anyhow::Result<Self>
|
||||||
{
|
{
|
||||||
Self::initial(index, rtxn, query_tree, candidates, field_id, facet_type, true)
|
Self::initial(index, rtxn, query_tree, candidates, field_name, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initial_desc(
|
pub fn initial_desc(
|
||||||
@ -47,33 +47,30 @@ impl<'t> AscDesc<'t> {
|
|||||||
rtxn: &'t heed::RoTxn,
|
rtxn: &'t heed::RoTxn,
|
||||||
query_tree: Option<Operation>,
|
query_tree: Option<Operation>,
|
||||||
candidates: Option<RoaringBitmap>,
|
candidates: Option<RoaringBitmap>,
|
||||||
field_id: FieldId,
|
field_name: String,
|
||||||
facet_type: FacetType,
|
|
||||||
) -> anyhow::Result<Self>
|
) -> anyhow::Result<Self>
|
||||||
{
|
{
|
||||||
Self::initial(index, rtxn, query_tree, candidates, field_id, facet_type, false)
|
Self::initial(index, rtxn, query_tree, candidates, field_name, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn asc(
|
pub fn asc(
|
||||||
index: &'t Index,
|
index: &'t Index,
|
||||||
rtxn: &'t heed::RoTxn,
|
rtxn: &'t heed::RoTxn,
|
||||||
parent: Box<dyn Criterion + 't>,
|
parent: Box<dyn Criterion + 't>,
|
||||||
field_id: FieldId,
|
field_name: String,
|
||||||
facet_type: FacetType,
|
|
||||||
) -> anyhow::Result<Self>
|
) -> anyhow::Result<Self>
|
||||||
{
|
{
|
||||||
Self::new(index, rtxn, parent, field_id, facet_type, true)
|
Self::new(index, rtxn, parent, field_name, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn desc(
|
pub fn desc(
|
||||||
index: &'t Index,
|
index: &'t Index,
|
||||||
rtxn: &'t heed::RoTxn,
|
rtxn: &'t heed::RoTxn,
|
||||||
parent: Box<dyn Criterion + 't>,
|
parent: Box<dyn Criterion + 't>,
|
||||||
field_id: FieldId,
|
field_name: String,
|
||||||
facet_type: FacetType,
|
|
||||||
) -> anyhow::Result<Self>
|
) -> anyhow::Result<Self>
|
||||||
{
|
{
|
||||||
Self::new(index, rtxn, parent, field_id, facet_type, false)
|
Self::new(index, rtxn, parent, field_name, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial(
|
fn initial(
|
||||||
@ -81,11 +78,14 @@ impl<'t> AscDesc<'t> {
|
|||||||
rtxn: &'t heed::RoTxn,
|
rtxn: &'t heed::RoTxn,
|
||||||
query_tree: Option<Operation>,
|
query_tree: Option<Operation>,
|
||||||
candidates: Option<RoaringBitmap>,
|
candidates: Option<RoaringBitmap>,
|
||||||
field_id: FieldId,
|
field_name: String,
|
||||||
facet_type: FacetType,
|
|
||||||
ascending: bool,
|
ascending: bool,
|
||||||
) -> anyhow::Result<Self>
|
) -> anyhow::Result<Self>
|
||||||
{
|
{
|
||||||
|
let fields_ids_map = index.fields_ids_map(rtxn)?;
|
||||||
|
let faceted_fields = index.faceted_fields(rtxn)?;
|
||||||
|
let (field_id, facet_type) = field_id_facet_type(&fields_ids_map, &faceted_fields, &field_name)?;
|
||||||
|
|
||||||
let faceted_candidates = index.faceted_documents_ids(rtxn, field_id)?;
|
let faceted_candidates = index.faceted_documents_ids(rtxn, field_id)?;
|
||||||
let candidates = match &query_tree {
|
let candidates = match &query_tree {
|
||||||
Some(qt) => {
|
Some(qt) => {
|
||||||
@ -102,6 +102,7 @@ impl<'t> AscDesc<'t> {
|
|||||||
Ok(AscDesc {
|
Ok(AscDesc {
|
||||||
index,
|
index,
|
||||||
rtxn,
|
rtxn,
|
||||||
|
field_name,
|
||||||
field_id,
|
field_id,
|
||||||
facet_type,
|
facet_type,
|
||||||
ascending,
|
ascending,
|
||||||
@ -117,14 +118,18 @@ impl<'t> AscDesc<'t> {
|
|||||||
index: &'t Index,
|
index: &'t Index,
|
||||||
rtxn: &'t heed::RoTxn,
|
rtxn: &'t heed::RoTxn,
|
||||||
parent: Box<dyn Criterion + 't>,
|
parent: Box<dyn Criterion + 't>,
|
||||||
field_id: FieldId,
|
field_name: String,
|
||||||
facet_type: FacetType,
|
|
||||||
ascending: bool,
|
ascending: bool,
|
||||||
) -> anyhow::Result<Self>
|
) -> anyhow::Result<Self>
|
||||||
{
|
{
|
||||||
|
let fields_ids_map = index.fields_ids_map(rtxn)?;
|
||||||
|
let faceted_fields = index.faceted_fields(rtxn)?;
|
||||||
|
let (field_id, facet_type) = field_id_facet_type(&fields_ids_map, &faceted_fields, &field_name)?;
|
||||||
|
|
||||||
Ok(AscDesc {
|
Ok(AscDesc {
|
||||||
index,
|
index,
|
||||||
rtxn,
|
rtxn,
|
||||||
|
field_name,
|
||||||
field_id,
|
field_id,
|
||||||
facet_type,
|
facet_type,
|
||||||
ascending,
|
ascending,
|
||||||
@ -140,8 +145,8 @@ impl<'t> AscDesc<'t> {
|
|||||||
impl<'t> Criterion for AscDesc<'t> {
|
impl<'t> Criterion for AscDesc<'t> {
|
||||||
fn next(&mut self) -> anyhow::Result<Option<CriterionResult>> {
|
fn next(&mut self) -> anyhow::Result<Option<CriterionResult>> {
|
||||||
loop {
|
loop {
|
||||||
debug!("Facet {} iteration ({:?})",
|
debug!("Facet {}({}) iteration ({:?})",
|
||||||
if self.ascending { "Asc" } else { "Desc" }, self.candidates,
|
if self.ascending { "Asc" } else { "Desc" }, self.field_name, self.candidates,
|
||||||
);
|
);
|
||||||
|
|
||||||
match &mut self.candidates {
|
match &mut self.candidates {
|
||||||
@ -197,6 +202,21 @@ impl<'t> Criterion for AscDesc<'t> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn field_id_facet_type(
|
||||||
|
fields_ids_map: &FieldsIdsMap,
|
||||||
|
faceted_fields: &HashMap<String, FacetType>,
|
||||||
|
field: &str,
|
||||||
|
) -> anyhow::Result<(FieldId, FacetType)>
|
||||||
|
{
|
||||||
|
let id = fields_ids_map.id(field).with_context(|| {
|
||||||
|
format!("field {:?} isn't registered", field)
|
||||||
|
})?;
|
||||||
|
let facet_type = faceted_fields.get(field).with_context(|| {
|
||||||
|
format!("field {:?} isn't faceted", field)
|
||||||
|
})?;
|
||||||
|
Ok((id, *facet_type))
|
||||||
|
}
|
||||||
|
|
||||||
fn facet_ordered(
|
fn facet_ordered(
|
||||||
index: &Index,
|
index: &Index,
|
||||||
rtxn: &heed::RoTxn,
|
rtxn: &heed::RoTxn,
|
||||||
|
@ -122,18 +122,6 @@ impl<'t> CriteriaBuilder<'t> {
|
|||||||
{
|
{
|
||||||
use crate::criterion::Criterion as Name;
|
use crate::criterion::Criterion as Name;
|
||||||
|
|
||||||
let fields_ids_map = self.index.fields_ids_map(&self.rtxn)?;
|
|
||||||
let faceted_fields = self.index.faceted_fields(&self.rtxn)?;
|
|
||||||
let field_id_facet_type = |field: &str| -> anyhow::Result<(FieldId, FacetType)> {
|
|
||||||
let id = fields_ids_map.id(field).with_context(|| {
|
|
||||||
format!("field {:?} isn't registered", field)
|
|
||||||
})?;
|
|
||||||
let facet_type = faceted_fields.get(field).with_context(|| {
|
|
||||||
format!("field {:?} isn't faceted", field)
|
|
||||||
})?;
|
|
||||||
Ok((id, *facet_type))
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut criterion = None as Option<Box<dyn Criterion>>;
|
let mut criterion = None as Option<Box<dyn Criterion>>;
|
||||||
for name in self.index.criteria(&self.rtxn)? {
|
for name in self.index.criteria(&self.rtxn)? {
|
||||||
criterion = Some(match criterion.take() {
|
criterion = Some(match criterion.take() {
|
||||||
@ -141,14 +129,8 @@ impl<'t> CriteriaBuilder<'t> {
|
|||||||
Name::Typo => Box::new(Typo::new(self, father)),
|
Name::Typo => Box::new(Typo::new(self, father)),
|
||||||
Name::Words => Box::new(Words::new(self, father)),
|
Name::Words => Box::new(Words::new(self, father)),
|
||||||
Name::Proximity => Box::new(Proximity::new(self, father)),
|
Name::Proximity => Box::new(Proximity::new(self, father)),
|
||||||
Name::Asc(field) => {
|
Name::Asc(field) => Box::new(AscDesc::asc(&self.index, &self.rtxn, father, field)?),
|
||||||
let (id, facet_type) = field_id_facet_type(&field)?;
|
Name::Desc(field) => Box::new(AscDesc::desc(&self.index, &self.rtxn, father, field)?),
|
||||||
Box::new(AscDesc::asc(&self.index, &self.rtxn, father, id, facet_type)?)
|
|
||||||
},
|
|
||||||
Name::Desc(field) => {
|
|
||||||
let (id, facet_type) = field_id_facet_type(&field)?;
|
|
||||||
Box::new(AscDesc::desc(&self.index, &self.rtxn, father, id, facet_type)?)
|
|
||||||
},
|
|
||||||
_otherwise => father,
|
_otherwise => father,
|
||||||
},
|
},
|
||||||
None => match name {
|
None => match name {
|
||||||
@ -156,12 +138,10 @@ impl<'t> CriteriaBuilder<'t> {
|
|||||||
Name::Words => Box::new(Words::initial(self, query_tree.take(), facet_candidates.take())),
|
Name::Words => Box::new(Words::initial(self, query_tree.take(), facet_candidates.take())),
|
||||||
Name::Proximity => Box::new(Proximity::initial(self, query_tree.take(), facet_candidates.take())),
|
Name::Proximity => Box::new(Proximity::initial(self, query_tree.take(), facet_candidates.take())),
|
||||||
Name::Asc(field) => {
|
Name::Asc(field) => {
|
||||||
let (id, facet_type) = field_id_facet_type(&field)?;
|
Box::new(AscDesc::initial_asc(&self.index, &self.rtxn, query_tree.take(), facet_candidates.take(), field)?)
|
||||||
Box::new(AscDesc::initial_asc(&self.index, &self.rtxn, query_tree.take(), facet_candidates.take(), id, facet_type)?)
|
|
||||||
},
|
},
|
||||||
Name::Desc(field) => {
|
Name::Desc(field) => {
|
||||||
let (id, facet_type) = field_id_facet_type(&field)?;
|
Box::new(AscDesc::initial_desc(&self.index, &self.rtxn, query_tree.take(), facet_candidates.take(), field)?)
|
||||||
Box::new(AscDesc::initial_desc(&self.index, &self.rtxn, query_tree.take(), facet_candidates.take(), id, facet_type)?)
|
|
||||||
},
|
},
|
||||||
_otherwise => continue,
|
_otherwise => continue,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user