getSearchSuggestions method

Future getSearchSuggestions(
  1. String query, {
  2. bool detailedRuns = false,
})

Get search suggestions.

  • query Query string, i.e. 'faded'.
  • detailedRuns Whether to return detailed runs of each suggestion. If true, it returns the query that the user typed and the remaining suggestion along with the complete text (like many search services usually bold the text typed by the user). Default: false, returns the list of search suggestions in plain text.

Returns a list of search suggestions. If detailedRuns is false, it returns plain text suggestions. If detailedRuns is true, it returns a list of Maps with detailed information.

Example response when query is 'fade' and detailedRuns is set to false:

[
  "faded",
  "faded alan walker lyrics",
  "faded alan walker",
  "faded remix",
  "faded song",
  "faded lyrics",
  "faded instrumental"
]

Example response when detailedRuns is set to true:

[
  {
    "text": "faded",
    "runs": [
      {
        "text": "fade",
        "bold": true
      },
      {
        "text": "d"
      }
    ],
    "fromHistory": true,
    "feedbackToken": "AEEJK..."
  },
  {
    "text": "faded alan walker lyrics",
    "runs": [
      {
        "text": "fade",
        "bold": true
      },
      {
        "text": "d alan walker lyrics"
      }
    ],
    "fromHistory": false,
    "feedbackToken": null
  },
  {
    "text": "faded alan walker",
    "runs": [
      {
        "text": "fade",
        "bold": true
      },
      {
        "text": "d alan walker"
      }
    ],
    "fromHistory": false,
    "feedbackToken": null
  },
  ...
]

Implementation

Future<dynamic> getSearchSuggestions(
  String query, {
  bool detailedRuns = false,
}) async {
  final body = <String, dynamic>{'input': query};
  const endpoint = 'music/get_search_suggestions';
  final response = await sendRequest(endpoint, body);
  return parseSearchSuggestions(response, detailedRuns);
}