Excerpt shows all fields even when only one field has the searchterm

Created on 7 February 2019, over 6 years ago
Updated 7 July 2025, 4 months ago

Hi,
when:

  • I use the excerpt in my view
  • In the index=>processors=>Highlight=>Exclude fields from excerpt: I have not checked Field A and Field B
  • I have checked Field C (so it´s excluded)
  • I search for "searchterm" which is in Field A and not in Field B
  • Field A AND Field B is displayed in the excerpt

Expected behaviour:
Do not display fields in my excerpt that does not match with "searchterm".

Furtheron:

When Field B has multiple values - for example when Field B is the linkname in a referenced entity, and there are 4 entities attached, the excerpt will show all 4 linknames. Only thing needed is
- a match of "searchterm" in one of the referenced linknames
- or a match of searchtearm in Field A

But maybe: Someone wants to display a field in the excerpt as a standard output - even when this field has no match. If this was the intention it´s not working fine also. Because:
When I do not have ANY matches of "searchterm" in one of the unchecked fields:
Those unchecked fields are not displayed.
For example: "searchterm" is in Field C : the excerpt is empty.
If someone wants to have a standard output of a given field, which has no match, he should put this field into his view or use replacement patterns in the rewrite results section of the views excerpt field.

I try to make a figure:

in SOLR, this is how my linkname field is stored (In Our example "Field A"). The linkname field is part of the node attached via entity reference field:
( Entity Reference Field) » Content » Call to action » Link text (title_3)

"tm_X3b_en_X2d_SG_title_3":
          ["CTA1BCDshowertest",
          "Learn more CTA2",
          "Learn more CTA3a",
          "CTA 5a"],

When I search for "showertest", the excerpt displays:
CTA1BCDshowertest … Learn more CTA2 … Learn more CTA3a … CTA 5a … Learn more CTA4a … Learn more CTA4b … CTA 6a … CTA7a … CTA8a …

The italic part is coming from my Field B:
( Entity Reference Field) » Content » (Field in the attached node) » Paragraph » Call to action » Link text (title_5)

"tm_X3b_en_X2d_SG_title_5":
          ["Learn more CTA4a",
          "Learn more CTA4b",
          "CTA 6a",
          "CTA7a",
          "CTA8a"],

And when I have a match in Field C - in my case it´s the summary field: The excerpt is empty.
(Summary (field_summary)):
"tm_X3b_en_X2d_SG_field_summary":["Teaser Showertest ...stripped text..."],

Here´s the spell of this node:

spell":["Teaser Showertest ...stripped text...",
          ...stripped other fields...
          "CTA1BCDshowertest",
          "Learn more CTA2",
          "Learn more CTA3a",
          "CTA 5a",
          "Learn more CTA4a",
          "Learn more CTA4b",
          "CTA 6a",
          "CTA7a",
          "CTA8a"],

How can i make it, that only the values are in the excerpt which have matched "showertest" ?
(the excerpt should display only CTA1BCDshowertest)
Greetings,
Lars

P.S.: I hope i am in the right module and it´s not a search_api or views issue. If it so, forgive me and move to them :-D

🐛 Bug report
Status

Active

Version

1.0

Component

Plugins

Created by

🇩🇪Germany synflag

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • 🇪🇸Spain tuwebo

    I am working on 3031390-excerpt-shows-all-fields fork:
    - Trying to solve handling for the borders between different values/fields
    - Bypassing merging $keys if the backend found $highlighted_keys.
    - PoC: For rendering the excerpt field names as part of the excerpt. It might be useful to know where the excerpt came from.

    Any review/contribution will be very welcome.

  • Pipeline finished with Failed
    4 months ago
    Total: 332s
    #543207
  • Pipeline finished with Failed
    4 months ago
    Total: 453s
    #543277
  • Pipeline finished with Failed
    4 months ago
    Total: 336s
    #543301
  • Pipeline finished with Failed
    4 months ago
    Total: 358s
    #543881
  • Pipeline finished with Failed
    4 months ago
    Total: 357s
    #544296
  • Pipeline finished with Failed
    4 months ago
    Total: 346s
    #544320
  • Pipeline finished with Failed
    3 months ago
    Total: 398s
    #547018
  • Pipeline finished with Failed
    3 months ago
    #547916
  • 🇪🇸Spain tuwebo

    I am adding two related issues for this one work properly.
    - 🐛 Replace deprecated REQUIREMENT_ERROR constant in search_api_db_defaults_requirements() for Drupal 11+ compatibility Active
    will solve the failing test search_api_db_defaults\Functional\IntegrationTest::testInstallAndDefaultSetupWorking in this MR.
    - 🐛 Values overwritten when multiple aggregated fields exist on same data source Needs work
    is needed for taking into account any aggregated_fields in the excerpt.

    I think the only task pending could be a hook_update for updating indexes configuration to include:
    $processors['highlight']['settings']['include_field_labels'] = FALSE;

  • Pipeline finished with Failed
    3 months ago
    #549136
  • Pipeline finished with Failed
    3 months ago
    Total: 348s
    #549972
  • Pipeline finished with Success
    2 months ago
    Total: 428s
    #576605
  • 🇪🇸Spain tuwebo

    I've merged the issue branch with the latest changes from 8.x-1.x (which includes around ~12 commits), so the only test that was failing now passes. All tests are passing and pipelines run with no issues.
    Any review will be very welcome.

    There are some test added and new configuration for the Highlight processor to be able to show the field labels, since it helps the user to spot where the snippets are coming from.
    See attached images: "drupal-search-api-3031390-15-01" and "drupal-search-api-3031390-15-02"

  • 🇦🇹Austria drunken monkey Vienna, Austria

    Amazing work, thank you very much!
    I left some comments in the MR and did some refactoring according to my personal preferences (plus minor code style fixes) but mostly this looks very good already. And thanks to our exhaustive test coverage I think we can be reasonably sure that all of this is working as it should.
    The only things that still need to be addresses are the two unrelated features you added, which will need to be either ironed out or split into separate tickets, whichever you prefer. (See the unresolved threads in the MR.)

    In any case, thanks a lot again!

  • 🇪🇸Spain tuwebo

    Wow thank you so much for the review. I'll go through the MR comments and try to reply there, afterwards create a summary here in a new comment if necessary.
    If for some reason (mostly lacking of time) you don't see me taking some action this week, please feel free to go ahead with whatever better suit the search api module needs.

    Thank you!

  • Pipeline finished with Success
    about 2 months ago
    Total: 345s
    #582277
  • 🇦🇹Austria drunken monkey Vienna, Austria

    I split both of the new features into their own issues, I think this is probably easier to work with and should definitely make more sense when reviewing these changes in the future.
    If you are fine with that, I think we can merge this one.

    In any case, thanks a lot again for all your work on this, sorry I had to complicate things with the new issues.

  • 🇪🇸Spain tuwebo

    Thank you very much for the review, I understand better now, and I totally agree to split the new features. I'll try to look at them in the coming days.

  • 🇦🇹Austria drunken monkey Vienna, Austria

    Great, thanks!
    So, do you agree this is RTBC now, can I merge it?

  • 🇪🇸Spain tuwebo

    Yes, let's do it

  • 🇪🇸Spain tuwebo

    I've just realized that config/schema/search_api.processor.schema.yml does no longer need include_field_labels, since we have a separate issue for it Optionally add field labels to excerpt snippets Active

  • 🇦🇹Austria drunken monkey Vienna, Austria

    Thanks, good catch!
    Fixed that and merged.
    Thanks a lot again, was a pleasure working with you on this!

Production build 0.71.5 2024