Skip to content

Commit

Permalink
chore: adding debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Sma1lboy committed Nov 12, 2024
1 parent d84bab1 commit 3d2682a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion crates/tabby-common/src/api/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use async_trait::async_trait;
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tracing::debug;

use crate::path::normalize_path;

Expand Down Expand Up @@ -67,8 +68,15 @@ impl CodeSearchQuery {
content: String,
source_id: String,
) -> Self {
debug!("CodeSearchQuery::new - Original filepath: {:?}", filepath);
let normalized = normalize_path(filepath).unwrap_or(None);
debug!(
"CodeSearchQuery::new - Normalized filepath: {:?}",
normalized
);

Self {
filepath: normalize_path(filepath).unwrap_or(None),
filepath: normalized,
language,
content,
source_id,
Expand Down
9 changes: 8 additions & 1 deletion crates/tabby-common/src/index/code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use tantivy::{
Term,
};
pub use tokenizer::tokenize_code;
use tracing::debug;

use super::{corpus, IndexSchema};
use crate::{api::code::CodeSearchQuery, path::normalize_path};
Expand Down Expand Up @@ -49,15 +50,16 @@ pub fn body_query(tokens: &[String]) -> Box<dyn Query> {
}

fn filepath_query(filepath: &str) -> Box<TermQuery> {
debug!("filepath_query - Input filepath: {}", filepath);
let schema = IndexSchema::instance();
let mut term =
Term::from_field_json_path(schema.field_chunk_attributes, fields::CHUNK_FILEPATH, false);

// normalize the path base on the platform.
let filepath = normalize_path(Some(filepath.to_string()))
.ok()
.flatten()
.unwrap_or_else(|| filepath.to_string());
debug!("filepath_query - Normalized filepath: {}", filepath);

term.append_type_and_str(&filepath);
Box::new(TermQuery::new(term, IndexRecordOption::Basic))
Expand Down Expand Up @@ -91,7 +93,12 @@ pub fn code_search_query(

// When filepath presents, we exclude the file from the search.
if let Some(filepath) = &query.filepath {
debug!("code_search_query - Original filepath: {}", filepath);
if let Ok(Some(normalized_path)) = normalize_path(Some(filepath.clone())) {
debug!(
"code_search_query - Normalized filepath: {}",
normalized_path
);
subqueries.push((
Occur::MustNot,
Box::new(ConstScoreQuery::new(filepath_query(&normalized_path), 0.0)),
Expand Down

0 comments on commit 3d2682a

Please sign in to comment.