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 string
literals under a built-in predicate allowlist (every predicate, if you set
predicates = []), 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
# predicates = [ # optional. Absent: a built-in list of common text
# "https://schema.org/name", # predicates. []: every predicate.
# "https://schema.org/description", # A list replaces the built-in one.
# ]
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.
For a worked setup and the practices that keep text search dependable, see Text Search Best Practice.
text:query — full-text FILTER
text:query runs a full-text query expression — terms, AND / OR,
quoted phrases, and a leading - that excludes a term — against the
analyzed text of every indexed 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.
Operators in the search string are upper-case (and, or, and not in
lower case are searched as ordinary words), a query made only of
exclusions is an error, and there is no wildcard or field prefix. The
literal form searches the indexed predicates and only those: a literal
under a predicate outside the predicates list is simply not found, with
no error. The example therefore assumes http://ex/label is in the
list.
To restrict a search to one language, add a trailing lang:xx
argument, written as a plain string. Tags match exactly and are stored in
lower case:
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; one index search
covers the whole set, and the subjects are resolved in the object
partition, where the index lives, so the matched values are never read
back. Every named predicate must be in the index’s predicates
allowlist — naming an unindexed predicate is a query error rather than a
silently empty result for that field (see the
text.toml reference). Bind the subject variable with a triple pattern
in the same group, as ?species a ex:TaxonomicNode does above.
When the subject variable, or a literal-form variable, holds a single
known value — one VALUES row, or BIND of a constant — the call is
answered as a membership test instead of a search.
The subject form’s search sees 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 the graph ?g is bound
to, and with --default-union every graph is visible — same answers the
plain triple patterns would produce.
Two rules keep the semantics honest:
-
text:queryonly works inFILTER. 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.
These functions are exact and case-sensitive. The index is consulted only
when every value of the searched variable comes from an indexed
predicate; when the variable can also be bound by a VALUES column, a
BIND, or a predicate outside the predicates list, the filter runs over
every row instead — the same answers, without the shortcut.
If the index is unavailable
-
STRSTARTS/STRENDS/ anchoredREGEXfall back to the plain filter — same answers, slower. -
text:queryfails 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. Over HTTP the response status is 400, with the message as the body.
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, seed_chars, or predicates in text.toml changes the
index’s identity. An existing index built with other settings is refused at
startup and import (never rebuilt automatically): the command exits with a
message naming both identities before it opens the store. An index built by
Waratah 0.6.1 or earlier is such a case — its layout differs, and every text
index must be rebuilt once after upgrading. Rebuild with
waratah text rebuild-index on a stopped data dir; it replaces the
mismatched index.
A store that has no text index yet needs no rebuild: the first start with the plugin enabled builds it over the whole store before answering queries.
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. The search string has no wildcard and no field prefix.
text:query is accepted only as a plain, top-level FILTER conjunct. A
call nested inside ||, !, IF, or COALESCE fails at plan time; a
call used as a triple predicate (?s text:query with a string as the
object) fails too. Use a UNION of two arms for alternatives and
FILTER NOT EXISTS for exclusion — the
best-practice page
shows both.
A text:query FILTER inside an OPTIONAL is accepted when it tests a
variable the OPTIONAL itself binds, and rejected when it tests a variable
bound outside it: the injected candidate scan would then decide whether
the outer row survives. The rejection is a plan-time error that says so.
To filter on an outer variable, write the text:query FILTER after the
OPTIONAL.
A subject-form call needs a triple pattern in its group that binds the subject variable; without one the query fails.