@@ -335,18 +335,19 @@ func (r *weaviateWrapper) unmarshalSimilarSearchResponse(res *models.GraphQLResp
335335 content := ""
336336 filePath := getStringValue (obj , MetadataFilePath )
337337
338+ // 从MetadataRange中提取startLine和endLine(用于构建映射键)
339+ var startLine , endLine int
340+ if rangeValue , ok := obj [MetadataRange ].([]interface {}); ok && len (rangeValue ) >= 2 {
341+ if first , ok := rangeValue [0 ].(float64 ); ok {
342+ startLine = int (first )
343+ }
344+ if second , ok := rangeValue [2 ].(float64 ); ok {
345+ endLine = int (second )
346+ }
347+ }
348+
338349 // 如果开启获取源码且有批量获取的内容,则使用获取到的内容
339350 if r .cfg .FetchSourceCode && filePath != "" && codebasePath != "" {
340- // 从MetadataRange中提取startLine和endLine(用于构建映射键)
341- var startLine , endLine int
342- if rangeValue , ok := obj [MetadataRange ].([]interface {}); ok && len (rangeValue ) >= 2 {
343- if first , ok := rangeValue [0 ].(float64 ); ok {
344- startLine = int (first )
345- }
346- if second , ok := rangeValue [2 ].(float64 ); ok {
347- endLine = int (second )
348- }
349- }
350351
351352 // 构建映射键并查找批量获取的内容
352353 fullPath := filepath .Join (codebasePath , filePath )
@@ -358,9 +359,11 @@ func (r *weaviateWrapper) unmarshalSimilarSearchResponse(res *models.GraphQLResp
358359
359360 // Create SemanticFileItem with proper fields
360361 item := & types.SemanticFileItem {
361- Content : content ,
362- FilePath : filePath ,
363- Score : float32 (getFloatValue (additional , "certainty" )), // Convert float64 to float32
362+ Content : content ,
363+ FilePath : filePath ,
364+ StartLine : startLine ,
365+ EndLine : endLine ,
366+ Score : float32 (getFloatValue (additional , "certainty" )), // Convert float64 to float32
364367 }
365368
366369 items = append (items , item )
@@ -1423,6 +1426,79 @@ func (r *weaviateWrapper) getRecordsByPathPrefix(ctx context.Context, pathPrefix
14231426 return r .unmarshalRecordsResponse (res )
14241427}
14251428
1429+ // DeleteDictionary 删除指定目录的记录,通过匹配filePath的前缀
1430+ func (r * weaviateWrapper ) DeleteDictionary (ctx context.Context , dictionary string , options Options ) error {
1431+ // 生成租户名称
1432+ tenantName , err := r .generateTenantName (options .CodebasePath )
1433+ if err != nil {
1434+ return fmt .Errorf ("failed to generate tenant name: %w" , err )
1435+ }
1436+
1437+ // 确保路径前缀以/结尾,以便正确匹配子目录和文件
1438+ if dictionary != "" && ! strings .HasSuffix (dictionary , "/" ) {
1439+ dictionary += "/"
1440+ }
1441+
1442+ // 获取所有匹配目录前缀的记录
1443+ records , err := r .getRecordsByPathPrefix (ctx , dictionary , tenantName )
1444+ if err != nil {
1445+ return fmt .Errorf ("failed to get records by path prefix: %w" , err )
1446+ }
1447+
1448+ if len (records ) == 0 {
1449+ // 没有找到需要删除的记录
1450+ return nil
1451+ }
1452+
1453+ // 将记录转换为CodeChunk格式以便删除
1454+ chunks := make ([]* types.CodeChunk , 0 , len (records ))
1455+ for _ , record := range records {
1456+ chunk := & types.CodeChunk {
1457+ CodebaseId : record .CodebaseId ,
1458+ FilePath : record .FilePath ,
1459+ }
1460+ chunks = append (chunks , chunk )
1461+ }
1462+
1463+ if len (chunks ) > 0 {
1464+ chunkFilters := make ([]* filters.WhereBuilder , len (chunks ))
1465+ for i , chunk := range chunks {
1466+ if chunk .FilePath == types .EmptyString {
1467+ return fmt .Errorf ("invalid chunk to delete: and filePath" )
1468+ }
1469+ chunkFilters [i ] = filters .Where ().
1470+ WithOperator (filters .And ).
1471+ WithOperands ([]* filters.WhereBuilder {
1472+ filters .Where ().
1473+ WithPath ([]string {MetadataCodebaseId }).
1474+ WithOperator (filters .Equal ).
1475+ WithValueInt (int64 (chunk .CodebaseId )),
1476+ filters .Where ().
1477+ WithPath ([]string {MetadataFilePath }).
1478+ WithOperator (filters .Equal ).
1479+ WithValueText (chunk .FilePath ),
1480+ })
1481+ }
1482+
1483+ // Combine all chunk filters with OR to support batch deletion of files
1484+ combinedFilter := filters .Where ().
1485+ WithOperator (filters .Or ).
1486+ WithOperands (chunkFilters )
1487+
1488+ do , err := r .client .Batch ().ObjectsBatchDeleter ().
1489+ WithTenant (tenantName ).WithWhere (
1490+ combinedFilter ,
1491+ ).WithClassName (r .className ).Do (ctx )
1492+ if err != nil {
1493+ return fmt .Errorf ("failed to send delete chunks err:%w" , err )
1494+ }
1495+ return CheckBatchDeleteErrors (do )
1496+ }
1497+
1498+ // 批量删除记录
1499+ return nil
1500+ }
1501+
14261502// UpdateCodeChunksDictionary 更新代码块的目录路径,通过匹配filePath的前缀
14271503func (r * weaviateWrapper ) UpdateCodeChunksDictionary (ctx context.Context , codebasePath string , dictionary string , newDictionary string ) error {
14281504 // 生成租户名称
0 commit comments