mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-03-06 13:51:03 +08:00
Check if the geo fields changed additionally to the other faceted fields when reindexing facets
This commit is contained in:
parent
19598ccd5c
commit
26fcde1a32
@ -1,5 +1,6 @@
|
|||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use heed::RoTxn;
|
use heed::RoTxn;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::document::{
|
use super::document::{
|
||||||
Document as _, DocumentFromDb, DocumentFromVersions, MergedDocument, Versions,
|
Document as _, DocumentFromDb, DocumentFromVersions, MergedDocument, Versions,
|
||||||
@ -10,7 +11,7 @@ use super::vector_document::{
|
|||||||
};
|
};
|
||||||
use crate::documents::FieldIdMapper;
|
use crate::documents::FieldIdMapper;
|
||||||
use crate::vector::EmbeddingConfigs;
|
use crate::vector::EmbeddingConfigs;
|
||||||
use crate::{DocumentId, Index, Result};
|
use crate::{DocumentId, Index, InternalError, Result};
|
||||||
|
|
||||||
pub enum DocumentChange<'doc> {
|
pub enum DocumentChange<'doc> {
|
||||||
Deletion(Deletion<'doc>),
|
Deletion(Deletion<'doc>),
|
||||||
@ -241,6 +242,29 @@ impl<'doc> Update<'doc> {
|
|||||||
Ok(has_deleted_fields)
|
Ok(has_deleted_fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the geo fields have changed.
|
||||||
|
pub fn has_changed_for_geo_fields<'t, Mapper: FieldIdMapper>(
|
||||||
|
&self,
|
||||||
|
rtxn: &'t RoTxn,
|
||||||
|
index: &'t Index,
|
||||||
|
mapper: &'t Mapper,
|
||||||
|
) -> Result<bool> {
|
||||||
|
let current = self.current(rtxn, index, mapper)?;
|
||||||
|
let current_geo = current.geo_field()?;
|
||||||
|
let updated_geo = self.only_changed_fields().geo_field()?;
|
||||||
|
match (current_geo, updated_geo) {
|
||||||
|
(Some(current_geo), Some(updated_geo)) => {
|
||||||
|
let current: Value =
|
||||||
|
serde_json::from_str(current_geo.get()).map_err(InternalError::SerdeJson)?;
|
||||||
|
let updated: Value =
|
||||||
|
serde_json::from_str(updated_geo.get()).map_err(InternalError::SerdeJson)?;
|
||||||
|
Ok(current != updated)
|
||||||
|
}
|
||||||
|
(None, None) => Ok(false),
|
||||||
|
_ => Ok(true),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn only_changed_vectors(
|
pub fn only_changed_vectors(
|
||||||
&self,
|
&self,
|
||||||
doc_alloc: &'doc Bump,
|
doc_alloc: &'doc Bump,
|
||||||
|
@ -97,12 +97,15 @@ impl FacetedDocidsExtractor {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
DocumentChange::Update(inner) => {
|
DocumentChange::Update(inner) => {
|
||||||
if !inner.has_changed_for_fields(
|
let has_changed = inner.has_changed_for_fields(
|
||||||
Some(attributes_to_extract),
|
Some(attributes_to_extract),
|
||||||
rtxn,
|
rtxn,
|
||||||
index,
|
index,
|
||||||
context.db_fields_ids_map,
|
context.db_fields_ids_map,
|
||||||
)? {
|
)?;
|
||||||
|
let has_changed_for_geo_fields =
|
||||||
|
inner.has_changed_for_geo_fields(rtxn, index, context.db_fields_ids_map)?;
|
||||||
|
if !has_changed && !has_changed_for_geo_fields {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user