diff --git a/crates/tabby-scheduler/src/code/index.rs b/crates/tabby-scheduler/src/code/index.rs index 98cab1f4ec9e..1f51db980bfd 100644 --- a/crates/tabby-scheduler/src/code/index.rs +++ b/crates/tabby-scheduler/src/code/index.rs @@ -4,7 +4,7 @@ use tabby_common::config::RepositoryConfig; use tracing::warn; use super::{cache::CacheStore, create_code_index, intelligence::SourceCode}; -use crate::DocIndex; +use crate::Indexer; // Magic numbers static MAX_LINE_LENGTH_THRESHOLD: usize = 300; @@ -25,7 +25,7 @@ pub fn garbage_collection(cache: &mut CacheStore) { async fn add_changed_documents( cache: &mut CacheStore, repository: &RepositoryConfig, - index: &DocIndex, + index: &Indexer, ) { let mut indexed_files_batch = Batch::new(); for file in Walk::new(repository.dir()) { @@ -57,7 +57,7 @@ async fn add_changed_documents( cache.apply_indexed(indexed_files_batch); } -fn remove_staled_documents(cache: &mut CacheStore, index: &DocIndex) { +fn remove_staled_documents(cache: &mut CacheStore, index: &Indexer) { // Create a new writer to commit deletion of removed indexed files let gc_commit = cache.prepare_garbage_collection_for_indexed_files(|key| { index.delete(key); diff --git a/crates/tabby-scheduler/src/code/mod.rs b/crates/tabby-scheduler/src/code/mod.rs index 74eb74392b92..c42b3272a989 100644 --- a/crates/tabby-scheduler/src/code/mod.rs +++ b/crates/tabby-scheduler/src/code/mod.rs @@ -6,7 +6,7 @@ use tabby_common::{config::RepositoryConfig, index::code}; use tracing::{info, warn}; use self::{cache::SourceFileKey, intelligence::SourceCode}; -use crate::{code::intelligence::CodeIntelligence, DocIndex, DocumentBuilder}; +use crate::{code::intelligence::CodeIntelligence, Indexer, IndexAttributeBuilder}; /// Module for creating code search index. mod cache; @@ -44,7 +44,7 @@ impl CodeIndex { struct CodeBuilder; #[async_trait] -impl DocumentBuilder for CodeBuilder { +impl IndexAttributeBuilder for CodeBuilder { fn format_id(&self, id: &str) -> String { format!("code:{}", id) } @@ -96,7 +96,7 @@ impl DocumentBuilder for CodeBuilder { } } -fn create_code_index() -> DocIndex { +fn create_code_index() -> Indexer { let builder = CodeBuilder; - DocIndex::new(builder) + Indexer::new(builder) } diff --git a/crates/tabby-scheduler/src/doc/mod.rs b/crates/tabby-scheduler/src/doc/mod.rs index 862e75cfb950..3caea66699ed 100644 --- a/crates/tabby-scheduler/src/doc/mod.rs +++ b/crates/tabby-scheduler/src/doc/mod.rs @@ -10,7 +10,7 @@ use tantivy::doc; use text_splitter::TextSplitter; use tracing::warn; -use crate::{DocIndex, DocumentBuilder}; +use crate::{Indexer, IndexAttributeBuilder}; pub struct SourceDocument { pub id: String, @@ -32,7 +32,7 @@ impl DocBuilder { } #[async_trait] -impl DocumentBuilder for DocBuilder { +impl IndexAttributeBuilder for DocBuilder { fn format_id(&self, id: &str) -> String { format!("web:{id}") } @@ -85,7 +85,7 @@ impl DocumentBuilder for DocBuilder { } } -pub fn create_web_index(embedding: Arc) -> DocIndex { +pub fn create_web_index(embedding: Arc) -> Indexer { let builder = DocBuilder::new(embedding); - DocIndex::new(builder) + Indexer::new(builder) } diff --git a/crates/tabby-scheduler/src/index.rs b/crates/tabby-scheduler/src/index.rs index 05bc40c59c37..42233dee9c74 100644 --- a/crates/tabby-scheduler/src/index.rs +++ b/crates/tabby-scheduler/src/index.rs @@ -5,7 +5,7 @@ use tantivy::{doc, IndexWriter, TantivyDocument, Term}; use crate::tantivy_utils::open_or_create_index; #[async_trait::async_trait] -pub trait DocumentBuilder: Send + Sync { +pub trait IndexAttributeBuilder: Send + Sync { fn format_id(&self, id: &str) -> String; async fn build_id(&self, document: &T) -> String; async fn build_attributes(&self, document: &T) -> serde_json::Value; @@ -15,13 +15,13 @@ pub trait DocumentBuilder: Send + Sync { ) -> BoxStream<(Vec, serde_json::Value)>; } -pub struct DocIndex { - builder: Box>, +pub struct Indexer { + builder: Box>, writer: IndexWriter, } -impl DocIndex { - pub fn new(builder: impl DocumentBuilder + 'static) -> Self { +impl Indexer { + pub fn new(builder: impl IndexAttributeBuilder + 'static) -> Self { let doc = IndexSchema::instance(); let (_, index) = open_or_create_index(&doc.schema, &path::index_dir()); let writer = index diff --git a/crates/tabby-scheduler/src/lib.rs b/crates/tabby-scheduler/src/lib.rs index 67d7b1154531..624d1b5e1cfe 100644 --- a/crates/tabby-scheduler/src/lib.rs +++ b/crates/tabby-scheduler/src/lib.rs @@ -10,7 +10,7 @@ pub use code::CodeIndex; use crawl::crawl_pipeline; use doc::SourceDocument; use futures::StreamExt; -use index::{DocIndex, DocumentBuilder}; +use index::{Indexer, IndexAttributeBuilder}; mod doc; use std::{env, sync::Arc};