Skip to content

feat: expose the text field option highlight_offsets in the gRPC API, the HTTP gateway, the CLI and the bindings #1879

Done

Description

@mosuka

Background

Issue #596 adds the text field option highlight_offsets to TextOption. A field that sets it stores its tokens, and a search highlights it from them instead of analyzing each hit's stored text again. The core reads it from a JSON or TOML schema (serde) and from TextOption::highlight_offsets, but nothing else exposes it yet:

  • The gRPC TextOption message (laurus-server/proto/laurus/v1/index.proto) has no field for it. field_option_from_proto sets the default (false), and field_option_to_proto drops it. So a schema read through the server or MCP and written back turns the option off.
  • The HTTP gateway's TEXT_OPTION_KEYS (laurus-server/src/gateway/convert.rs) rejects the key.
  • The CLI's create schema wizard (laurus-cli/src/commands/create.rs) does not ask for it.
  • The Python, Node.js, WASM, Ruby and PHP add_text_field take no parameter for it; they set false.

Goal

Every front end that takes a text field's options takes highlight_offsets, and round-trips it.

Acceptance criteria

  • The proto's TextOption gets optional bool highlight_offsets = 8, tri-state like term_vectors; field_option_to_proto and field_option_from_proto carry it, with a round-trip test.
  • The HTTP gateway accepts and emits the key (TEXT_OPTION_KEYS, the JSON conversions, FIELD_OPTION_BOOLEAN_KEYS, and TEXT_KEYS in laurus-server/tests/http_boolean_key_validation_test.rs).
  • The CLI's wizard asks for it.
  • The five bindings take it as a parameter appended after the existing ones, so positional callers keep working (scripts/check-binding-snippets.py checks the fifth argument).
  • The docs of the gRPC API, the HTTP gateway, the CLI and each binding (en/ja) list it.

References

Tasks

Activity

  1. added
    enhancement
    on Dec 3, 2026
  2. mosuka commented on Dec 5, 2026

    @mosuka
    OwnerAuthor

    Investigation

    All on main at ce5f3baf. Outside the core, highlight_offsets appears only where a front end fixes it to the default.

    The core

    • TextOption::highlight_offsets (laurus/src/lexical/core/field.rs:283-284) is a bool with #[serde(default)], so false when omitted. The builder method is TextOption::highlight_offsets(bool) (field.rs:375-378).
    • Nothing rejects it on a field that is not indexed and stored: it takes effect only on such a field.
      • The writer: highlight_offsets_for, lexical/index/inverted/writer.rs:238-242.
      • The search: engine.rs:5550.
      • The classification of a field change: engine/schema.rs:741.

    gRPC

    • TextOption in laurus-server/proto/laurus/v1/index.proto:127-159 uses field numbers 1 to 7. term_vectors is optional bool term_vectors = 3, a tri-state.
    • field_option_to_proto (laurus-server/src/convert/schema.rs:152-160) has nothing to carry the option to.
    • field_option_from_proto sets the core's default: // Not in the proto yet (Issue #596): the default. (convert/schema.rs:278-279).
    • So a schema written through the server and read back has the option off.
    • The tri-state round-trip tests to follow are schema_field_option_text_multi_valued_round_trip (convert/schema.rs:1978) and doc_values_round_trips_through_proto_and_unset_defaults_to_true (convert/schema.rs:2098).

    MCP

    create_index, add_field and update_field (laurus-mcp/src/server.rs:429, :548, :647) read the JSON with serde into the core types, then convert them with to_proto or field_option_to_proto. So MCP accepts "highlight_offsets": true and silently drops it on the way to the server. Fixing the conversion fixes MCP. No MCP code or docs name the option.

    The HTTP gateway (laurus-server/src/gateway/convert.rs)

    • TEXT_OPTION_KEYS (:805-812) has seven keys, so the gateway rejects highlight_offsets.
    • json_to_proto_field_option (:686-709) reads term_vectors with json_optional_bool, and proto_field_option_to_json (:868-887) writes it.
    • These tests list the text keys: FIELD_OPTION_BOOLEAN_KEYS (:2691-2721) and TEXT_KEYS (laurus-server/tests/http_boolean_key_validation_test.rs:98-103).

    The CLI

    • prompt_text_option (laurus-cli/src/commands/create.rs:381-464) asks for indexed, stored, term_vectors, doc_values, multi_valued, then the analyzer.
    • It sets highlight_offsets: false with // Not asked yet; a schema file can set it (Issue #596). (:463-464).
    • It asks for position_increment_gap only when the field is multi-valued, which is a precedent for asking only when the answer matters.
    • No test drives the prompts.

    The bindings

    Each sets highlight_offsets: false (// Not a parameter yet (Issue #596).):

    Binding Signature Parameters after the name
    Python laurus-python/src/schema.rs:282-293 keyword-only: stored, indexed, term_vectors, doc_values, multi_valued, position_increment_gap, analyzer
    Node.js laurus-nodejs/src/schema.rs:205-213 positional: stored, indexed, termVectors, docValues, analyzer, multiValued, positionIncrementGap
    WASM laurus-wasm/src/schema.rs:304-313 positional, as Node.js
    Ruby laurus-ruby/src/schema.rs:385, keywords at :407-414 keywords
    PHP laurus-php/src/schema.rs:239-249 positional: stored, indexed, termVectors, docValues, analyzer, multiValued, positionIncrementGap
    • positionIncrementGap (Issue feat(schema): multi_valued support for Text fields #1175) was appended last so that positional callers keep working. The new parameter can follow it the same way.
    • scripts/check-binding-snippets.py checks the fifth argument of addTextField (docValues), so a parameter appended last needs no change there.
    • WASM's own tests call add_text_field with every argument (10 calls in laurus-wasm/src/index.rs, e.g. :2596), so they get one more.

    Docs (English and Japanese)

    • concepts/schema_and_fields.md "Stored tokens for highlighting" says that the gRPC API, the HTTP gateway, the CLI's create wizard and the bindings do not take the option yet (:125-127, ja :122-124).
    • laurus-server/grpc_api.md:113 and laurus-server/http_gateway.md:178 (ja :116) list the text options without it.
    • laurus-cli/commands.md:108 lists the wizard's text options as indexed, stored, term_vectors only. It already misses doc_values, multi_valued and the analyzer.
    • Each binding's api_reference.md has the add_text_field signature:
      • Python :231, Node.js :211, WASM :643, Ruby :201, PHP :207;
      • the Japanese pages: :234, :213, :640, :203, :209.
    • The PHP README (en and ja) shows addTextField's parameters.
    • laurus-cli/schema_format.md already documents the option for schema files.

    Choices for the plan

    • The bindings' parameter:
      • appended after position_increment_gap, default false;
      • named highlight_offsets in Python and Ruby (keywords) and highlightOffsets in Node.js, WASM and PHP, like their other parameters.
    • The CLI wizard: ask "Store tokens for highlighting?" (default no) only when the field is indexed and stored, as position_increment_gap is asked only for a multi-valued field. Elsewhere the option would have no effect.
    • MCP: no code change, but a test that a text field added with the option through MCP keeps it. That is the path that drops it silently now.
    • The CLI's option list in commands.md: add only highlight_offsets. The other missing options are out of scope.
  3. mosuka commented on Dec 5, 2026

    @mosuka
    OwnerAuthor

    Plan

    Following the investigation. Nothing breaks: the proto gets an optional field, and the bindings get a parameter at the end.

    The shape

    • Every front end round-trips the core TextOption's value.
      • The proto field is a tri-state optional bool, like term_vectors. When it is omitted, the option takes the core's default (false).
      • The gateway and MCP carry the value through the proto conversion.
    • The bindings append the parameter.
      • It goes after position_increment_gap, as that one did (Issue feat(schema): multi_valued support for Text fields #1175), so positional callers keep working.
      • Its default is false.
      • Its name follows each language: highlight_offsets in Python and Ruby, highlightOffsets in Node.js, WASM and PHP.
    • The wizard asks only when it matters. The option takes effect only on an indexed and stored field. So the wizard asks "Store tokens for highlighting?" (default no) only for such a field, and sets false otherwise. That is how it asks for position_increment_gap only for a multi-valued field.

    Changes

    • laurus-server/proto/laurus/v1/index.proto: TextOption gets optional bool highlight_offsets = 8;.
    • laurus-server/src/convert/schema.rs:
      • field_option_to_proto sets Some(o.highlight_offsets).
      • field_option_from_proto reads o.highlight_offsets.unwrap_or(default.highlight_offsets).
    • laurus-server/src/gateway/convert.rs:
      • TEXT_OPTION_KEYS gets the key.
      • json_to_proto_field_option reads it with json_optional_bool.
      • proto_field_option_to_json writes it as it writes term_vectors.
    • laurus-cli/src/commands/create.rs: prompt_text_option asks for it when the field is indexed and stored.
    • The five bindings' add_text_field:
      • The parameter is appended, in place of the fixed highlight_offsets: false, and the doc comments describe it.
      • WASM's tests that call add_text_field with every argument get one more.
    • Docs (English and Japanese):
      • concepts/schema_and_fields.md, "Stored tokens for highlighting": how each front end sets the option, instead of "do not take it yet".
      • laurus-server/grpc_api.md: the TextOption fields and the tri-state.
      • laurus-server/http_gateway.md: the boolean keys.
      • laurus-cli/commands.md: the wizard's text options get highlight_offsets.
      • Each binding's api_reference.md: the signature and the parameter.
      • The PHP README.

    Tests, written first

    • Conversion: highlight_offsets_round_trips_through_proto_and_unset_defaults_to_false checks that:

      • true and false round-trip through the proto;
      • an omitted field reads as false;
      • it does not touch term_vectors.
    • The gateway:

      • highlight_offsets joins the text keys of FIELD_OPTION_BOOLEAN_KEYS. The existing tests then check that a non-boolean is rejected, that null is the same as omitting the key, and that true and false round-trip.
      • It also joins TEXT_KEYS in tests/http_boolean_key_validation_test.rs, which checks the 400 through the server and that update_field accepts it.
    • MCP: {"Text": {"highlight_offsets": true}}, read with serde into FieldOption as MCP reads it, comes out of field_option_to_proto as Some(true).

    • Each binding: an index created with the option writes highlight_offsets = true to its schema.toml, and one created without it writes false.

      • Python, Node.js, Ruby and PHP check this beside their index-directory tests.
      • WASM checks the built schema's TextOption in a wasm_bindgen_test.
    • The CLI wizard: no test drives its prompts. It will be run under a pseudo-terminal (Python's pty) to check when it asks and what schema.toml it writes, and the result goes in the PR. If that cannot be done, the PR says the wizard is unverified.

    • RED: each element is disabled in turn, the tests run, and the sources restored and compared:

      • E1: field_option_to_proto drops the field. The conversion and MCP tests fail.
      • E2: field_option_from_proto takes the default. The conversion test fails.
      • E3: TEXT_OPTION_KEYS lacks the key. The gateway's unit and HTTP tests fail.
      • E4: proto_field_option_to_json does not write it. The round-trip test fails.
      • E5: all five bindings ignore the parameter, in one run of the bindings. Each binding's new test fails.

      On main the new field and parameters do not exist, so the new tests do not compile or run there. The elements above show the RED.

    Verification

    • RED and GREEN.
    • The CI-equivalent checks and the five bindings.
      • scripts/check-binding-snippets.py checks the fifth argument, which does not move.
    • markdownlint on the docs.
    • An adversarial review by a subagent, given the code only.

    Out of scope

    • The other text options missing from the wizard's list in laurus-cli/commands.md (doc_values, multi_valued, the analyzer).
    • Rejecting highlight_offsets on a field that is not indexed and stored. The core lets it have no effect there, and that stays.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions