Skip to content

fix: search populate snippet field from EFTS highlight payload (#47)#55

Merged
joce merged 2 commits into
mainfrom
fix/47-search-snippets
May 25, 2026
Merged

fix: search populate snippet field from EFTS highlight payload (#47)#55
joce merged 2 commits into
mainfrom
fix/47-search-snippets

Conversation

@joce
Copy link
Copy Markdown
Owner

@joce joce commented May 25, 2026

Summary

Fixes #47edgarq search was returning rows with \"snippet\": \"\" always.

Root cause: the EFTS API (efts.sec.gov/LATEST/search-index) does NOT return highlight fragments at all. The server-side Elasticsearch query excludes doc_text from _source and never adds a highlight clause, so the existing code that read hit[\"highlight\"] always found an empty dict. The SEC's own EDGAR full-text search UI confirms this — it doesn't show per-row snippets either.

Fix: after fetching each EFTS page, fetch the matched filing's primary document (https://www.sec.gov/Archives/edgar/data/{cik}/{accession_no_dashes}/{filename}), strip tags, and extract a ±150-char window around the first case-insensitive match of the query. Best-effort: a 404/5xx on the doc fetch yields an empty snippet but never aborts the search. Non-text primaries (.pdf, etc.) are skipped.

Test plan

  • New unit test test_search_snippet_populated_from_filing_text — mocks EFTS + filing HTML, asserts snippet contains query terms (failed before fix, passes after).
  • New unit test test_search_snippet_fetch_failure_yields_empty — verifies a 404 on the filing fetch leaves snippet empty without affecting other row fields.
  • Existing 14 unit tests in test_search.py updated to register a catch-all archive 404 mock (snippet stays empty for them, all other assertions unchanged).
  • Full uv run tox matrix py3.10–3.14 green (black, ruff format, ruff check, pyright, pytest).
  • Live smoke uv run edgarq search \"climate risk\" --forms 10-K --limit 2 --no-cache returns non-empty snippets containing "Climate Risk" excerpts for both Carnival Corp and MSCI Inc.

🤖 Generated with Claude Code

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 25, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 67.34694% with 16 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/edgarq/commands_impl/search.py 67.34% 8 Missing and 8 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 685f932216

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/edgarq/commands_impl/search.py Outdated
@joce joce merged commit 79a2b1d into main May 25, 2026
14 checks passed
@joce joce deleted the fix/47-search-snippets branch May 25, 2026 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

search: snippet field always empty in result rows

2 participants