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 that Kind;
  • 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.

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: 1,
  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
Annotations
  • @immutable

Constructors

SearchIndex({required int version, required String name, required SearchColumns columns, required SearchRowGetters getters})
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
name String
A string representing the name of the provided description.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
updater SearchIndexUpdater
The SearchIndexUpdater maintained by the Scheme for this FTS index.
latefinal
version int
An integer representing the version of the provided description.
finalinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited