Remove and Insert the DelAdd geo points

This commit is contained in:
Kerollmops 2023-10-23 13:49:54 +02:00 committed by Louis Dureuil
parent 544440c363
commit 77dcbff6b2
No known key found for this signature in database
2 changed files with 20 additions and 9 deletions

View File

@ -15,7 +15,6 @@ use crate::{FieldId, InternalError, Result};
/// Returns the generated grenad reader containing the docid as key associated to the (latitude, longitude) /// Returns the generated grenad reader containing the docid as key associated to the (latitude, longitude)
#[logging_timer::time] #[logging_timer::time]
pub fn extract_geo_points<R: io::Read + io::Seek>( pub fn extract_geo_points<R: io::Read + io::Seek>(
// TODO grenad::Reader<Obkv<FieldId, Obkv<DelAdd, JsonValue>>>
obkv_documents: grenad::Reader<R>, obkv_documents: grenad::Reader<R>,
indexer: GrenadParameters, indexer: GrenadParameters,
primary_key_id: FieldId, primary_key_id: FieldId,

View File

@ -279,15 +279,18 @@ pub(crate) fn write_typed_chunk_into_index(
// convert the key back to a u32 (4 bytes) // convert the key back to a u32 (4 bytes)
let docid = key.try_into().map(DocumentId::from_be_bytes).unwrap(); let docid = key.try_into().map(DocumentId::from_be_bytes).unwrap();
// convert the latitude and longitude back to a f64 (8 bytes) let deladd_obkv = KvReaderDelAdd::new(value);
let (lat, tail) = helpers::try_split_array_at::<u8, 8>(value).unwrap(); if let Some(value) = deladd_obkv.get(DelAdd::Deletion) {
let (lng, _) = helpers::try_split_array_at::<u8, 8>(tail).unwrap(); let geopoint = extract_geo_point(value, docid);
let point = [f64::from_ne_bytes(lat), f64::from_ne_bytes(lng)]; rtree.remove(&geopoint);
let xyz_point = lat_lng_to_xyz(&point); geo_faceted_docids.remove(docid);
}
rtree.insert(GeoPoint::new(xyz_point, (docid, point))); if let Some(value) = deladd_obkv.get(DelAdd::Addition) {
let geopoint = extract_geo_point(value, docid);
rtree.insert(geopoint);
geo_faceted_docids.insert(docid); geo_faceted_docids.insert(docid);
} }
}
index.put_geo_rtree(wtxn, &rtree)?; index.put_geo_rtree(wtxn, &rtree)?;
index.put_geo_faceted_documents_ids(wtxn, &geo_faceted_docids)?; index.put_geo_faceted_documents_ids(wtxn, &geo_faceted_docids)?;
} }
@ -368,6 +371,15 @@ pub(crate) fn write_typed_chunk_into_index(
Ok((RoaringBitmap::new(), is_merged_database)) Ok((RoaringBitmap::new(), is_merged_database))
} }
/// Converts the latitude and longitude back to an xyz GeoPoint.
fn extract_geo_point(value: &[u8], docid: DocumentId) -> GeoPoint {
let (lat, tail) = helpers::try_split_array_at::<u8, 8>(value).unwrap();
let (lng, _) = helpers::try_split_array_at::<u8, 8>(tail).unwrap();
let point = [f64::from_ne_bytes(lat), f64::from_ne_bytes(lng)];
let xyz_point = lat_lng_to_xyz(&point);
GeoPoint::new(xyz_point, (docid, point))
}
fn merge_word_docids_reader_into_fst( fn merge_word_docids_reader_into_fst(
word_docids_iter: grenad::Reader<io::Cursor<ClonableMmap>>, word_docids_iter: grenad::Reader<io::Cursor<ClonableMmap>>,
exact_word_docids_iter: grenad::Reader<io::Cursor<ClonableMmap>>, exact_word_docids_iter: grenad::Reader<io::Cursor<ClonableMmap>>,