Add likes and views to search display

AI-generated summary

The discussion revolves around adding likes and views to the search display in Discourse. pfaffman requests the ability to show the number of likes and views for topics in search results, noting that this data is available in the JSON response but unclear how to display it. codinghorror asks for a mockup, which pfaffman provides, suggesting the metrics appear to the right of the topic title, similar to how likes are shown when sorting by likes. Falco explains that the data is part of the posts model and can be accessed via theme outlets, referencing a guide on adding plugin outlets in themes. pfaffman appreciates the guidance and defers implementation to the client.

I’d like to add to the search page the number of likes and views a topic has received.

The json in https://site.com/search.json?q=whatever has the number of likes in the posts and for topics includes likes and views. I think it should be “easy” to pull that data out of the json payload and display it, but it’s still not easy for me.

Can you please mock up what this would look like?

No. I’m really bad at that. Here is instead some hand waving.

The the right of the title (“Discourse backup vs DO backup”, below) there would also be the number of likes and/or views the topic has gotten.

The hand waving is the easy part unfortunately.

What I was asking for more generally, is how to pull a field out of the json load and display it. Do I need javascript to access the number of likes that’s in the json load for the page?

I believe the data is inside the posts model and there is a outlet for each result, so maybe you can get around it using this:

By the way, the likes are displayed when you order by likes.

Aha! That’s helpful, though for some reason the likes are not showing on that site when I sort by likes. They do here, though. I don’t see any CSS changes there.

It’d look like this:

And the number of views might be to the right of the :heart: like views: 123.

Edit: but you’d not have to sort by likes to make it show up.

Thanks, @falco. That’s what I was looking for. I’ll leave it to my client to implement it if he wants. :slight_smile: