index/fulltext_index/
create.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15mod bloom_filter;
16mod tantivy;
17
18use async_trait::async_trait;
19use puffin::puffin_manager::{PuffinWriter, PutOptions};
20
21pub use crate::fulltext_index::create::bloom_filter::BloomFilterFulltextIndexCreator;
22pub use crate::fulltext_index::create::tantivy::{
23    TantivyFulltextIndexCreator, ROWID_FIELD_NAME, TEXT_FIELD_NAME,
24};
25use crate::fulltext_index::error::Result;
26
27/// `FulltextIndexCreator` is for creating a fulltext index.
28#[async_trait]
29pub trait FulltextIndexCreator: Send {
30    /// Pushes a text to the index.
31    async fn push_text(&mut self, text: &str) -> Result<()>;
32
33    /// Finalizes the creation of the index.
34    async fn finish(
35        &mut self,
36        puffin_writer: &mut (impl PuffinWriter + Send),
37        blob_key: &str,
38        put_options: PutOptions,
39    ) -> Result<u64>;
40
41    /// Aborts the creation of the index.
42    async fn abort(&mut self) -> Result<()>;
43
44    /// Returns the memory usage in bytes during the creation of the index.
45    fn memory_usage(&self) -> usize;
46}