platform icon indicating copy to clipboard operation
platform copied to clipboard

feat: multi-backend fulltext search (Elastic, OpenSearch, Typesense)

Open dnplkndll opened this issue 8 months ago • 2 comments

Summary

Add configurable fulltext search backend with three adapters and self-healing for non-persistent backends.

New packages

  • @hcengineering/opensearch — Drop-in OpenSearch 2.x replacement for ES 7.x (Apache 2.0 licensed, same wire protocol)
  • @hcengineering/typesense — Lightweight C++ search engine (~3-5x less RAM, no JVM)

Fulltext pod changes

  • FULLTEXT_BACKEND env var selects adapter at runtime: elastic (default) | opensearch | typesense
  • Auto-reindex on empty backend — non-persistent backends (e.g. Typesense with emptyDir) self-heal after pod restart. On startup, detects 0 docs → enumerates active workspaces → queues fullReindex for each. Elastic/OpenSearch skip this check (persistent storage).
  • Optional getDocCount() method on FullTextAdapter interface enables the detection.

Build fix

  • show_version.js — reads version.txt before git tags. Previously fell back to hardcoded 0.6.0 when no git tags exist (forks), causing model version mismatch that blocked the indexer entirely.

Search Comparison Results

Tested with 565 docs, 7 query types across all 3 backends:

Query ES↔OpenSearch ES↔Typesense
Prefix "set" 5/5 identical 7/7 same docs, minor rank diff
Fuzzy "projecct" (typo) 4/5 overlap 3/5 (top 2 identical)
Multi-word "deployment setup" 1/1 identical 1/1 identical
Class filter "project" 5/5 identical 5/5 same docs

OpenSearch is a perfect drop-in (identical results). Typesense finds the same relevant documents with minor ranking differences (different scoring model).

Resource Comparison (production verified)

ES 7.14 Typesense Savings
Search engine RAM 1353 Mi 84 Mi 94%
Disk 10Gi PVC emptyDir 100%
Self-healing on restart N/A Auto-reindex (~30s) ✓

Commits

  1. feat: add OpenSearch and Typesense fulltext adapters — new @hcengineering/opensearch and @hcengineering/typesense packages implementing FullTextAdapter
  2. feat: configurable fulltext backend via FULLTEXT_BACKEND env var — backend selection in fulltext pod
  3. fix: read version.txt before git tags in show_version.js — fixes model version resolution in forks without git tags
  4. feat: tune Typesense adapter for better search parity with ES — field weights, typo tolerance, sanitizeDoc() for dynamic fields
  5. feat: auto-reindex on empty Typesense backend startup — getDocCount() on adapter + checkAndTriggerReindex() in manager

Backward Compatibility

  • Default backend remains elastic — zero changes for existing deployments
  • FullTextAdapter interface change is additive only (getDocCount is optional)
  • No Helm chart changes required (env vars are optional)

Related

  • Helm chart support: https://github.com/ledoent/huly-selfhost/pull/3
  • Test harness & infra: https://gitlab.com/ledoent/infra/-/merge_requests/5

Test plan

  • [x] rush build passes
  • [x] CI: build, formatting, test, docker-build, svelte-check, all uitests pass
  • [x] Fulltext pod starts correctly with each backend
  • [x] Search comparison: 7 queries across all 3 backends
  • [x] Self-healing: Typesense pod kill → auto-reindex → 565 docs restored in ~30s
  • [x] FULLTEXT_BACKEND=invalid exits with clear error message

🤖 Generated with Claude Code

dnplkndll avatar Mar 29 '26 23:03 dnplkndll

Connected to Huly®: UBERF-16138

huly-github-staging avatar Mar 29 '26 23:03 huly-github-staging

Hi @dnplkndll Could you please update dependency versions in new packages? The rush check step is failed due to this(CI / build (pull_request)):

Starting "rush check"
@hcengineering/analytics
  workspace:^0.7.19
   - @hcengineering/account
   - @hcengineering/account-service
   - @hcengineering/activity-resources
   - @hcengineering/ai-assistant-resources
   - @hcengineering/analytics-providers
   (and 82 others)
  workspace:^0.7.17
   - @hcengineering/opensearch
   - @hcengineering/typesense

@hcengineering/core
  workspace:^0.7.26
   - @hcengineering/account
   - @hcengineering/account-client
   - @hcengineering/account-service
   - @hcengineering/achievement
   - @hcengineering/achievement-resources
   (and 385 others)
  workspace:^0.7.24
   - @hcengineering/opensearch
   - @hcengineering/typesense

@hcengineering/platform
  workspace:^0.7.20
   - @hcengineering/account
   - @hcengineering/account-client
   - @hcengineering/account-service
   - @hcengineering/achievement
   - @hcengineering/achievement-assets
   (and 435 others)
  workspace:^0.7.19
   - @hcengineering/opensearch
   - @hcengineering/typesense

@hcengineering/server-core
  workspace:^0.7.19
   - @hcengineering/account
   - @hcengineering/ai-bot
   - @hcengineering/backup-api-pod
   - @hcengineering/backup-service
   - @hcengineering/collaboration
   (and 154 others)
  workspace:^0.7.18
   - @hcengineering/opensearch
   - @hcengineering/typesense

@hcengineering/platform-rig
  workspace:^0.7.21
   - @hcengineering/account
   - @hcengineering/account-client
   - @hcengineering/account-service
   - @hcengineering/achievement
   - @hcengineering/achievement-assets
   (and 472 others)
  workspace:^0.7.19
   - @hcengineering/opensearch
   - @hcengineering/typesense

ArtyomSavchenko avatar Apr 03 '26 02:04 ArtyomSavchenko