mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
Move fields frequency from common store to index main store
This commit is contained in:
parent
394976d330
commit
3286a5213c
@ -1,3 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use chrono::{DateTime, Utc};
|
||||
use crate::RankedMap;
|
||||
use heed::Result as ZResult;
|
||||
@ -7,6 +8,7 @@ use std::sync::Arc;
|
||||
|
||||
const CREATED_AT: &str = "created-at";
|
||||
const CUSTOMS_KEY: &str = "customs-key";
|
||||
const FIELDS_FREQUENCY: &str = "fields-frequency";
|
||||
const NAME: &str = "name";
|
||||
const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents";
|
||||
const RANKED_MAP_KEY: &str = "ranked-map";
|
||||
@ -16,6 +18,8 @@ const SYNONYMS_KEY: &str = "synonyms";
|
||||
const UPDATED_AT: &str = "updated-at";
|
||||
const WORDS_KEY: &str = "words";
|
||||
|
||||
pub type FreqsMap = HashMap<String, usize>;
|
||||
type SerdeFreqsMap = SerdeBincode<FreqsMap>;
|
||||
type SerdeDatetime = SerdeBincode<DateTime<Utc>>;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -144,6 +148,21 @@ impl Main {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put_fields_frequency(self, writer: &mut heed::RwTxn, fields_frequency: &FreqsMap) -> ZResult<()> {
|
||||
self.main
|
||||
.put::<Str, SerdeFreqsMap>(writer, FIELDS_FREQUENCY, fields_frequency)
|
||||
}
|
||||
|
||||
pub fn fields_frequency(&self, reader: &heed::RoTxn) -> ZResult<Option<FreqsMap>> {
|
||||
match self
|
||||
.main
|
||||
.get::<Str, SerdeFreqsMap>(&reader, FIELDS_FREQUENCY)?
|
||||
{
|
||||
Some(freqs) => Ok(Some(freqs)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put_customs(self, writer: &mut heed::RwTxn, customs: &[u8]) -> ZResult<()> {
|
||||
self.main
|
||||
.put::<Str, ByteSlice>(writer, CUSTOMS_KEY, customs)
|
||||
|
@ -5,14 +5,12 @@ use std::sync::Arc;
|
||||
use chrono::{DateTime, Utc};
|
||||
use heed::types::{SerdeBincode, Str};
|
||||
use log::*;
|
||||
use meilidb_core::{Database, MResult};
|
||||
use meilidb_core::{Database, MResult, Error as MError};
|
||||
use sysinfo::Pid;
|
||||
|
||||
use crate::option::Opt;
|
||||
use crate::routes::index::index_update_callback;
|
||||
|
||||
pub type FreqsMap = HashMap<String, usize>;
|
||||
type SerdeFreqsMap = SerdeBincode<FreqsMap>;
|
||||
type SerdeDatetime = SerdeBincode<DateTime<Utc>>;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -44,47 +42,25 @@ impl DataInner {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn last_update(
|
||||
&self,
|
||||
reader: &heed::RoTxn,
|
||||
index_uid: &str,
|
||||
) -> MResult<Option<DateTime<Utc>>> {
|
||||
let key = format!("last-update-{}", index_uid);
|
||||
pub fn last_update(&self, reader: &heed::RoTxn) -> MResult<Option<DateTime<Utc>>> {
|
||||
match self
|
||||
.db
|
||||
.common_store()
|
||||
.get::<Str, SerdeDatetime>(&reader, &key)?
|
||||
.get::<Str, SerdeDatetime>(&reader, "last-update")?
|
||||
{
|
||||
Some(datetime) => Ok(Some(datetime)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_last_update(&self, writer: &mut heed::RwTxn, index_uid: &str) -> MResult<()> {
|
||||
let key = format!("last-update-{}", index_uid);
|
||||
pub fn set_last_update(&self, writer: &mut heed::RwTxn) -> MResult<()> {
|
||||
self.db
|
||||
.common_store()
|
||||
.put::<Str, SerdeDatetime>(writer, &key, &Utc::now())
|
||||
.put::<Str, SerdeDatetime>(writer, "last-update", &Utc::now())
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn fields_frequency(
|
||||
&self,
|
||||
reader: &heed::RoTxn,
|
||||
index_uid: &str,
|
||||
) -> MResult<Option<FreqsMap>> {
|
||||
let key = format!("fields-frequency-{}", index_uid);
|
||||
match self
|
||||
.db
|
||||
.common_store()
|
||||
.get::<Str, SerdeFreqsMap>(&reader, &key)?
|
||||
{
|
||||
Some(freqs) => Ok(Some(freqs)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compute_stats(&self, writer: &mut heed::RwTxn, index_uid: &str) -> MResult<()> {
|
||||
pub fn compute_stats(&self, mut writer: &mut heed::RwTxn, index_uid: &str) -> MResult<()> {
|
||||
let index = match self.db.open_index(&index_uid) {
|
||||
Some(index) => index,
|
||||
None => {
|
||||
@ -115,12 +91,7 @@ impl DataInner {
|
||||
.map(|(a, c)| (schema.attribute_name(a).to_owned(), c))
|
||||
.collect();
|
||||
|
||||
let key = format!("fields-frequency-{}", index_uid);
|
||||
self.db
|
||||
.common_store()
|
||||
.put::<Str, SerdeFreqsMap>(writer, &key, &frequency)?;
|
||||
|
||||
Ok(())
|
||||
index.main.put_fields_frequency(&mut writer, &frequency).map_err(MError::Zlmdb)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user