suggestions property Null safety
can be used to get the parsed suggestions from the results
.
If enablePopularSuggestions
property is set to true
then the popular suggestions will get appended at the bottom with a property in source
object named _popular_suggestion
as true
.
Implementation
List<Suggestion> get suggestions {
if (this.type != null && this.type != QueryType.search) {
return [];
}
List<String> fields = getNormalizedField(this.dataField);
if (fields.length == 0 && this.results!.data.length > 0) {
// Extract fields from _source
fields = this.results!.data[0].keys.toList();
}
if (this.enablePopularSuggestions == true) {
// extract suggestions from popular suggestion fields too
fields = [...fields, ...popularSuggestionFields];
}
return getSuggestions(
fields, this.results!.data, this.value, this.showDistinctSuggestions);
}