mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
squash-me
This commit is contained in:
parent
2ee90a891c
commit
bbe1845f66
20 changed files with 1118 additions and 676 deletions
|
@ -3,7 +3,7 @@ use crate::database::MainT;
|
|||
use crate::DocumentId;
|
||||
use heed::types::OwnedType;
|
||||
use heed::Result as ZResult;
|
||||
use meilisearch_schema::SchemaAttr;
|
||||
use meilisearch_schema::FieldId;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct DocumentsFieldsCounts {
|
||||
|
@ -15,7 +15,7 @@ impl DocumentsFieldsCounts {
|
|||
self,
|
||||
writer: &mut heed::RwTxn<MainT>,
|
||||
document_id: DocumentId,
|
||||
attribute: SchemaAttr,
|
||||
attribute: FieldId,
|
||||
value: u16,
|
||||
) -> ZResult<()> {
|
||||
let key = DocumentAttrKey::new(document_id, attribute);
|
||||
|
@ -27,8 +27,8 @@ impl DocumentsFieldsCounts {
|
|||
writer: &mut heed::RwTxn<MainT>,
|
||||
document_id: DocumentId,
|
||||
) -> ZResult<usize> {
|
||||
let start = DocumentAttrKey::new(document_id, SchemaAttr::min());
|
||||
let end = DocumentAttrKey::new(document_id, SchemaAttr::max());
|
||||
let start = DocumentAttrKey::new(document_id, FieldId::min());
|
||||
let end = DocumentAttrKey::new(document_id, FieldId::max());
|
||||
self.documents_fields_counts
|
||||
.delete_range(writer, &(start..=end))
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ impl DocumentsFieldsCounts {
|
|||
self,
|
||||
reader: &heed::RoTxn<MainT>,
|
||||
document_id: DocumentId,
|
||||
attribute: SchemaAttr,
|
||||
attribute: FieldId,
|
||||
) -> ZResult<Option<u16>> {
|
||||
let key = DocumentAttrKey::new(document_id, attribute);
|
||||
match self.documents_fields_counts.get(reader, &key)? {
|
||||
|
@ -55,8 +55,8 @@ impl DocumentsFieldsCounts {
|
|||
reader: &'txn heed::RoTxn<MainT>,
|
||||
document_id: DocumentId,
|
||||
) -> ZResult<DocumentFieldsCountsIter<'txn>> {
|
||||
let start = DocumentAttrKey::new(document_id, SchemaAttr::min());
|
||||
let end = DocumentAttrKey::new(document_id, SchemaAttr::max());
|
||||
let start = DocumentAttrKey::new(document_id, FieldId::min());
|
||||
let end = DocumentAttrKey::new(document_id, FieldId::max());
|
||||
let iter = self.documents_fields_counts.range(reader, &(start..=end))?;
|
||||
Ok(DocumentFieldsCountsIter { iter })
|
||||
}
|
||||
|
@ -83,12 +83,12 @@ pub struct DocumentFieldsCountsIter<'txn> {
|
|||
}
|
||||
|
||||
impl Iterator for DocumentFieldsCountsIter<'_> {
|
||||
type Item = ZResult<(SchemaAttr, u16)>;
|
||||
type Item = ZResult<(FieldId, u16)>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.iter.next() {
|
||||
Some(Ok((key, count))) => {
|
||||
let attr = SchemaAttr(key.attr.get());
|
||||
let attr = FieldId(key.attr.get());
|
||||
Some(Ok((attr, count)))
|
||||
}
|
||||
Some(Err(e)) => Some(Err(e)),
|
||||
|
@ -127,13 +127,13 @@ pub struct AllDocumentsFieldsCountsIter<'txn> {
|
|||
}
|
||||
|
||||
impl Iterator for AllDocumentsFieldsCountsIter<'_> {
|
||||
type Item = ZResult<(DocumentId, SchemaAttr, u16)>;
|
||||
type Item = ZResult<(DocumentId, FieldId, u16)>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.iter.next() {
|
||||
Some(Ok((key, count))) => {
|
||||
let docid = DocumentId(key.docid.get());
|
||||
let attr = SchemaAttr(key.attr.get());
|
||||
let attr = FieldId(key.attr.get());
|
||||
Some(Ok((docid, attr, count)))
|
||||
}
|
||||
Some(Err(e)) => Some(Err(e)),
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::fields_map::FieldsMap;
|
||||
use crate::database::MainT;
|
||||
use crate::RankedMap;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
@ -17,6 +18,7 @@ const FIELDS_FREQUENCY_KEY: &str = "fields-frequency";
|
|||
const NAME_KEY: &str = "name";
|
||||
const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents";
|
||||
const RANKED_MAP_KEY: &str = "ranked-map";
|
||||
const FIELDS_MAP_KEY: &str = "fields-map";
|
||||
const SCHEMA_KEY: &str = "schema";
|
||||
const UPDATED_AT_KEY: &str = "updated-at";
|
||||
const WORDS_KEY: &str = "words";
|
||||
|
@ -112,6 +114,16 @@ impl Main {
|
|||
.get::<_, Str, SerdeBincode<RankedMap>>(reader, RANKED_MAP_KEY)
|
||||
}
|
||||
|
||||
pub fn put_fields_map(self, writer: &mut heed::RwTxn<MainT>, fields_map: &FieldsMap) -> ZResult<()> {
|
||||
self.main
|
||||
.put::<_, Str, SerdeBincode<FieldsMap>>(writer, FIELDS_MAP_KEY, &fields_map)
|
||||
}
|
||||
|
||||
pub fn fields_map(self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<FieldsMap>> {
|
||||
self.main
|
||||
.get::<_, Str, SerdeBincode<FieldsMap>>(reader, FIELDS_MAP_KEY)
|
||||
}
|
||||
|
||||
pub fn put_synonyms_fst(self, writer: &mut heed::RwTxn<MainT>, fst: &fst::Set) -> ZResult<()> {
|
||||
let bytes = fst.as_fst().as_bytes();
|
||||
self.main.put::<_, Str, ByteSlice>(writer, SYNONYMS_KEY, bytes)
|
||||
|
|
|
@ -206,11 +206,10 @@ impl Index {
|
|||
let schema = self.main.schema(reader)?;
|
||||
let schema = schema.ok_or(Error::SchemaMissing)?;
|
||||
|
||||
// let attributes = attributes.map(|a| a.iter().filter_map(|name| schema.get_id(*name)).collect());
|
||||
|
||||
let attributes = match attributes {
|
||||
Some(attributes) => attributes
|
||||
.iter()
|
||||
.map(|name| schema.attribute(name))
|
||||
.collect(),
|
||||
Some(attributes) => Some(attributes.iter().filter_map(|name| schema.get_id(*name)).collect()),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue