suggestions property
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 != null &&
this.results.data.length > 0 &&
this.results.data[0] != null &&
this.results.data[0]['_source'] is Map &&
this.results.data[0]['_source'] != null) {
// Extract fields from _source
fields = this.results.data[0]['_source'].keys;
}
if (this.enablePopularSuggestions == true) {
// extract suggestions from popular suggestion fields too
fields = [...fields, ...popularSuggestionFields];
}
return getSuggestions(
fields, this.results.data, this.value, this.showDistinctSuggestions);
}