Repository navigation
Done
Labels
enhancementNew feature or request
Description
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
TextOptionmessage (laurus-server/proto/laurus/v1/index.proto) has no field for it.field_option_from_protosets the default (false), andfield_option_to_protodrops 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 schemawizard (laurus-cli/src/commands/create.rs) does not ask for it. - The Python, Node.js, WASM, Ruby and PHP
add_text_fieldtake no parameter for it; they setfalse.
Goal
Every front end that takes a text field's options takes highlight_offsets, and round-trips it.
Acceptance criteria
- The proto's
TextOptiongetsoptional bool highlight_offsets = 8, tri-state liketerm_vectors;field_option_to_protoandfield_option_from_protocarry it, with a round-trip test. - The HTTP gateway accepts and emits the key (
TEXT_OPTION_KEYS, the JSON conversions,FIELD_OPTION_BOOLEAN_KEYS, andTEXT_KEYSinlaurus-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.pychecks the fifth argument). - The docs of the gRPC API, the HTTP gateway, the CLI and each binding (en/ja) list it.
References
- perf(lexical/search): highlight re-tokenises full field text per hit; no stored term-vectors #596 and its PR
docs/src/concepts/schema_and_fields.md"Stored tokens for highlighting"
Tasks
- Investigation (comment): where each front end fixes the option to its default (feat: expose the text field option highlight_offsets in the gRPC API, the HTTP gateway, the CLI and the bindings #1879 (comment))
- Plan (comment): the parameters, the wizard's question, and the tests (feat: expose the text field option highlight_offsets in the gRPC API, the HTTP gateway, the CLI and the bindings #1879 (comment))
- Tests that fail on
main: the proto round trip, the gateway keys, MCP, and each binding (the new field and parameters do not exist onmain, so the RED is shown by disabling each part in turn) - The proto, the conversions, the gateway, the CLI wizard and the five bindings
- The docs (en/ja), and the CI-equivalent checks with the five bindings
- Implementation PR (feat: take the text field option highlight_offsets in the gRPC API, the HTTP gateway, MCP, the CLI wizard and the five bindings, which used to fix it to false #1901)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
mosuka commentedon Dec 5, 2026
Investigation
All on
mainatce5f3baf. Outside the core,highlight_offsetsappears only where a front end fixes it to the default.The core
TextOption::highlight_offsets(laurus/src/lexical/core/field.rs:283-284) is aboolwith#[serde(default)], sofalsewhen omitted. The builder method isTextOption::highlight_offsets(bool)(field.rs:375-378).indexedandstored: it takes effect only on such a field.highlight_offsets_for,lexical/index/inverted/writer.rs:238-242.engine.rs:5550.engine/schema.rs:741.gRPC
TextOptioninlaurus-server/proto/laurus/v1/index.proto:127-159uses field numbers 1 to 7.term_vectorsisoptional 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_protosets the core's default:// Not in the proto yet (Issue #596): the default.(convert/schema.rs:278-279).schema_field_option_text_multi_valued_round_trip(convert/schema.rs:1978) anddoc_values_round_trips_through_proto_and_unset_defaults_to_true(convert/schema.rs:2098).MCP
create_index,add_fieldandupdate_field(laurus-mcp/src/server.rs:429,:548,:647) read the JSON with serde into the core types, then convert them withto_protoorfield_option_to_proto. So MCP accepts"highlight_offsets": trueand 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 rejectshighlight_offsets.json_to_proto_field_option(:686-709) readsterm_vectorswithjson_optional_bool, andproto_field_option_to_json(:868-887) writes it.FIELD_OPTION_BOOLEAN_KEYS(:2691-2721) andTEXT_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 forindexed,stored,term_vectors,doc_values,multi_valued, then the analyzer.highlight_offsets: falsewith// Not asked yet; a schema file can set it (Issue #596).(:463-464).position_increment_gaponly when the field is multi-valued, which is a precedent for asking only when the answer matters.The bindings
Each sets
highlight_offsets: false(// Not a parameter yet (Issue #596).):laurus-python/src/schema.rs:282-293stored, indexed, term_vectors, doc_values, multi_valued, position_increment_gap, analyzerlaurus-nodejs/src/schema.rs:205-213stored, indexed, termVectors, docValues, analyzer, multiValued, positionIncrementGaplaurus-wasm/src/schema.rs:304-313laurus-ruby/src/schema.rs:385, keywords at:407-414laurus-php/src/schema.rs:239-249stored, indexed, termVectors, docValues, analyzer, multiValued, positionIncrementGappositionIncrementGap(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.pychecks the fifth argument ofaddTextField(docValues), so a parameter appended last needs no change there.add_text_fieldwith every argument (10 calls inlaurus-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'screatewizard and the bindings do not take the option yet (:125-127, ja:122-124).laurus-server/grpc_api.md:113andlaurus-server/http_gateway.md:178(ja:116) list the text options without it.laurus-cli/commands.md:108lists the wizard's text options asindexed, stored, term_vectorsonly. It already missesdoc_values,multi_valuedand the analyzer.api_reference.mdhas theadd_text_fieldsignature::231, Node.js:211, WASM:643, Ruby:201, PHP:207;:234,:213,:640,:203,:209.addTextField's parameters.laurus-cli/schema_format.mdalready documents the option for schema files.Choices for the plan
position_increment_gap, defaultfalse;highlight_offsetsin Python and Ruby (keywords) andhighlightOffsetsin Node.js, WASM and PHP, like their other parameters.position_increment_gapis asked only for a multi-valued field. Elsewhere the option would have no effect.commands.md: add onlyhighlight_offsets. The other missing options are out of scope.mosuka commentedon Dec 5, 2026
Plan
Following the investigation. Nothing breaks: the proto gets an optional field, and the bindings get a parameter at the end.
The shape
TextOption's value.optional bool, liketerm_vectors. When it is omitted, the option takes the core's default (false).position_increment_gap, as that one did (Issue feat(schema): multi_valued support for Text fields #1175), so positional callers keep working.false.highlight_offsetsin Python and Ruby,highlightOffsetsin Node.js, WASM and PHP.falseotherwise. That is how it asks forposition_increment_gaponly for a multi-valued field.Changes
laurus-server/proto/laurus/v1/index.proto:TextOptiongetsoptional bool highlight_offsets = 8;.laurus-server/src/convert/schema.rs:field_option_to_protosetsSome(o.highlight_offsets).field_option_from_protoreadso.highlight_offsets.unwrap_or(default.highlight_offsets).laurus-server/src/gateway/convert.rs:TEXT_OPTION_KEYSgets the key.json_to_proto_field_optionreads it withjson_optional_bool.proto_field_option_to_jsonwrites it as it writesterm_vectors.laurus-cli/src/commands/create.rs:prompt_text_optionasks for it when the field is indexed and stored.add_text_field:highlight_offsets: false, and the doc comments describe it.add_text_fieldwith every argument get one more.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: theTextOptionfields and the tri-state.laurus-server/http_gateway.md: the boolean keys.laurus-cli/commands.md: the wizard's text options gethighlight_offsets.api_reference.md: the signature and the parameter.Tests, written first
Conversion:
highlight_offsets_round_trips_through_proto_and_unset_defaults_to_falsechecks that:trueandfalseround-trip through the proto;false;term_vectors.The gateway:
highlight_offsetsjoins the text keys ofFIELD_OPTION_BOOLEAN_KEYS. The existing tests then check that a non-boolean is rejected, thatnullis the same as omitting the key, and thattrueandfalseround-trip.TEXT_KEYSintests/http_boolean_key_validation_test.rs, which checks the 400 through the server and thatupdate_fieldaccepts it.MCP:
{"Text": {"highlight_offsets": true}}, read with serde intoFieldOptionas MCP reads it, comes out offield_option_to_protoasSome(true).Each binding: an index created with the option writes
highlight_offsets = trueto itsschema.toml, and one created without it writesfalse.TextOptionin awasm_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 whatschema.tomlit 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:
field_option_to_protodrops the field. The conversion and MCP tests fail.field_option_from_prototakes the default. The conversion test fails.TEXT_OPTION_KEYSlacks the key. The gateway's unit and HTTP tests fail.proto_field_option_to_jsondoes not write it. The round-trip test fails.On
mainthe new field and parameters do not exist, so the new tests do not compile or run there. The elements above show the RED.Verification
scripts/check-binding-snippets.pychecks the fifth argument, which does not move.Out of scope
laurus-cli/commands.md(doc_values,multi_valued, the analyzer).highlight_offsetson a field that is not indexed and stored. The core lets it have no effect there, and that stays.feat: take the text field option highlight_offsets in the gRPC API, t…