Skip to content

mod-flexsearch: ship a serialized FlexSearch index (export/import) for faster lazy load #1933

@markdumay

Description

@markdumay

Problem or enhancement idea

mod-flexsearch v4's new lazyLoad option (added in gethinode/mod-flexsearch@caaa1fb) fetches a JSON array of documents on the visitor's first search interaction and calls index.add(doc) per document. Tokenization runs in the browser. On large sites this is acceptable but not the fastest available option.

Proposed solution

FlexSearch v0.8 supports Document.export() / Document.import() for serialized indices. The proposal:

  • At build time, serialize the index via Document.export() and emit the chunked JSON output FlexSearch produces (per field, per stage: reg, tag, doc, map).
  • Switch the lazy runtime in flexsearch.index.js to fetch and import() instead of fetch and per-document add().

Estimated wins: faster first search (no client-side tokenization) and a smaller transferred payload (~40-50% per the FlexSearch docs).

Alternatives

Keep the current JSON-array + add() path. It is simpler and version-independent of FlexSearch's serialization format, at the cost of CPU on first search.

Additional context

  • lazyLoad introduced in gethinode/mod-flexsearch@caaa1fb (feat: add lazyLoad option to fetch the search index on demand).
  • The plan for the original lazy-load work flagged this as the next perf step.
  • Implementation needs a Node-side step at build time to invoke export() and a corresponding import() in the client.
  • Couples mod-flexsearch to the FlexSearch v0.8.x serialization format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions