Full-Text Search

The text plugin adds Jena-style full-text search over string literals: a text:query FILTER backed by a full-text index, plus index-accelerated STRSTARTS / STRENDS / anchored-REGEX filters. Unlike geospatial and temporal support, the text plugin is off by default — it indexes every string literal in your store up to a size limit (see [size-limit]), so you opt in:

waratah start --data-dir ./waratah-data --with-text

or persistently, with {config-dir}/text.toml:

enabled = true
analyzer = "simple"   # or "en_stem" (English stemming), "whitespace"
seed_chars = 16       # characters kept for prefix/suffix matching

The first start with the plugin enabled builds the text index before serving queries (the index lives beside the store, in a Tantivy directory on the object partition). Later starts reuse it.

text:query — full-text FILTER

text:query runs a full-text query expression — terms, AND / OR / NOT, quoted phrases — against the analyzed text of every string literal. Multi-term queries are disjunctions by default (laser printer means laser OR printer); write AND when you need both terms:

PREFIX ex: <http://ex/>
PREFIX text: <http://jena.apache.org/text#>

SELECT ?label WHERE {
  ?item ex:label ?label .
  FILTER(text:query(?label, "laser printer"))
}

Without the FILTER, a query like this scans every ex:label row and tests it. With it, the planner strips the conjunct and answers it from the index, joining the matching literals back onto ?label — the rest of the query only sees rows the index already matched.

To restrict a search to one language, add a trailing "lang:xx" argument:

FILTER(text:query(?label, "bonjour", "lang:fr"))

To find the subjects whose property text matches — the Jena subject form — name the predicate in the call and leave the value unbound. Bind the subject with whatever other patterns you need (its type, for instance); the searched predicate appears only inside text:query, and you never need a variable for the matched text:

SELECT ?species WHERE {
  ?species a ex:TaxonomicNode .
  ?species ex:hasRank ex:Species .
  FILTER(text:query(?species, ex:hasName, "bellendena"))
}

The subject form never multiplies rows: a subject with several matching values appears once. You can pass several predicates; the search runs over all of them.

The subject form’s injected property scans see exactly the graphs the rest of the query sees: a bare BGP matches the unnamed graph, FROM <g> restricts the search to g, GRAPH ?g { …​ } searches within g, and with --default-union every graph is visible — same answers the plain triple patterns would produce.

Two rules keep the semantics honest:

  • text:query only works in FILTER. Writing it as a graph pattern (?s text:query "word") is a query error, not an empty result.

  • If the variable you pass can only hold subjects (or, for the subject form, only literals), the query fails with an explanation naming the other form — the usual Jena reflex ?s text:query "word" is caught at plan time.

Prefix and suffix matching

STRSTARTS, STRENDS, and anchored REGEX are answered from a compact prefix/suffix structure beside the full-text index. You write ordinary SPARQL — nothing changes semantically, the planner only narrows which rows are tested:

SELECT ?label WHERE {
  ?species ex:label ?label .
  FILTER(STRSTARTS(?label, "Bellendena"))
}

STRENDS(?label, "montana") and REGEX(?label, "^Bellendena") / REGEX(?label, ".*montana$") work the same way. A general REGEX still works — it just does not get the index shortcut. General means the anchored body contains regex syntax (any of . * + ? | ( ) [ ] { } \ ^ $) or the call passes flags: such a pattern is answered by the exact residual below, never by a candidate seed (a seed carries the body’s characters as literal text, which a regex reads as operators). Results are always exactly what the plain FILTER would produce; the index only decides which rows get tested.

Short patterns (up to seed_chars characters) are answered entirely from the index. Longer patterns use their first (or last) seed_chars characters to narrow candidates, then the exact filter decides — same answers, still fast.

If the index is unavailable

The two feature families degrade differently when the text index is missing, unbuilt, or was built with different settings:

  • STRSTARTS / STRENDS / anchored REGEX fall back to the plain filter — same answers, slower.

  • text:query fails the query with a message naming the repair command. There is no slow path for a full-text query; the error is the honest answer.

The repair command rebuilds the index offline (stop the cluster first — the index directory is single-writer):

waratah text rebuild-index --data-dir ./waratah-data
waratah text status --data-dir ./waratah-data

Changing analyzer or seed_chars in text.toml changes the index’s identity: an existing index built with the old settings is reported untrusted until you rebuild.

Size limit

A string literal longer than 1 MiB (1,048,576 bytes) cannot be written to a clustered store (waratah start, waratah import): the string registry — the store’s dictionary service — rejects any string over 1 MiB (MAX_REGISTERED_STRING_BYTES), whether or not the text plugin is enabled. The whole write fails with an error naming the limit; the literal is not stored. The registry limit exists because every stored string must travel back inside a single query-response message; multi-megabyte values are a data-modeling error better kept in object storage and referenced by IRI.

Single-process stores (waratah standalone, waratah import --offline) have no registry length check; there the text plugin enforces the same 1 MiB limit (MAX_INDEXED_LEXICAL_BYTES) while it is enabled, and no length limit applies with the plugin disabled.

The two limits are deliberately the same number, so the answer to "how long can a literal be" is 1 MiB everywhere the text plugin is enabled. If your data legitimately contains literals that large, hold them on a single-process store with the text plugin disabled; a clustered store cannot hold them today. Where the plugin is enabled, the text features fail or fall back as described in [index-unavailable] when the index is unavailable.

What is not supported

CONTAINS and general (unanchored) REGEX are not index-accelerated — they run as ordinary filters. text:query has no score, highlight, or limit arguments in this release, and STR(?v)-wrapped arguments are not rewritten.

A text:query FILTER inside an OPTIONAL is not a supported position. Depending on the surrounding pattern the query either fails at plan time (the lowering moves the body’s filter into the OPTIONAL’s join condition, where the injected candidate scan would decide outer rows) or rewrites; only a FILTER in a plain group pattern behaves the same way in every query. Write the pattern and its text:query FILTER outside the OPTIONAL.