elastic / elastic/semantic-code-search-mcp-server

Display aggregated file paths for duplicate content chunks

Open
#30 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
12
Forks
7
PR merge metrics
No merged PRs in 30d

Description

## Problem

When the indexer aggregates file paths for identical content (see elastic/semantic-code-search-indexer#121), the MCP server needs to display this information properly to users.

Currently, search results show a single `filePath`. After the indexer change, documents will have:
- `filePaths`: array of `{ path, startLine, endLine }` objects
- `fileCount`: total number of files containing this content

## Proposed Changes

**Update search result format:**

Before:
```json
{
"score": 0.92,
"content": "useContext(JobCreatorContext)",
"filePath": "ml/pick_fields_step/rare_field/rare_field.tsx",
"startLine": 18,
"endLine": 18
}
```

After:
```json
{
"score": 0.92,
"content": "useContext(JobCreatorContext)",
"fileCount": 77,
"filePaths": [
"ml/pick_fields_step/categorization_view/top_categories.tsx:23",
"ml/pick_fields_step/influencers/influencers.tsx:31",
"ml/pick_fields_step/rare_field/rare_field.tsx:18",
"... and 74 more"
]
}
```

**Implementation:**

1. Update `semantic_code_search.ts` result mapping to include `filePaths` and `fileCount`
2. Format `filePaths` as `path:startLine` strings for readability
3. Truncate to first 10 paths if `fileCount > 10`, append "... and N more"
4. Backward compatibility: handle documents with old `filePath` field (single string) during migration period

## Related

- Indexer changes: elastic/semantic-code-search-indexer#121

## Acceptance Criteria

- [ ] Search results include `filePaths` array and `fileCount`
- [ ] File paths formatted as `path:line` for readability
- [ ] Results truncated to 10 paths with "and N more" suffix when needed
- [ ] Backward compatible with old single-`filePath` documents during migration

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.