| 1 | #nullable enable |
| 2 | using CascadeIDE.Contracts; |
| 3 | using CascadeIDE.Features.HybridIndex.Application; |
| 4 | using CascadeIDE.Features.Search.DataAcquisition; |
| 5 | using CascadeIDE.Services; |
| 6 | |
| 7 | namespace CascadeIDE.Features.Search.Application; |
| 8 | |
| 9 | /// <summary>Workspace-поиск палитры через Hybrid Codebase Index (FTS; semantic выключен). ADR 0112 §7.</summary> |
| 10 | internal sealed class HybridIndexCommandPaletteGoToSearchBackend( |
| 11 | IHybridIndexOrchestratorSearch orchestrator, |
| 12 | string hybridScopeMode) : ICommandPaletteGoToSearchBackend |
| 13 | { |
| 14 | public async Task<(IReadOnlyList<RipgrepWorkspaceMatch> Matches, string? Error)> SearchMatchesAsync( |
| 15 | GoToAllQuery query, |
| 16 | string workspaceRoot, |
| 17 | string? solutionPath, |
| 18 | int maxMatches, |
| 19 | string? _rgExecutable, |
| 20 | CancellationToken cancellationToken) |
| 21 | { |
| 22 | var surface = CommandPaletteHciQueryExtensions.TryBuildFtsSurfaceQuery(query); |
| 23 | if (surface is null) |
| 24 | return ([], null); |
| 25 | |
| 26 | var root = CanonicalFilePath.Normalize(workspaceRoot.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); |
| 27 | (var hciRoot, var hciSolution) = HybridIndexScopeResolver.ApplyScopeMode(hybridScopeMode, root, solutionPath); |
| 28 | var extensions = CommandPaletteHciQueryExtensions.FtsIncludeExtensions(query); |
| 29 | var (response, searchErr) = await orchestrator |
| 30 | .SearchHybridAsync( |
| 31 | hciRoot, |
| 32 | hciSolution, |
| 33 | surface, |
| 34 | topN: Math.Max(1, maxMatches), |
| 35 | pathPrefix: null, |
| 36 | excludePathPrefixes: null, |
| 37 | extensions, |
| 38 | semantic: false, |
| 39 | alpha: 0.65, |
| 40 | beta: 0.35, |
| 41 | vecTopK: 30, |
| 42 | cancellationToken) |
| 43 | .ConfigureAwait(false); |
| 44 | |
| 45 | if (!string.IsNullOrEmpty(searchErr)) |
| 46 | return ([], searchErr); |
| 47 | |
| 48 | return (CommandPaletteHybridIndexHitMapper.MapHits(response.Hits, hciRoot), null); |
| 49 | } |
| 50 | } |
| 51 | |