field method

dynamic field(
  1. String fieldName, [
  2. FieldMapping? attributes
])

Adds a field to the list of document fields that will be indexed. Every document being indexed should have this field. Null values for this field in indexed documents will not cause errors but will limit the chance of that document being retrieved by searches.

All fields should be added before adding documents to the index. Adding fields after a document has been indexed will have no effect on already indexed documents.

Fields can be boosted at build time. This allows terms within that field to have more importance when ranking search results. Use a field boost to specify that matches within one field are more important than other fields.

fieldName - The name of a field to index in all documents. attributes - Optional attributes associated with this field. Throws Exception if fieldName cannot contain unsupported characters '/'

Implementation

field(String fieldName, [FieldMapping? attributes]) {
  if (RegExp('/').hasMatch(fieldName)) {
    throw Exception("Field '$fieldName' contains illegal character '/'");
  }

  _fields[fieldName] = attributes ?? {};
}