SearchIndex class base
A description used within a Scheme to define an FTS index.
An FTS index is created by SQLite as a special table with the given name (along with several supporting tables) and is useful for full-text search queries that operate on the columns of this table.
The row content (i.e., the values of the columns) of an FTS index is defined by the getters, which is a SearchRowGetters map. To enable full-text search on selected data elements of JSON values from the mapping table, the following steps must be taken:
- identify the
Kinds of JSON values (from the mapping table value column) that must be FTS-indexed; - for every
Kind, provide a SearchRowGetter callback that extracts a SearchRow from a JSON value of thatKind; - pass the resulting
Kind-SearchRowGetter pairs as a map to the getters argument of SearchIndex.new.
The set formed by the keys of a SearchRow and the set formed by the names of columns must match exactly in value and size; i.e., in the context of a particular SearchIndex, every SearchRowGetter callback from SearchIndex.getters must return a SearchRow whose keys are found among the names of the SearchIndex.columns, and vice versa.
To know when to trigger a search index migration, the library tracks search index description changes via the SearchIndex.toDefinition method. However, the getters map values are references to SearchRowGetters, and it is not possible to automatically track their implementation changes. If a SearchRowGetter changes its output (and SearchIndex properties remain the same in other respects), then this change must be accompanied by a manual SearchIndex.version increase to trigger migration.
In the following fragment, an FTS index named "kitchens" is defined for
the columns "conditionSummary" and "procurementGuideline"; the content
for the columns is extracted from JSON data in the SearchRowGetter:
var si = SearchIndex(
version: schemeElementInitialVersion,
name: "kitchens",
columns: [
SearchColumn("conditionSummary"),
SearchColumn("procurementGuideline"),
],
getters: {
"Kitchen": (Object data) {
if (data case [
"Kitchen",
{
"condition_summary": String conditionSummary,
"procurement_guideline": String procurementGuideline,
},
])
return {
"conditionSummary": ftsText(conditionSummary),
"procurementGuideline": ftsText(procurementGuideline),
};
throw FormatException("Wrong JSON data: $data");
},
},
);
/* ... */
- Inheritance
-
- Object
- SchemeElement
- SearchIndex
- Annotations
-
- @immutable
Constructors
- SearchIndex({required int version, required String name, required SearchColumns columns, required SearchRowGetters getters, bool removeLatinDiacritics = true, String tokenCategories = ftsTokenCategories, String preprocessor = ftsPreprocessor})
- Creates a description of an FTS index using the given parameters.
Properties
- columns → SearchColumns
-
The list of SearchColumns that form the FTS index.
final
- getters → SearchRowGetters
-
The map associating
Kinds of the FTS index with SearchRowGetters.final - hashCode → int
-
The hash code for this object.
no setterinherited
- lcName → String
-
The lowercase variant of name.
finalinherited
- name → String
-
A string representing the name of the provided description.
finalinherited
- preprocessor → String
-
The version string of preprocessing used for this FTS index.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tokenizer → String
-
An FTS tokenizer configuration for this FTS index.
final
- version → int
-
An integer representing the version of the provided description.
finalinherited
Methods
-
columnsDdlSql(
) → String - Returns a string of the column names for use in DDL statements.
-
columnsSql(
) → String - Returns a comma-separated string of the quoted names of the columns.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parametersSql(
) → String - Returns a string of the named SQL parameters using the column ordinals.
-
searchRowToParameters(
SearchRow row) → Map< String, Object> - Converts a SearchRow to a value binding map of named SQL parameters.
-
toDefinition(
) → Map< String, Object> -
Returns a JSON that changes when SchemeElement properties change.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited