Skip to content

Adding more fields to the autosuggest results #2128

Closed
@fagiani

Description

I was looking at the JS code that builds the autosuggest list and found that only the post_title is set to text field of the formatted hits as seen below:

/**
* Helper function to format search results for consumption
* by the updateAutosuggestBox function
*
* @param {object} hits - results from ES
* @returns {Array} formatted hits
*/
const formatSearchResults = (hits) => {
return hits.map((hit) => {
const text = hit._source.post_title;
const url = hit._source.permalink;
return { text, url };
});
};

Is there any way to override this method somehow to add other fields like the post date?

Also, is it something that you'd be considering abstracting for a future version? I'd be interested in contributing with a PR if I had some general guidance.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions