Full-text search: fulltext
fulltext ranks entities by the words of their text fields. It keeps an
index of the fields that its settings name, and the query clause
fulltext/match finds the entities whose indexed text matches a query and
gives each one a BM25 relevance score. It requires database, and keeps its
index in the database storage. Without fulltext, a query has no full-text
clause.
| Setting | Accepts | Purpose | Default |
|---|---|---|---|
analyzer | An analyzer name | The analyzer of each field that does not set its own. | None: each field sets one |
fields | A map from a field name to true or to {analyzer …} | The fields the index holds, each with its analyzer. | No fields |
Each field is true, which takes the top-level analyzer, or a map with its
own analyzer. Each field must get an analyzer from one of the two. The
plugin refuses a field without an analyzer, an unknown analyzer or an unknown
setting when the database opens.
Dependencies
- Requires
database
Configuration
Select this plugin, and database with a path, when opening the database:
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 000 | 54 52 4F 4E | magic TRON |
| 004 | 4C 70617468 | txt "path" |
| 009 | 6C 6170702E6462 | txt "app.db" |
| 010 | 0F 0A 04000000 0900 0000 | map leaf, size 10: @4 → @9 |
| 01A | 6C 236C6F63616C | txt "#local" |
| 021 | 7C 656E676C697368 | txt "english" |
| 029 | 0F 0A 1A000000 2100 0000 | map leaf, size 10: @1A → @21 |
| 033 | 6C 236C6F63616C | txt "#local" |
| 03A | 6C 6672656E6368 | txt "french" |
| 041 | 0F 0A 33000000 3A00 0000 | map leaf, size 10: @33 → @3A |
| 04B | 8C 616E616C797A65 72 | txt "analyzer" |
| 054 | 0F 0A 4B000000 4100 0000 | map leaf, size 10: @4B → @41 |
| 05E | 4C 626F6479 | txt "body" |
| 063 | 0F 0A 5E000000 5400 0000 | map leaf, size 10: @5E → @54 |
| 06D | 5C 7469746C65 | txt "title" |
| 073 | 09 | bit true |
| 074 | 0F 0A 6D000000 7300 0000 | map leaf, size 10: @6D → @73 |
| 07E | 07 0E 10400000 6300 0000 74000000 | map branch, size 14, depth 0 (root), slots 4, 14: @63 → @74 |
| 08C | 8C 616E616C797A65 72 | txt "analyzer" |
| 095 | 0F 0A 8C000000 2900 0000 | map leaf, size 10: @8C → @29 |
| 09F | 6C 6669656C6473 | txt "fields" |
| 0A6 | 0F 0A 9F000000 7E00 0000 | map leaf, size 10: @9F → @7E |
| 0B0 | 07 0E 0A000000 9500 0000 A6000000 | map branch, size 14, depth 0 (root), slots 1, 3: @95 → @A6 |
| 0BE | 8C 66756C6C746578 74 | txt "fulltext" |
| 0C7 | 0F 0A BE000000 B000 0000 | map leaf, size 10: @BE → @B0 |
| 0D1 | 8C 64617461626173 65 | txt "database" |
| 0DA | 0F 0A D1000000 1000 0000 | map leaf, size 10: @D1 → @10 |
| 0E4 | 07 0E 40100000 C700 0000 DA000000 | map branch, size 14, depth 0 (root), slots 6, 12: @C7 → @DA |
| 0F2 | 7C 706C7567696E73 | txt "plugins" |
| 0FA | 0F 0A F2000000 E400 0000 | map leaf, size 10: @F2 → @E4 |
| 104 | FA000000 00000000 | root → @FA; previous: none |
The index
The index holds the text values of the named fields. It does not hold numbers, lists, maps or field names. The text fields of one entity make one document. Each write updates the index in the same transaction as its facts, so a query always reads the index of the current facts.
A database that opens with other fields or analyzers than its index was built
with, or after a host without fulltext wrote to it, builds the index again
from the current facts before the first request.
The fulltext/rebuild request builds it again on demand.
The clause
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 000 | 54 52 4F 4E | magic TRON |
| 004 | 6C 236C6F63616C | txt "#local" |
| 00B | EC 66756C6C746578 742F6D61746368 | txt "fulltext/match" |
| 01A | 0F 0A 04000000 0B00 0000 | map leaf, size 10: @4 → @B |
| 024 | 6C 236C6F63616C | txt "#local" |
| 02B | 5C 7175657279 | txt "query" |
| 031 | 0F 0A 24000000 2B00 0000 | map leaf, size 10: @24 → @2B |
| 03B | 6C 236C6F63616C | txt "#local" |
| 042 | 7C 3F656E74697479 | txt "?entity" |
| 04A | 0F 0A 3B000000 4200 0000 | map leaf, size 10: @3B → @42 |
| 054 | 6C 236C6F63616C | txt "#local" |
| 05B | 6C 3F73636F7265 | txt "?score" |
| 062 | 0F 0A 54000000 5B00 0000 | map leaf, size 10: @54 → @5B |
| 06C | 6C 236C6F63616C | txt "#local" |
| 073 | 5C 7469746C65 | txt "title" |
| 079 | 0F 0A 6C000000 7300 0000 | map leaf, size 10: @6C → @73 |
| 083 | 0E 0D 00 0100 010000 00 79000000 | array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @79 |
| 090 | 6C 236C6F63616C | txt "#local" |
| 097 | 7C 656E676C697368 | txt "english" |
| 09F | 0F 0A 90000000 9700 0000 | map leaf, size 10: @90 → @97 |
| 0A9 | 8C 616E616C797A65 72 | txt "analyzer" |
| 0B2 | 0F 0A A9000000 9F00 0000 | map leaf, size 10: @A9 → @9F |
| 0BC | 6C 6669656C6473 | txt "fields" |
| 0C3 | 0F 0A BC000000 8300 0000 | map leaf, size 10: @BC → @83 |
| 0CD | 5C 746F702D6B | txt "top-k" |
| 0D3 | 02 0A000000000000 00 | i64 10 |
| 0DC | 0F 0A CD000000 D300 0000 | map leaf, size 10: @CD → @D3 |
| 0E6 | 07 12 0A040000 B200 0000 C3000000 DC00 0000 | map branch, size 18, depth 0 (root), slots 1, 3, 10: @B2 → @C3 → @DC |
| 0F8 | 0E 1D 00 1F00 050000 00 1A000000 310000 00 4A000000 620000 00 E6000000 | array leaf, size 29, shift 0, bitmap 001F, count 5 (root): @1A → @31 → @4A → @62 → @E6 |
| 115 | F8000000 00000000 | root → @F8; previous: none |
The clause binds ?entity and ?score for each hit. The query is a text, a
:input, a ?variable that the query's in or another clause binds, or a
map:
| Query | Matches |
|---|---|
"red shoes" or {term "red shoes"} | Documents with every word |
{phrase "red shoes"} | The words next to each other, in order |
{prefix "sho"} | Words that start with the text |
{and [q ...]}, {or [q ...]} | All of the queries, any of them |
{not q} | Excludes q, inside an and with a positive query |
| Option | Accepts | Default |
|---|---|---|
top-k | An integer of 1 or more: the most hits the clause gives | 100 |
analyzer | The analyzer of the query text | english |
fields | A list of indexed fields: the search reads only their text and statistics | Each indexed field |
Hits come best first; hits with the same score come in ascending entity
order. top-k keeps the best hits whose entity matches each fact pattern the
query's other clauses have on it: a value for the field, and the
pattern's value when it names one. Predicates filter the rows
afterwards. When the clause is the query's only clause and the query orders
by the score descending, limit and offset also lower the number of hits,
and the rows are those the query gives without them.
When an earlier clause has bound the entity, the clause keeps that entity only when it is among those top-k hits. The rows never depend on the order the planner picks.
In a write, such as a reactor's query, the clause finds the write's own changes, as the fact clauses do. A subscription to a query with the clause runs again when a write changes an indexed field or a field of the query's other clauses.
A query with as-of reads the indexed fields at that state: the search
builds each document from the values of that state.
Analyzers
An analyzer folds case, normalizes Unicode (NFKC), splits text into words and
stems each word with the Snowball stemmer of the same name. english also
drops English stop words. The analyzers are arabic, armenian, basque,
catalan, czech, danish, dutch, dutch_porter, earlymodernenglish,
english, esperanto, estonian, finnish, french, german, greek,
hindi, hungarian, indonesian, irish, italian, lithuanian,
lovins, nepali, norwegian, persian, polish, porter, portuguese,
romanian, russian, serbian, sesotho, spanish, swedish, tamil,
turkish and yiddish.
Status
The fulltext/status request reports fields, the indexed fields, and
documents and length, the number of indexed documents and their words.
With params {terms [...]} it also reports frequencies, the number of
documents with each analyzed term. With params {fields [...]} it reports
fieldCorpus, the documents and words of only those fields.
Contributions
Requests
fulltext/statusfulltext/rebuild