MeiliSearch/meilisearch-core/src/store/postings_lists.rs

48 lines
1.3 KiB
Rust
Raw Normal View History

use std::borrow::Cow;
2019-10-21 12:05:53 +02:00
use heed::Result as ZResult;
use heed::types::ByteSlice;
2019-10-16 17:05:24 +02:00
use sdset::{Set, SetBuf};
use slice_group_by::GroupBy;
use crate::database::MainT;
use crate::DocIndex;
use crate::store::{Postings, PostingsCodec};
2019-10-03 15:04:11 +02:00
#[derive(Copy, Clone)]
pub struct PostingsLists {
pub(crate) postings_lists: heed::Database<ByteSlice, PostingsCodec>,
}
2019-10-03 15:04:11 +02:00
impl PostingsLists {
pub fn put_postings_list(
2019-10-18 13:21:41 +02:00
self,
writer: &mut heed::RwTxn<MainT>,
2019-10-03 15:04:11 +02:00
word: &[u8],
matches: &Set<DocIndex>,
2019-10-18 13:05:28 +02:00
) -> ZResult<()> {
let docids = matches.linear_group_by_key(|m| m.document_id).map(|g| g[0].document_id).collect();
let docids = Cow::Owned(SetBuf::new_unchecked(docids));
let matches = Cow::Borrowed(matches);
let postings = Postings { docids, matches };
self.postings_lists.put(writer, word, &postings)
}
pub fn del_postings_list(self, writer: &mut heed::RwTxn<MainT>, word: &[u8]) -> ZResult<bool> {
2019-10-16 17:05:24 +02:00
self.postings_lists.delete(writer, word)
}
pub fn clear(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<()> {
self.postings_lists.clear(writer)
}
2019-10-16 17:05:24 +02:00
pub fn postings_list<'txn>(
2019-10-18 13:21:41 +02:00
self,
reader: &'txn heed::RoTxn<MainT>,
word: &[u8],
) -> ZResult<Option<Postings<'txn>>> {
self.postings_lists.get(reader, word)
}
}