Hey all,
So, I’m mainly here to help to answer your questions, or find someone who can, but this time I need some help myself.
Over on liferay.dev I just reworked the Blogs page (which previously used the Blogs Widget with a custom Widget Template) to be a Search Page (with lots of filtering, sorting, searching options to make it so much easier to find blogs you might be interested in!) If you haven’t checked it out yet - please do!
I was able to present pretty much all of the information presented in the Blogs widget - but for one thing - the number of times the blog has been read.
In the Blogs widget, this is presented via a couple of simple lines in the Widget Template:
<#assign assetEntry = blogsEntryAssetEntryUtil.getAssetEntry(request, curBlogEntry) />
<#if blogsPortletInstanceConfiguration.enableViewCount()>
<span><@clay["icon"] symbol="view" /> ${assetEntry.getViewCount()}</span>
</#if>
Which all seems pretty simple, and in theory easy to implement in a Search Results widget template too - after all, this seems to return an AssetEntry object, which also seems to be what’s returned when working with Search Results.
But, in Search Results entry.getViewCount() is null, non-existent, nothing…
I assumed this was because when you’re working with the Search Results widget you’re working with data returned from Elastic, and maybe the view count isn’t in the search index.
But, then I queried that directly using cURL and, it’s there:
“viewCount” : “1485”,
But, entry.viewCount doesn’t yield anything either.
So, I’m at a loss - hence the ask here - does anyone know how (or if) it is possible to get the View Count for an Asset (in this case Blogs) in a Search Results widget template?
Not an answer, but what strikes me is that the viewCount is on AssetEntry, while the configuration is on BlogsEntry. Both exclusively. Also, somehow I wouldn't expect the viewCount to be derived from the search index, just because I wouldn't expect a write operation to the index per read-access to an entry - but then: some write operation needs to be done, either to DB or to ES. Hopefully in batches and not per individual access...
– olafkI can't be certain this applies to your setup, but I just tested locally by adding a blogs entry, adding an asset publisher to the home page, and repeatedly viewing the blog. I would go to the search results (Display in Document Form enabled), and check the viewCount field. It remained at 0 until I manually reindexed (I did Asset Entry and Blogs Entry models individually; YMMV).
– Russell_Bohl