diff --git a/meilisearch-core/src/criterion/exact.rs b/meilisearch-core/src/criterion/exact.rs index e9ae1b5dc..c3e7aba9c 100644 --- a/meilisearch-core/src/criterion/exact.rs +++ b/meilisearch-core/src/criterion/exact.rs @@ -12,7 +12,7 @@ fn number_exact_matches( query_index: &[u32], attribute: &[u16], is_exact: &[bool], - fields_counts: &Set<(SchemaAttr, u64)>, + fields_counts: &Set<(SchemaAttr, u16)>, ) -> usize { let mut count = 0; let mut index = 0; diff --git a/meilisearch-core/src/lib.rs b/meilisearch-core/src/lib.rs index e9ba84a41..0bc07e27e 100644 --- a/meilisearch-core/src/lib.rs +++ b/meilisearch-core/src/lib.rs @@ -25,7 +25,7 @@ pub use self::ranked_map::RankedMap; pub use self::raw_document::RawDocument; pub use self::store::Index; pub use self::update::{EnqueuedUpdateResult, ProcessedUpdateResult, UpdateStatus, UpdateType}; -pub use meilisearch_types::{DocIndex, DocumentId, Highlight}; +pub use meilisearch_types::{DocIndex, DocumentId, Highlight, AttrCount}; #[doc(hidden)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/meilisearch-core/src/query_builder.rs b/meilisearch-core/src/query_builder.rs index 132dda557..87b4e9021 100644 --- a/meilisearch-core/src/query_builder.rs +++ b/meilisearch-core/src/query_builder.rs @@ -815,7 +815,7 @@ mod tests { let mut words_fst = BTreeSet::new(); let mut postings_lists = HashMap::new(); - let mut fields_counts = HashMap::<_, u64>::new(); + let mut fields_counts = HashMap::<_, u16>::new(); for (word, indexes) in iter { let word = word.to_lowercase().into_bytes(); diff --git a/meilisearch-core/src/raw_document.rs b/meilisearch-core/src/raw_document.rs index 291e532be..1ecb9322d 100644 --- a/meilisearch-core/src/raw_document.rs +++ b/meilisearch-core/src/raw_document.rs @@ -12,7 +12,7 @@ pub struct RawDocument { pub id: DocumentId, pub matches: SharedMatches, pub highlights: Vec, - pub fields_counts: SetBuf<(SchemaAttr, u64)>, + pub fields_counts: SetBuf<(SchemaAttr, u16)>, } impl RawDocument { @@ -101,7 +101,7 @@ impl fmt::Debug for RawDocument { pub fn raw_documents_from( matches: SetBuf<(DocumentId, TmpMatch)>, highlights: SetBuf<(DocumentId, Highlight)>, - fields_counts: SetBuf<(DocumentId, SchemaAttr, u64)>, + fields_counts: SetBuf<(DocumentId, SchemaAttr, u16)>, ) -> Vec { let mut docs_ranges: Vec<(_, Range, _, _)> = Vec::new(); let mut matches2 = Matches::with_capacity(matches.len()); diff --git a/meilisearch-core/src/serde/serializer.rs b/meilisearch-core/src/serde/serializer.rs index c083991f5..2016cd314 100644 --- a/meilisearch-core/src/serde/serializer.rs +++ b/meilisearch-core/src/serde/serializer.rs @@ -325,7 +325,7 @@ where txn, document_id, attribute, - number_of_words as u64, + number_of_words as u16, )?; } } diff --git a/meilisearch-core/src/store/documents_fields_counts.rs b/meilisearch-core/src/store/documents_fields_counts.rs index 72ac7a2f8..0a7eb1bbf 100644 --- a/meilisearch-core/src/store/documents_fields_counts.rs +++ b/meilisearch-core/src/store/documents_fields_counts.rs @@ -7,7 +7,7 @@ use meilisearch_schema::SchemaAttr; #[derive(Copy, Clone)] pub struct DocumentsFieldsCounts { - pub(crate) documents_fields_counts: heed::Database, OwnedType>, + pub(crate) documents_fields_counts: heed::Database, OwnedType>, } impl DocumentsFieldsCounts { @@ -16,7 +16,7 @@ impl DocumentsFieldsCounts { writer: &mut heed::RwTxn, document_id: DocumentId, attribute: SchemaAttr, - value: u64, + value: u16, ) -> ZResult<()> { let key = DocumentAttrKey::new(document_id, attribute); self.documents_fields_counts.put(writer, &key, &value) @@ -42,7 +42,7 @@ impl DocumentsFieldsCounts { reader: &heed::RoTxn, document_id: DocumentId, attribute: SchemaAttr, - ) -> ZResult> { + ) -> ZResult> { let key = DocumentAttrKey::new(document_id, attribute); match self.documents_fields_counts.get(reader, &key)? { Some(count) => Ok(Some(count)), @@ -79,11 +79,11 @@ impl DocumentsFieldsCounts { } pub struct DocumentFieldsCountsIter<'txn> { - iter: heed::RoRange<'txn, OwnedType, OwnedType>, + iter: heed::RoRange<'txn, OwnedType, OwnedType>, } impl Iterator for DocumentFieldsCountsIter<'_> { - type Item = ZResult<(SchemaAttr, u64)>; + type Item = ZResult<(SchemaAttr, u16)>; fn next(&mut self) -> Option { match self.iter.next() { @@ -99,7 +99,7 @@ impl Iterator for DocumentFieldsCountsIter<'_> { pub struct DocumentsIdsIter<'txn> { last_seen_id: Option, - iter: heed::RoIter<'txn, OwnedType, OwnedType>, + iter: heed::RoIter<'txn, OwnedType, OwnedType>, } impl Iterator for DocumentsIdsIter<'_> { @@ -123,11 +123,11 @@ impl Iterator for DocumentsIdsIter<'_> { } pub struct AllDocumentsFieldsCountsIter<'txn> { - iter: heed::RoIter<'txn, OwnedType, OwnedType>, + iter: heed::RoIter<'txn, OwnedType, OwnedType>, } impl Iterator for AllDocumentsFieldsCountsIter<'_> { - type Item = ZResult<(DocumentId, SchemaAttr, u64)>; + type Item = ZResult<(DocumentId, SchemaAttr, u16)>; fn next(&mut self) -> Option { match self.iter.next() { diff --git a/meilisearch-types/src/lib.rs b/meilisearch-types/src/lib.rs index c02281a5f..3419c61fd 100644 --- a/meilisearch-types/src/lib.rs +++ b/meilisearch-types/src/lib.rs @@ -63,3 +63,11 @@ pub struct Highlight { /// without needing to run the tokenizer again. pub char_length: u16, } + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "zerocopy", derive(AsBytes, FromBytes))] +#[repr(C)] +pub struct AttrCount { + pub attr: u16, + pub count: u16, +}