feat(indexer): add a typesense issue indexer backend #70
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!70
Loading…
Reference in a new issue
No description provided.
Delete branch "t3code/fix-issue-69"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #69.
Adds a fork-local
typesenseissue 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
foundcount rather than Meilisearch'sEstimatedTotalHits.Merge surface
Exactly one upstream Go file changes: the
default:branch of the backend switch inmodules/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
modules/indexer/issues/indexer.gomodules/indexer/issues/codefloe_registry.gomodules/indexer/issues/codefloe_registry_test.gotypesenseand rejects everything elsemodules/indexer/issues/typesense/typesense.goInit/Ping/Closemodules/indexer/issues/typesense/document.gointernal.IndexerDatato Typesense documentmodules/indexer/issues/typesense/index.gomodules/indexer/issues/typesense/search.goSearchplus theq,filter_byandsort_bybuildersmodules/indexer/issues/typesense/search_test.gomodules/indexer/issues/typesense/typesense_test.go.forgejo/workflows/testing.ymltest-unitcustom/conf/app.example.initypesensealongside the other indexer typesdocs/codefloe/issue-indexer-typesense.mdgo.mod,go.sum,assets/go-licenses.jsontypesense-go/v3 v3.2.0Behaviour
The API key is parsed out of
ISSUE_INDEXER_CONN_STRinside the fork-local package, somodules/setting/indexer.goneeds 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:
#13resolves to issue 13, via anindex_strfield weighted abovetitleinquery_by. This restores the behaviour bleve gets from a boosted numeric term.PriorityRepoIDmaps to an_eval(repo_id:=N):descsort clause.Totalnow comes from Typesense's exactfoundrather than Meilisearch'sEstimatedTotalHits.A
ListAllsearch walks successive 250-hit pages instead of truncating at Typesense'sper_pageceiling.num_typosis 2 anddrop_tokens_thresholdis 0, the closest behavioural match to Meilisearch today; both are documented with the knob to change.Tests
q,filter_byandsort_by, no server required.tests.TestIndexer, the same one bleve runs: all 47 cases pass. The meilisearch backend skips this suite entirely.ListAllsearch wider than the 250 hit page ceiling, a skipped page, and a delete of more ids than fit in onefilter_by.typesense/typesense:29.0service in thetest-unitjob.Locally verified:
make lint-go,make fmt,make tidy,make security-checkandmake lint-editorconfigare all clean, and.deadcode-outis 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
Root cause is in upstream
routers/web/repo/issue.go, not in this backend, and it affects elasticsearch and meilisearch equally.Both
IssueIndexerUnavailablepathsreturnbefore the block that assignsctx.Data["Keyword"]and the other filter values, sorepo/issue/filter_listblows up on a missing.Keywordinstead 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:Also hardened here:
parseConnStrnow requires anhttp://orhttps://scheme and a host.url.Parseaccepts a barehost:8108as 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 founduntil Forgejo restarts, since the collection is only created duringInit.Silently recreating an empty collection would hide the fact that the whole index disappeared.
Follow-up, not in this PR
The ansible
typesenseplaybook and the Meilisearch decommission live in the deploy repo.The issue gates the decommission on a staging cutover anyway, and the upstream
meilisearchbackend is deliberately left in the fork so the rollback path stays open.101e3e424f33759ab7a133759ab7a18ee6c109668ee6c109660073bb0ccd6f906e8cf6cf700dfe47