Skip to content

Commit

Permalink
better naming for index
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys committed May 23, 2024
1 parent 6704cdb commit b07a5b6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions crates/tabby-scheduler/src/code/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +25,7 @@ pub fn garbage_collection(cache: &mut CacheStore) {
async fn add_changed_documents(
cache: &mut CacheStore,
repository: &RepositoryConfig,
index: &DocIndex<SourceCode>,
index: &Indexer<SourceCode>,
) {
let mut indexed_files_batch = Batch::new();
for file in Walk::new(repository.dir()) {
Expand Down Expand Up @@ -57,7 +57,7 @@ async fn add_changed_documents(
cache.apply_indexed(indexed_files_batch);
}

fn remove_staled_documents(cache: &mut CacheStore, index: &DocIndex<SourceCode>) {
fn remove_staled_documents(cache: &mut CacheStore, index: &Indexer<SourceCode>) {
// 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);
Expand Down
8 changes: 4 additions & 4 deletions crates/tabby-scheduler/src/code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +44,7 @@ impl CodeIndex {
struct CodeBuilder;

#[async_trait]
impl DocumentBuilder<SourceCode> for CodeBuilder {
impl IndexAttributeBuilder<SourceCode> for CodeBuilder {
fn format_id(&self, id: &str) -> String {
format!("code:{}", id)
}
Expand Down Expand Up @@ -96,7 +96,7 @@ impl DocumentBuilder<SourceCode> for CodeBuilder {
}
}

fn create_code_index() -> DocIndex<SourceCode> {
fn create_code_index() -> Indexer<SourceCode> {
let builder = CodeBuilder;
DocIndex::new(builder)
Indexer::new(builder)
}
8 changes: 4 additions & 4 deletions crates/tabby-scheduler/src/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,7 +32,7 @@ impl DocBuilder {
}

#[async_trait]
impl DocumentBuilder<SourceDocument> for DocBuilder {
impl IndexAttributeBuilder<SourceDocument> for DocBuilder {
fn format_id(&self, id: &str) -> String {
format!("web:{id}")
}
Expand Down Expand Up @@ -85,7 +85,7 @@ impl DocumentBuilder<SourceDocument> for DocBuilder {
}
}

pub fn create_web_index(embedding: Arc<dyn Embedding>) -> DocIndex<SourceDocument> {
pub fn create_web_index(embedding: Arc<dyn Embedding>) -> Indexer<SourceDocument> {
let builder = DocBuilder::new(embedding);
DocIndex::new(builder)
Indexer::new(builder)
}
10 changes: 5 additions & 5 deletions crates/tabby-scheduler/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>: Send + Sync {
pub trait IndexAttributeBuilder<T>: 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;
Expand All @@ -15,13 +15,13 @@ pub trait DocumentBuilder<T>: Send + Sync {
) -> BoxStream<(Vec<String>, serde_json::Value)>;
}

pub struct DocIndex<T> {
builder: Box<dyn DocumentBuilder<T>>,
pub struct Indexer<T> {
builder: Box<dyn IndexAttributeBuilder<T>>,
writer: IndexWriter,
}

impl<T> DocIndex<T> {
pub fn new(builder: impl DocumentBuilder<T> + 'static) -> Self {
impl<T> Indexer<T> {
pub fn new(builder: impl IndexAttributeBuilder<T> + 'static) -> Self {
let doc = IndexSchema::instance();
let (_, index) = open_or_create_index(&doc.schema, &path::index_dir());
let writer = index
Expand Down
2 changes: 1 addition & 1 deletion crates/tabby-scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit b07a5b6

Please sign in to comment.