index/inverted_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
15pub mod sort;
16pub mod sort_create;
17
18use async_trait::async_trait;
19
20use crate::bitmap::BitmapType;
21use crate::inverted_index::error::Result;
22use crate::inverted_index::format::writer::InvertedIndexWriter;
23use crate::BytesRef;
24
25/// `InvertedIndexCreator` provides functionality to construct an inverted index
26#[async_trait]
27pub trait InvertedIndexCreator: Send {
28    /// Adds a value to the named index. A `None` value represents an absence of data (null)
29    ///
30    /// - `index_name`: Identifier for the index being built
31    /// - `value`: The data to be indexed, or `None` for a null entry
32    ///
33    /// It should be equivalent to calling `push_with_name_n` with `n = 1`
34    async fn push_with_name(
35        &mut self,
36        index_name: &str,
37        value: Option<BytesRef<'_>>,
38    ) -> Result<()> {
39        self.push_with_name_n(index_name, value, 1).await
40    }
41
42    /// Adds `n` identical values to the named index. `None` values represent absence of data (null)
43    ///
44    /// - `index_name`: Identifier for the index being built
45    /// - `value`: The data to be indexed, or `None` for a null entry
46    ///
47    /// It should be equivalent to calling `push_with_name` `n` times
48    async fn push_with_name_n(
49        &mut self,
50        index_name: &str,
51        value: Option<BytesRef<'_>>,
52        n: usize,
53    ) -> Result<()>;
54
55    /// Finalizes the index creation process, ensuring all data is properly indexed and stored
56    /// in the provided writer
57    async fn finish(
58        &mut self,
59        writer: &mut dyn InvertedIndexWriter,
60        bitmap_type: BitmapType,
61    ) -> Result<()>;
62}