1

Currently when I search for something it displays the title of the node and if there is a match a small excerpt from either the content short summary or a small excerpt from the paragraph bundle. If there is no match it displays nothing.

How can i change this so it displays content even if only the title match. How can i change this so it displays the date it was published as well.

The modules involved are paragraphs, solr, searchAPI, Display Suite.

5

You can simply add a new view mode for search results:

  1. Go to admin/structure/types/manage/page/display (where "page" is your content type)
  2. Expand the Show Custom display settings fieldset
  3. Check Search index

Search index view mode

  1. Click Save
  2. Go to admin/structure/types/manage/page/display/search_index (where "page" is your content type)

My advice would be to use the Display Suite module as well for extra fields and more options.

  • Can you elaborate on Display Suite? I have that enabled but i'm not sure how to make it work. – blu Jan 10 '17 at 20:00
  • I just updated my answer with more details. – Wim Mostrey Jan 10 '17 at 20:00
  • I followed the steps above and nothing seems to have changed from my search results page. – blu Jan 10 '17 at 20:22
  • It would appear that you need the Apachesolr View Modes module as well: "Enables view modes to be used to control the display of search results". – Wim Mostrey Jan 10 '17 at 20:33
  • Display suite is a good solution. I had some difficulties at the beginning to configure it : layout must be selected to enable Display Suite functionality such as get search snippet field etc. – Sébastien Gicquel Mar 22 '18 at 14:14
1

I am assuming you're using Drupal 8. You'll want to modify the search-result.html.twig template. By default, I believe the code looks something like this:

{{ title_suffix }}
<p{{ content_attributes }}>{{ snippet }}</p>

You can modify it to display something like the node's body field summary:

{{ title_suffix }}
{% if result.node.body.0.summary %}
  <p{{ content_attributes }}>{{ summary|length > 200 ? summary|slice(0, 250) ~ '...' : summary }}</p>
  <div>{{ result.node.created }}</div>
{% else %}
  <p{{ content_attributes }}>{{ snippet }}</p>
  <div>{{ result.node.created }}</div>
{% endif %}

EDIT: formatting

-1

I have a question: How to highlight the keywords in search results and show excerpts according to the keywords?

I have implemented the above comments. Any solutions?

  • Welcome to StackExchange. Bit of etiquette advice: Please do not use answers to ask questions. You could use comments on the answer for this. But for a 2 year old question, it would be better to ask a new question and refer to the original. – CG Monroe Jul 10 at 13:54
  • ok. Actually I dont have 50 reputations due to that I was unable to comment on that. Will take care. – Eshban Jul 10 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.