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.

SettingAcceptsPurposeDefault
analyzerAn analyzer nameThe analyzer of each field that does not set its own.None: each field sets one
fieldsA 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

Configuration

Select this plugin, and database with a path, when opening the database:

TRON268 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0044C 70617468txt "path"
0096C 6170702E6462txt "app.db"
0100F 0A 04000000 0900 0000map leaf, size 10: @4 → @9
01A6C 236C6F63616Ctxt "#local"
0217C 656E676C697368txt "english"
0290F 0A 1A000000 2100 0000map leaf, size 10: @1A → @21
0336C 236C6F63616Ctxt "#local"
03A6C 6672656E6368txt "french"
0410F 0A 33000000 3A00 0000map leaf, size 10: @33 → @3A
04B8C 616E616C797A65 72txt "analyzer"
0540F 0A 4B000000 4100 0000map leaf, size 10: @4B → @41
05E4C 626F6479txt "body"
0630F 0A 5E000000 5400 0000map leaf, size 10: @5E → @54
06D5C 7469746C65txt "title"
07309bit true
0740F 0A 6D000000 7300 0000map leaf, size 10: @6D → @73
07E07 0E 10400000 6300 0000 74000000map branch, size 14, depth 0 (root), slots 4, 14: @63 → @74
08C8C 616E616C797A65 72txt "analyzer"
0950F 0A 8C000000 2900 0000map leaf, size 10: @8C → @29
09F6C 6669656C6473txt "fields"
0A60F 0A 9F000000 7E00 0000map leaf, size 10: @9F → @7E
0B007 0E 0A000000 9500 0000 A6000000map branch, size 14, depth 0 (root), slots 1, 3: @95 → @A6
0BE8C 66756C6C746578 74txt "fulltext"
0C70F 0A BE000000 B000 0000map leaf, size 10: @BE → @B0
0D18C 64617461626173 65txt "database"
0DA0F 0A D1000000 1000 0000map leaf, size 10: @D1 → @10
0E407 0E 40100000 C700 0000 DA000000map branch, size 14, depth 0 (root), slots 6, 12: @C7 → @DA
0F27C 706C7567696E73txt "plugins"
0FA0F 0A F2000000 E400 0000map leaf, size 10: @F2 → @E4

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

TRON285 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0046C 236C6F63616Ctxt "#local"
00BEC 66756C6C746578 742F6D61746368txt "fulltext/match"
01A0F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
0246C 236C6F63616Ctxt "#local"
02B5C 7175657279txt "query"
0310F 0A 24000000 2B00 0000map leaf, size 10: @24 → @2B
03B6C 236C6F63616Ctxt "#local"
0427C 3F656E74697479txt "?entity"
04A0F 0A 3B000000 4200 0000map leaf, size 10: @3B → @42
0546C 236C6F63616Ctxt "#local"
05B6C 3F73636F7265txt "?score"
0620F 0A 54000000 5B00 0000map leaf, size 10: @54 → @5B
06C6C 236C6F63616Ctxt "#local"
0735C 7469746C65txt "title"
0790F 0A 6C000000 7300 0000map leaf, size 10: @6C → @73
0830E 0D 00 0100 010000 00 79000000array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @79
0906C 236C6F63616Ctxt "#local"
0977C 656E676C697368txt "english"
09F0F 0A 90000000 9700 0000map leaf, size 10: @90 → @97
0A98C 616E616C797A65 72txt "analyzer"
0B20F 0A A9000000 9F00 0000map leaf, size 10: @A9 → @9F
0BC6C 6669656C6473txt "fields"
0C30F 0A BC000000 8300 0000map leaf, size 10: @BC → @83
0CD5C 746F702D6Btxt "top-k"
0D302 0A000000000000 00i64 10
0DC0F 0A CD000000 D300 0000map leaf, size 10: @CD → @D3
0E607 12 0A040000 B200 0000 C3000000 DC00 0000map branch, size 18, depth 0 (root), slots 1, 3, 10: @B2 → @C3 → @DC
0F80E 1D 00 1F00 050000 00 1A000000 310000 00 4A000000 620000 00 E6000000array leaf, size 29, shift 0, bitmap 001F, count 5 (root): @1A → @31 → @4A → @62 → @E6

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:

QueryMatches
"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
OptionAcceptsDefault
top-kAn integer of 1 or more: the most hits the clause gives100
analyzerThe analyzer of the query textenglish
fieldsA list of indexed fields: the search reads only their text and statisticsEach 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/status
  • fulltext/rebuild