mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-18 08:48:32 +08:00
Introduce the AttrCount type
This commit is contained in:
parent
5b9fff6636
commit
11f3d7782d
@ -12,7 +12,7 @@ fn number_exact_matches(
|
|||||||
query_index: &[u32],
|
query_index: &[u32],
|
||||||
attribute: &[u16],
|
attribute: &[u16],
|
||||||
is_exact: &[bool],
|
is_exact: &[bool],
|
||||||
fields_counts: &Set<(SchemaAttr, u64)>,
|
fields_counts: &Set<(SchemaAttr, u16)>,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
@ -25,7 +25,7 @@ pub use self::ranked_map::RankedMap;
|
|||||||
pub use self::raw_document::RawDocument;
|
pub use self::raw_document::RawDocument;
|
||||||
pub use self::store::Index;
|
pub use self::store::Index;
|
||||||
pub use self::update::{EnqueuedUpdateResult, ProcessedUpdateResult, UpdateStatus, UpdateType};
|
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)]
|
#[doc(hidden)]
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
@ -815,7 +815,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut words_fst = BTreeSet::new();
|
let mut words_fst = BTreeSet::new();
|
||||||
let mut postings_lists = HashMap::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 {
|
for (word, indexes) in iter {
|
||||||
let word = word.to_lowercase().into_bytes();
|
let word = word.to_lowercase().into_bytes();
|
||||||
|
@ -12,7 +12,7 @@ pub struct RawDocument {
|
|||||||
pub id: DocumentId,
|
pub id: DocumentId,
|
||||||
pub matches: SharedMatches,
|
pub matches: SharedMatches,
|
||||||
pub highlights: Vec<Highlight>,
|
pub highlights: Vec<Highlight>,
|
||||||
pub fields_counts: SetBuf<(SchemaAttr, u64)>,
|
pub fields_counts: SetBuf<(SchemaAttr, u16)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawDocument {
|
impl RawDocument {
|
||||||
@ -101,7 +101,7 @@ impl fmt::Debug for RawDocument {
|
|||||||
pub fn raw_documents_from(
|
pub fn raw_documents_from(
|
||||||
matches: SetBuf<(DocumentId, TmpMatch)>,
|
matches: SetBuf<(DocumentId, TmpMatch)>,
|
||||||
highlights: SetBuf<(DocumentId, Highlight)>,
|
highlights: SetBuf<(DocumentId, Highlight)>,
|
||||||
fields_counts: SetBuf<(DocumentId, SchemaAttr, u64)>,
|
fields_counts: SetBuf<(DocumentId, SchemaAttr, u16)>,
|
||||||
) -> Vec<RawDocument> {
|
) -> Vec<RawDocument> {
|
||||||
let mut docs_ranges: Vec<(_, Range, _, _)> = Vec::new();
|
let mut docs_ranges: Vec<(_, Range, _, _)> = Vec::new();
|
||||||
let mut matches2 = Matches::with_capacity(matches.len());
|
let mut matches2 = Matches::with_capacity(matches.len());
|
||||||
|
@ -325,7 +325,7 @@ where
|
|||||||
txn,
|
txn,
|
||||||
document_id,
|
document_id,
|
||||||
attribute,
|
attribute,
|
||||||
number_of_words as u64,
|
number_of_words as u16,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ use meilisearch_schema::SchemaAttr;
|
|||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct DocumentsFieldsCounts {
|
pub struct DocumentsFieldsCounts {
|
||||||
pub(crate) documents_fields_counts: heed::Database<OwnedType<DocumentAttrKey>, OwnedType<u64>>,
|
pub(crate) documents_fields_counts: heed::Database<OwnedType<DocumentAttrKey>, OwnedType<u16>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DocumentsFieldsCounts {
|
impl DocumentsFieldsCounts {
|
||||||
@ -16,7 +16,7 @@ impl DocumentsFieldsCounts {
|
|||||||
writer: &mut heed::RwTxn<MainT>,
|
writer: &mut heed::RwTxn<MainT>,
|
||||||
document_id: DocumentId,
|
document_id: DocumentId,
|
||||||
attribute: SchemaAttr,
|
attribute: SchemaAttr,
|
||||||
value: u64,
|
value: u16,
|
||||||
) -> ZResult<()> {
|
) -> ZResult<()> {
|
||||||
let key = DocumentAttrKey::new(document_id, attribute);
|
let key = DocumentAttrKey::new(document_id, attribute);
|
||||||
self.documents_fields_counts.put(writer, &key, &value)
|
self.documents_fields_counts.put(writer, &key, &value)
|
||||||
@ -42,7 +42,7 @@ impl DocumentsFieldsCounts {
|
|||||||
reader: &heed::RoTxn<MainT>,
|
reader: &heed::RoTxn<MainT>,
|
||||||
document_id: DocumentId,
|
document_id: DocumentId,
|
||||||
attribute: SchemaAttr,
|
attribute: SchemaAttr,
|
||||||
) -> ZResult<Option<u64>> {
|
) -> ZResult<Option<u16>> {
|
||||||
let key = DocumentAttrKey::new(document_id, attribute);
|
let key = DocumentAttrKey::new(document_id, attribute);
|
||||||
match self.documents_fields_counts.get(reader, &key)? {
|
match self.documents_fields_counts.get(reader, &key)? {
|
||||||
Some(count) => Ok(Some(count)),
|
Some(count) => Ok(Some(count)),
|
||||||
@ -79,11 +79,11 @@ impl DocumentsFieldsCounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct DocumentFieldsCountsIter<'txn> {
|
pub struct DocumentFieldsCountsIter<'txn> {
|
||||||
iter: heed::RoRange<'txn, OwnedType<DocumentAttrKey>, OwnedType<u64>>,
|
iter: heed::RoRange<'txn, OwnedType<DocumentAttrKey>, OwnedType<u16>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator for DocumentFieldsCountsIter<'_> {
|
impl Iterator for DocumentFieldsCountsIter<'_> {
|
||||||
type Item = ZResult<(SchemaAttr, u64)>;
|
type Item = ZResult<(SchemaAttr, u16)>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match self.iter.next() {
|
match self.iter.next() {
|
||||||
@ -99,7 +99,7 @@ impl Iterator for DocumentFieldsCountsIter<'_> {
|
|||||||
|
|
||||||
pub struct DocumentsIdsIter<'txn> {
|
pub struct DocumentsIdsIter<'txn> {
|
||||||
last_seen_id: Option<DocumentId>,
|
last_seen_id: Option<DocumentId>,
|
||||||
iter: heed::RoIter<'txn, OwnedType<DocumentAttrKey>, OwnedType<u64>>,
|
iter: heed::RoIter<'txn, OwnedType<DocumentAttrKey>, OwnedType<u16>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator for DocumentsIdsIter<'_> {
|
impl Iterator for DocumentsIdsIter<'_> {
|
||||||
@ -123,11 +123,11 @@ impl Iterator for DocumentsIdsIter<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct AllDocumentsFieldsCountsIter<'txn> {
|
pub struct AllDocumentsFieldsCountsIter<'txn> {
|
||||||
iter: heed::RoIter<'txn, OwnedType<DocumentAttrKey>, OwnedType<u64>>,
|
iter: heed::RoIter<'txn, OwnedType<DocumentAttrKey>, OwnedType<u16>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator for AllDocumentsFieldsCountsIter<'_> {
|
impl Iterator for AllDocumentsFieldsCountsIter<'_> {
|
||||||
type Item = ZResult<(DocumentId, SchemaAttr, u64)>;
|
type Item = ZResult<(DocumentId, SchemaAttr, u16)>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match self.iter.next() {
|
match self.iter.next() {
|
||||||
|
@ -63,3 +63,11 @@ pub struct Highlight {
|
|||||||
/// without needing to run the tokenizer again.
|
/// without needing to run the tokenizer again.
|
||||||
pub char_length: u16,
|
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,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user