Skip to content

Display aggregated file paths for duplicate content chunks #30

Description

@kapral18

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:

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

After:

{
  "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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions