stops storing the whole fieldids weights map when no searchable are defined

This commit is contained in:
Tamo
2024-05-15 17:16:10 +02:00
parent 7ec4e2a3fb
commit ad4d8502b3
3 changed files with 56 additions and 29 deletions

View File

@ -4,7 +4,7 @@ use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::{FieldId, Weight};
use crate::{FieldId, FieldsIdsMap, Weight};
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct FieldidsWeightsMap {
@ -19,6 +19,13 @@ impl FieldidsWeightsMap {
self.map.insert(fid, weight)
}
/// Create the map from the fields ids maps.
/// Should only be called in the case there are NO searchable attributes.
/// The weights and the fields ids will have the same values.
pub fn from_field_id_map_without_searchable(fid_map: &FieldsIdsMap) -> Self {
FieldidsWeightsMap { map: fid_map.ids().map(|fid| (fid, fid)).collect() }
}
/// Removes a field id from the map, returning the associated weight previously in the map.
pub fn remove(&mut self, fid: FieldId) -> Option<Weight> {
self.map.remove(&fid)