How to define indexed fields in new Search API in Data Center

The new Search API requires us to add instances of com.atlassian.jira.search to a collector. I’d love some help doing that.

The Field interface defines a Builder like this:

public interface Builder<T extends Field> {
Builder<T> indexed();
Builder<T> docValues();
Builder<T> stored();
Builder<T> multiValued();
Builder<T> subfield(Field var1);
default Builder<T> subfield(Builder<?> fieldBuilder) {
return this.subfield(fieldBuilder.build());
}
T build();
}

The various sub-types of Field define their own Builder variants.

But the documentation of those builders is… let’s say… sparse.

I’d particularly like to know about the AnalyzedTextField.Builder

Here’s how I used to add document fields in the old Lucene-based world:

if (searchable) {
// A field that is indexed but not tokenized: the entire
// String value is indexed as a single token.
doc.add(new StringField(getDocumentFieldId(), stringValue, Field.Store.YES));
// Since our searcher implements CustomFieldStattable
doc.add(new SortedDocValuesField(getDocumentFieldId(),
new BytesRef(stringValue)));
} else {
doc.add(new StoredField(getDocumentFieldId(), stringValue));
}

What’s the equivalent code that should go inside the indexFieldsWithVisibility method in the new Search API?

By the way, the examples on the FieldIndexer migration details page show us how to define an indexer under Lucene, not the new Search API. WTF?