vsql_textsearch adds BM25 full-text search to MySQL. You store text in a
DOC(n) column, put a bm25 index on it, and ask for the best matches with
ORDER BY bm25_distance(column, 'query') LIMIT n. The index ranks rows with
BM25, the ranking function that Lucene uses, and stems English words, so a
search for run dog finds a row that says running dogs.
Install
vsql_textsearch is not bundled with the server, so build it from the
repository first, against your server build tree:
cmake --install copies vsql_textsearch.veb into the server build’s
veb_output_directory, which is the lib/veb directory that the server reads.
Then install it:
vsql_allow_preview_extensions is OFF, the install fails:
What it adds
The index takes these options in a
WITH (...) clause. An option that you
leave out takes its default.
bm25_indexes, bm25_status, bm25_spill, and bm25_merge are a temporary
interface for testing. They name an index by an internal id
(tablespace:root page), and they do not check privileges: an account with
only USAGE can call them.
Example
Create the table and the index while the table is empty, then insert:bm25_query, through a user
variable:
Limits
-
A search must be a query that the index serves:
ORDER BY bm25_distance(...)in ascending order, with aLIMIT, and the same search text everywherebm25_distanceappears. Any other query that callsbm25_distancefails: -
A
WHEREclause works while the bm25 index still serves the query. A range condition on another index, such asWHERE id < 4on the primary key, makes the optimizer use that index, and the query fails with the error above. -
bm25_query(...)written directly insidebm25_distance(...)fails with anIncorrect DOC valueerror. Pass it through a user variable or a prepared-statement parameter. -
Only a
DOCcolumn takes a bm25 index. OnVARCHARorTEXT,CREATE INDEXfails withERROR 3219 (HY000): No default index profile found: column 'body' is not a custom type. -
A value longer than
nbytes fails withERROR 3219 (HY000): DOC: text longer than the column's length. -
A
DOCvalue must come from a column, a literal, or a user variable. An expression such asCONCAT(...)fails withERROR 3219 (HY000): Incorrect DOC value: cannot implicitly cast string expression. Use explicit conversion for column 'body' at row 1. -
A bad index option or a filter with a syntax error fails with
ERROR 3219 (HY000): InnoDB: Custom type operation failed. See server error log for details.The reason is only in the server error log. - The stored format can change between versions of the extension.
See also
- Ranked full-text search with BM25 — a worked search over a table of articles, with filters
- Preview capabilities — what the preview flag turns on and what it promises
- Available extensions — the full catalog
- villagesql/vsql-textsearch — source, build instructions, and the current limits