SiteSearch plugin - How to show another information

Hello, I have successfully installed the SiteSearch plugin and it is working as it should. However, I was unable to display the ‘publish_up’ field in the results in ‘meta’. I think the documentation is not very clear about this.

In Plugin.php:
return [
‘title’ => $item->article_title,
‘text’ => $item->content,
‘url’ => $controller->pageUrl(‘/’).‘materias/’.$item->slug, //‘materias’, [‘slug’ => $item->slug]
//‘thumb’ => optional($item->images)->first(), // Instance of System\Models\File
‘relevance’ => $relevance, // higher relevance results in a higher
// position in the results listing
‘meta’ => [
‘publish_up’ => $item->publish_up
],
// ‘meta’ => ‘data’, // optional, any other information you want
// to associate with this result
// ‘model’ => $item, // optional, pass along the original model
];

Hi,

You should create your own search result partials.

Your code is fine, so in the results partial just:

[searchResults]
resultsPerPage = 10
showProviderBadge = 1
noResultsMessage = "Your search did not return any results."
visitPageMessage = "Visit page"
==
{% set results = searchResults.results %}
{% for result in results %}
  {# Display all results #}      
  {% partial 'search/searchresult' result = result %}
{% else %}
  {# No results found #}
  {% partial 'search/no-results' %}
{% endfor %}

In the search/searchresult partial just add the:
{{ result.meta.publish_up }}

And it should be there.
Try it

1 Like

Thanks !!! It´s work !!!

1 Like