Skip to content

Add the pure query core for the analysis catalog - #211

Open
alex-rawlings-yyc wants to merge 15 commits into
mainfrom
analysis-catalog-derivation
Open

Add the pure query core for the analysis catalog#211
alex-rawlings-yyc wants to merge 15 commits into
mainfrom
analysis-catalog-derivation

Conversation

@alex-rawlings-yyc

@alex-rawlings-yyc alex-rawlings-yyc commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Closes #192.

The pure derivation layer for the Analysis Catalog (#186) — no React, no store, no PAPI, no UI.

Modules

  • src/utils/search-fold.tsfoldForSearch (NFD → strip \p{Mn} → NFC → lowercase), kept deliberately apart from normalizeSurfaceForm.
  • src/utils/analysis-query.tsbuildCatalogRows, applyCatalogQuery, deriveFacets.
  • src/store/analysisSlice.tsselectCatalogRows(state, currentBook), memoized on the two token-level arrays plus the analysis language and book.

Three divergences from the issue, agreed before implementing

  1. Split build from query. Analysis catalog: pure query core (analysis-query.ts, search fold, memoized selector) #192 specifies buildCatalogRows(analysis, query) but also requires search/sort/filter to run outside the memoized build — those conflict. Shipped as buildCatalogRows(analysis, scope) + applyCatalogQuery(rows, query). buildCatalogRows takes Pick<TextAnalysis, 'tokenAnalyses' | 'tokenAnalysisLinks'> so the selector memoizes on those arrays rather than the whole TextAnalysis.
  2. CatalogRow carries pos / features / confidence. The row shape in Analysis catalog: pure query core (analysis-query.ts, search fold, memoized selector) #192 has none of them, so deriveFacets(rows) could not derive the facets it is asked to. status and lexicon refs are deliberately not facets: status is constant by construction (only approved links count as usages) and lexicon-ref presence is a boolean, not a value list.
  3. No analysisLanguages in the query. searchText folds every gloss value present, so a gloss in a language the project no longer declares stays findable.

#192 and #186's row model should be amended before #193 starts, since #193 consumes these exports.

Not in the issue, but the data requires it

USJ verse SIDs are verbatim, so a bridged verse arrives as "GEN 1:3-4:0" and Number('3-4') is NaN. Usage parsing goes through the existing firstVerseNumber; there is a test for it.

Testing

31 new tests covering all 25 behaviors listed in #192. Full suite 1681 passing, 100% coverage, lint clean.

🤖 Generated with Claude Code


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Added catalog search across glosses and morphemes.
    • Added filtering by book, usage, gloss, and morphology.
    • Added sorting by usage, text, gloss, and first occurrence.
    • Added catalog facets for books, part of speech, confidence, and feature values.
    • Search supports case- and diacritic-insensitive matching across Greek, Hebrew, Latin, Devanagari, and Arabic text.
  • Tests

    • Added comprehensive coverage for catalog queries, filtering, sorting, facets, multilingual search, and catalog updates.

@alex-rawlings-yyc alex-rawlings-yyc self-assigned this Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds a pure analysis catalog query core, search folding, row construction, facets, filters, sorting, and a memoized Redux selector. It also adds tests for catalog behavior, normalization, query operations, and selector memoization.

Changes

Analysis catalog

Layer / File(s) Summary
Catalog contracts and row construction
src/utils/analysis-query.ts, src/utils/search-fold.ts, src/__tests__/utils/analysis-query.test.ts, src/__tests__/utils/search-fold.test.ts, src/__tests__/utils/analysis-identity.test.ts
Adds catalog contracts, approved usage grouping, document ordering, row construction, folded search text, and Unicode search normalization.
Facets, filters, and sorting
src/utils/analysis-query.ts, src/__tests__/utils/analysis-query.test.ts
Adds facet derivation, search and filter evaluation, and count-, text-, gloss-, and first-use sorting.
Memoized store selector
src/store/analysisSlice.ts, src/__tests__/store/analysisSlice.test.ts
Exports selectCatalogRows and verifies stable references for unchanged state and recomputation after gloss updates.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AnalysisState
  participant selectCatalogRows
  participant buildCatalogRows
  AnalysisState->>selectCatalogRows: token analyses, links, language, current book
  selectCatalogRows->>buildCatalogRows: catalog scope
  buildCatalogRows-->>selectCatalogRows: catalog rows
  selectCatalogRows-->>AnalysisState: memoized row collection
Loading

Possibly related issues

  • Issue 186: The PR implements the Analysis Catalog v1 objectives, including rows, search folding, facets, filters, sorting, and memoized selection.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Most [#192] requirements are covered, but the summary specifies compatibility decomposition instead of the required NFD normalization for foldForSearch. Implement foldForSearch with NFD normalization, combining-mark removal, NFC recomposition, and lowercasing while preserving the required search-only distinctions.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding the pure query core for the Analysis Catalog.
Out of Scope Changes check ✅ Passed All listed changes support [#192], including implementation, selector integration, and focused tests; no unrelated code changes are identified.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch analysis-catalog-derivation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@alex-rawlings-yyc
alex-rawlings-yyc marked this pull request as draft August 10, 2026 21:56
coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

@alex-rawlings-yyc alex-rawlings-yyc left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alex-rawlings-yyc resolved 2 discussions.
Reviewable status: 0 of 7 files reviewed, all discussions resolved (waiting on alex-rawlings-yyc).

Row derivation, search fold, and facets, memoized as selectCatalogRows.
Row building and query application are separate functions so searching
and sorting never rebuild rows; the search fold stays apart from
normalizeSurfaceForm, since folding a diacritic into identity would
silently merge distinct analyses.
Adds pos, confidence, and feature filters, treats an empty selection as
inactive, and orders the confidence facet by strength. The search query
is
trimmed in applyCatalogQuery, not in foldForSearch, whose output
separates
the row fields a match must not span.
Compatibility normalization covers the shapes Unicode encodes as
variants;
Greek and Hebrew final letters, which it encodes as distinct letters,
are mapped.
Ties fell through to payload creation order, so a draft of mostly
one-usage rows was ordered by when each analysis happened to be
recorded; they now fall back to form, then gloss.
The analyses and links these fixtures build gained required createdAt /
updatedAt, so each now spreads FIXTURE_STAMPS. Also drops two fixture
counts from the doc comments, which nothing kept in sync.
@alex-rawlings-yyc
alex-rawlings-yyc force-pushed the analysis-catalog-derivation branch from 35e2980 to 7e0162a Compare August 11, 2026 18:44
@alex-rawlings-yyc
alex-rawlings-yyc marked this pull request as ready for review August 11, 2026 18:45
Absence now lists as undefined after a field's values, so a field one
analysis is tagged with still raises a dropdown, and a search for what
an analysis lacks is possible. Also folds a pasted Windows line ending
in a catalog search.
Usage counts match the suggestion pool's frequency only while a token
carries at most one approved link, and a single-book draft is offered
no books facet even when unused rows sit alongside the used ones.
coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

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.

Analysis catalog: pure query core (analysis-query.ts, search fold, memoized selector)

1 participant