use serde::Serialize;
use cqs::normalize_path;
#[derive(Serialize)]
pub(super) struct ChunkOutput {
pub name: String,
pub file: String,
pub line_start: u32,
pub line_end: u32,
pub language: String,
pub chunk_type: String,
pub score: f32,
#[serde(skip_serializing_if = "Option::is_none")]
pub signature: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content: Option<String>,
}
impl ChunkOutput {
pub fn from_search_result(r: &cqs::store::SearchResult, include_content: bool) -> Self {
Self {
name: r.chunk.name.clone(),
file: normalize_path(&r.chunk.file),
line_start: r.chunk.line_start,
line_end: r.chunk.line_end,
language: r.chunk.language.to_string(),
chunk_type: r.chunk.chunk_type.to_string(),
score: r.score,
signature: Some(r.chunk.signature.clone()),
content: if include_content {
Some(r.chunk.content.clone())
} else {
None
},
}
}
}