codefloe/forgejo-codefloe
Watch
4
12
Fork
You've already forked forgejo-codefloe
0

feat(indexer): add a typesense issue indexer backend #70

Merged
pat-s merged 1 commit from t3code/fix-issue-69 into v16.0/forgejo-codefloe 2026-09-03 06:44:30 +00:00
Owner

Closes #69.

Adds a fork-local typesense issue indexer so we can drop Meilisearch, whose replication is gated behind the Enterprise Edition, and run a self-hosted HA search cluster on a licence with no feature gates.
Typesense gives prefix search out of the box, ships Raft clustering in the GPL-3.0 binary, and returns an exact found count rather than Meilisearch's EstimatedTotalHits.

Merge surface

Exactly one upstream Go file changes: the default: branch of the backend switch in modules/indexer/issues/indexer.go, marked // CODEFLOE:, which now calls a fork-local registry.
Every future fork-local backend costs zero further upstream edits.
Everything else is new files under modules/indexer/issues/typesense/.

There is no database migration.
models/ is untouched, the index lives entirely in Typesense, and it is rebuilt from Postgres, so there is nothing that can conflict with upstream schema work.

Files

Path Change
modules/indexer/issues/indexer.go route unknown indexer types through the fork registry
modules/indexer/issues/codefloe_registry.go new, resolves fork-local backends by type string
modules/indexer/issues/codefloe_registry_test.go new, registry resolves typesense and rejects everything else
modules/indexer/issues/typesense/typesense.go new, client, versioned collection schema, Init / Ping / Close
modules/indexer/issues/typesense/document.go new, internal.IndexerData to Typesense document
modules/indexer/issues/typesense/index.go new, bulk upsert and chunked filter_by delete
modules/indexer/issues/typesense/search.go new, Search plus the q, filter_by and sort_by builders
modules/indexer/issues/typesense/search_test.go new, builder unit tests, no server needed
modules/indexer/issues/typesense/typesense_test.go new, shared conformance suite and pagination coverage
.forgejo/workflows/testing.yml add a pinned single-node typesense service to test-unit
custom/conf/app.example.ini list typesense alongside the other indexer types
docs/codefloe/issue-indexer-typesense.md new, operator setup, cutover, rollback, rebuild, sizing
go.mod, go.sum, assets/go-licenses.json add typesense-go/v3 v3.2.0

Behaviour

The API key is parsed out of ISSUE_INDEXER_CONN_STR inside the fork-local package, so modules/setting/indexer.go needs no change.
The collection is versioned as <ISSUE_INDEXER_NAME>_v1, so a schema change forces a clean rebuild rather than a silent mismatch.

Two cases work here that the meilisearch backend cannot do at all:

  • #13 resolves to issue 13, via an index_str field weighted above title in query_by. This restores the behaviour bleve gets from a boosted numeric term.
  • PriorityRepoID maps to an _eval(repo_id:=N):desc sort clause.

Total now comes from Typesense's exact found rather than Meilisearch's EstimatedTotalHits.
A ListAll search walks successive 250-hit pages instead of truncating at Typesense's per_page ceiling.
num_typos is 2 and drop_tokens_threshold is 0, the closest behavioural match to Meilisearch today; both are documented with the knob to change.

Tests

  • 10 builder unit tests for q, filter_by and sort_by, no server required.
  • The full shared conformance suite, tests.TestIndexer, the same one bleve runs: all 47 cases pass. The meilisearch backend skips this suite entirely.
  • A 601 document test covering the two paths the shared suite cannot reach: a ListAll search wider than the 250 hit page ceiling, a skipped page, and a delete of more ids than fit in one filter_by.
  • CI runs the suite against a digest-pinned typesense/typesense:29.0 service in the test-unit job.

Locally verified: make lint-go, make fmt, make tidy, make security-check and make lint-editorconfig are all clean, and .deadcode-out is unchanged.

Graceful degradation when the indexer is down

Reported on dev and reproduced locally against a real instance: with the indexer unreachable, the repo issue list died with

Render failed: failed to render template: repo/issue/list, error: template error:
repo/issue/filter_list:85:57 : executing "repo/issue/filter_list" at <$.Keyword>: invalid value; expected string

Root cause is in upstream routers/web/repo/issue.go, not in this backend, and it affects elasticsearch and meilisearch equally.
Both IssueIndexerUnavailable paths return before the block that assigns ctx.Data["Keyword"] and the other filter values, so repo/issue/filter_list blows up on a missing .Keyword instead of showing the "keyword search unavailable" banner the template already has for exactly this case.
The same paths also swallow the underlying error entirely, so nothing is logged.

Fixed fork-locally, marked // CODEFLOE:, verified by reproduction:

  • indexer up: 5 of 5 issues found
  • indexer down: HTTP 200, the intended banner renders, and the cause is logged with the full request URL and the network error
  • no keyword, indexer down: unaffected, served from the database

Also hardened here: parseConnStr now requires an http:// or https:// scheme and a host.
url.Parse accepts a bare host:8108 as an opaque URL, which used to produce a client that failed every request at runtime; it is now rejected at startup where the operator sees it.

A second failure mode is documented rather than papered over: if Typesense is reachable but its collection is gone, for example after a pod restarts without a persistent volume, keyword search returns 404 Collection not found until Forgejo restarts, since the collection is only created during Init.
Silently recreating an empty collection would hide the fact that the whole index disappeared.

Follow-up, not in this PR

The ansible typesense playbook and the Meilisearch decommission live in the deploy repo.
The issue gates the decommission on a staging cutover anyway, and the upstream meilisearch backend is deliberately left in the fork so the rollback path stays open.

Closes #69. Adds a fork-local `typesense` issue indexer so we can drop Meilisearch, whose replication is gated behind the Enterprise Edition, and run a self-hosted HA search cluster on a licence with no feature gates. Typesense gives prefix search out of the box, ships Raft clustering in the GPL-3.0 binary, and returns an exact `found` count rather than Meilisearch's `EstimatedTotalHits`. ## Merge surface Exactly one upstream Go file changes: the `default:` branch of the backend switch in `modules/indexer/issues/indexer.go`, marked `// CODEFLOE:`, which now calls a fork-local registry. Every future fork-local backend costs zero further upstream edits. Everything else is new files under `modules/indexer/issues/typesense/`. There is **no database migration**. `models/` is untouched, the index lives entirely in Typesense, and it is rebuilt from Postgres, so there is nothing that can conflict with upstream schema work. ## Files | Path | Change | | --- | --- | | `modules/indexer/issues/indexer.go` | route unknown indexer types through the fork registry | | `modules/indexer/issues/codefloe_registry.go` | new, resolves fork-local backends by type string | | `modules/indexer/issues/codefloe_registry_test.go` | new, registry resolves `typesense` and rejects everything else | | `modules/indexer/issues/typesense/typesense.go` | new, client, versioned collection schema, `Init` / `Ping` / `Close` | | `modules/indexer/issues/typesense/document.go` | new, `internal.IndexerData` to Typesense document | | `modules/indexer/issues/typesense/index.go` | new, bulk upsert and chunked filter_by delete | | `modules/indexer/issues/typesense/search.go` | new, `Search` plus the `q`, `filter_by` and `sort_by` builders | | `modules/indexer/issues/typesense/search_test.go` | new, builder unit tests, no server needed | | `modules/indexer/issues/typesense/typesense_test.go` | new, shared conformance suite and pagination coverage | | `.forgejo/workflows/testing.yml` | add a pinned single-node typesense service to `test-unit` | | `custom/conf/app.example.ini` | list `typesense` alongside the other indexer types | | `docs/codefloe/issue-indexer-typesense.md` | new, operator setup, cutover, rollback, rebuild, sizing | | `go.mod`, `go.sum`, `assets/go-licenses.json` | add `typesense-go/v3 v3.2.0` | ## Behaviour The API key is parsed out of `ISSUE_INDEXER_CONN_STR` inside the fork-local package, so `modules/setting/indexer.go` needs no change. The collection is versioned as `<ISSUE_INDEXER_NAME>_v1`, so a schema change forces a clean rebuild rather than a silent mismatch. Two cases work here that the meilisearch backend cannot do at all: - `#13` resolves to issue 13, via an `index_str` field weighted above `title` in `query_by`. This restores the behaviour bleve gets from a boosted numeric term. - `PriorityRepoID` maps to an `_eval(repo_id:=N):desc` sort clause. `Total` now comes from Typesense's exact `found` rather than Meilisearch's `EstimatedTotalHits`. A `ListAll` search walks successive 250-hit pages instead of truncating at Typesense's `per_page` ceiling. `num_typos` is 2 and `drop_tokens_threshold` is 0, the closest behavioural match to Meilisearch today; both are documented with the knob to change. ## Tests - 10 builder unit tests for `q`, `filter_by` and `sort_by`, no server required. - The full shared conformance suite, `tests.TestIndexer`, the same one bleve runs: **all 47 cases pass**. The meilisearch backend skips this suite entirely. - A 601 document test covering the two paths the shared suite cannot reach: a `ListAll` search wider than the 250 hit page ceiling, a skipped page, and a delete of more ids than fit in one `filter_by`. - CI runs the suite against a digest-pinned `typesense/typesense:29.0` service in the `test-unit` job. Locally verified: `make lint-go`, `make fmt`, `make tidy`, `make security-check` and `make lint-editorconfig` are all clean, and `.deadcode-out` is unchanged. ## Graceful degradation when the indexer is down Reported on dev and reproduced locally against a real instance: with the indexer unreachable, the repo issue list died with ``` Render failed: failed to render template: repo/issue/list, error: template error: repo/issue/filter_list:85:57 : executing "repo/issue/filter_list" at <$.Keyword>: invalid value; expected string ``` Root cause is in upstream `routers/web/repo/issue.go`, not in this backend, and it affects elasticsearch and meilisearch equally. Both `IssueIndexerUnavailable` paths `return` before the block that assigns `ctx.Data["Keyword"]` and the other filter values, so `repo/issue/filter_list` blows up on a missing `.Keyword` instead of showing the "keyword search unavailable" banner the template already has for exactly this case. The same paths also swallow the underlying error entirely, so nothing is logged. Fixed fork-locally, marked `// CODEFLOE:`, verified by reproduction: - indexer up: 5 of 5 issues found - indexer down: HTTP 200, the intended banner renders, and the cause is logged with the full request URL and the network error - no keyword, indexer down: unaffected, served from the database Also hardened here: `parseConnStr` now requires an `http://` or `https://` scheme and a host. `url.Parse` accepts a bare `host:8108` as an opaque URL, which used to produce a client that failed every request at runtime; it is now rejected at startup where the operator sees it. A second failure mode is documented rather than papered over: if Typesense is reachable but its collection is gone, for example after a pod restarts without a persistent volume, keyword search returns `404 Collection not found` until Forgejo restarts, since the collection is only created during `Init`. Silently recreating an empty collection would hide the fact that the whole index disappeared. ## Follow-up, not in this PR The ansible `typesense` playbook and the Meilisearch decommission live in the deploy repo. The issue gates the decommission on a staging cutover anyway, and the upstream `meilisearch` backend is deliberately left in the fork so the rollback path stays open.
pat-s force-pushed t3code/fix-issue-69 from 101e3e424f
Some checks failed
testing / backend-checks (pull_request) Has been cancelled
testing / frontend-checks (pull_request) Successful in 1m7s
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
to 33759ab7a1
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m18s
testing / backend-checks (pull_request) Successful in 6m15s
testing / test-sqlite (pull_request) Successful in 43m23s
testing / test-unit (pull_request) Successful in 9m57s
testing / test-remote-cacher (valkey) (pull_request) Successful in 1m50s
testing / test-remote-cacher (redis) (pull_request) Successful in 1m51s
testing / test-remote-cacher (garnet) (pull_request) Successful in 1m54s
testing / test-e2e (pull_request) Successful in 24m59s
testing / test-mysql (pull_request) Successful in 29m4s
testing / test-pgsql (pull_request) Successful in 46m24s
2026-08-03 13:23:26 +00:00
Compare
pat-s force-pushed t3code/fix-issue-69 from 33759ab7a1
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m18s
testing / backend-checks (pull_request) Successful in 6m15s
testing / test-sqlite (pull_request) Successful in 43m23s
testing / test-unit (pull_request) Successful in 9m57s
testing / test-remote-cacher (valkey) (pull_request) Successful in 1m50s
testing / test-remote-cacher (redis) (pull_request) Successful in 1m51s
testing / test-remote-cacher (garnet) (pull_request) Successful in 1m54s
testing / test-e2e (pull_request) Successful in 24m59s
testing / test-mysql (pull_request) Successful in 29m4s
testing / test-pgsql (pull_request) Successful in 46m24s
to 8ee6c10966
All checks were successful
testing / test-remote-cacher (redis) (pull_request) Successful in 2m38s
testing / frontend-checks (pull_request) Successful in 1m36s
testing / backend-checks (pull_request) Successful in 8m25s
testing / test-remote-cacher (valkey) (pull_request) Successful in 2m25s
testing / test-remote-cacher (garnet) (pull_request) Successful in 2m15s
testing / test-unit (pull_request) Successful in 7m37s
testing / test-e2e (pull_request) Successful in 36m40s
testing / test-mysql (pull_request) Successful in 37m48s
testing / test-sqlite (pull_request) Successful in 59m50s
testing / test-pgsql (pull_request) Successful in 1h3m58s
2026-08-04 15:20:48 +00:00
Compare
pat-s force-pushed t3code/fix-issue-69 from 8ee6c10966
All checks were successful
testing / test-remote-cacher (redis) (pull_request) Successful in 2m38s
testing / frontend-checks (pull_request) Successful in 1m36s
testing / backend-checks (pull_request) Successful in 8m25s
testing / test-remote-cacher (valkey) (pull_request) Successful in 2m25s
testing / test-remote-cacher (garnet) (pull_request) Successful in 2m15s
testing / test-unit (pull_request) Successful in 7m37s
testing / test-e2e (pull_request) Successful in 36m40s
testing / test-mysql (pull_request) Successful in 37m48s
testing / test-sqlite (pull_request) Successful in 59m50s
testing / test-pgsql (pull_request) Successful in 1h3m58s
to 0073bb0ccd
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m6s
testing / backend-checks (pull_request) Successful in 4m18s
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Successful in 2m6s
testing / test-mysql (pull_request) Successful in 27m16s
testing / test-sqlite (pull_request) Successful in 43m30s
testing / test-pgsql (pull_request) Successful in 45m32s
testing / test-unit (pull_request) Successful in 8m48s
testing / test-e2e (pull_request) Successful in 24m1s
2026-08-05 14:08:02 +00:00
Compare
pat-s force-pushed t3code/fix-issue-69 from 6f906e8cf6
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m39s
testing / backend-checks (pull_request) Successful in 8m40s
testing / test-unit (pull_request) Successful in 10m4s
testing / test-remote-cacher (redis) (pull_request) Successful in 3m45s
testing / test-remote-cacher (garnet) (pull_request) Successful in 3m47s
testing / test-remote-cacher (valkey) (pull_request) Successful in 4m6s
testing / test-e2e (pull_request) Successful in 25m10s
testing / test-mysql (pull_request) Successful in 28m40s
testing / test-pgsql (pull_request) Successful in 47m1s
testing / test-sqlite (pull_request) Successful in 44m57s
to cf700dfe47
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m23s
testing / backend-checks (pull_request) Successful in 4m20s
testing / test-remote-cacher (valkey) (pull_request) Successful in 2m10s
testing / test-unit (pull_request) Successful in 11m5s
testing / test-remote-cacher (redis) (pull_request) Successful in 1m48s
testing / test-remote-cacher (garnet) (pull_request) Successful in 2m18s
testing / test-e2e (pull_request) Successful in 28m45s
testing / test-mysql (pull_request) Successful in 33m37s
testing / test-sqlite (pull_request) Successful in 45m43s
testing / test-pgsql (pull_request) Successful in 47m45s
issue-labels / backporting (pull_request_target) Has been skipped
milestone / set (pull_request_target) Has been skipped
2026-09-02 21:01:53 +00:00
Compare
pat-s merged commit e8b3f5fcc0 into v16.0/forgejo-codefloe 2026-09-03 06:44:30 +00:00
pat-s deleted branch t3code/fix-issue-69 2026-09-03 06:44:30 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
codefloe/forgejo-codefloe!70
No description provided.