Problem/Motivation

In "Rendered HTML output" fields with "Html filter" when the entity has no data in its fields, the rendered entity is indexed with Html tags.

Steps to reproduce

1. We create two content types, Alpha and Beta:

  • In Beta content type we establish the following configurations:
    • Display settings: we deactivate Display author and date information
    • We activate the view display Search Index, making only the Body field visible, and hiding its label.
  • In Alpha content type we create a "Referenced / Content" type field that refers to the beta content type.

2. We overwrite the template "node.html.twig branch" for the "Search Index" Display View, and remove the code:

{% if label and not page %}
    <h2{{ title_attributes }}>
      <a href="{{ url }}" rel="bookmark">{{ label }}</a>
    </h2>
  {% endif %}

3. We create an Index:

  • In the Fields tab, among other fields, we will add one of type "Rendered HTML output", with the following configuration:
    • We select the Beta content type.
    • We select the view display "Search Index".
    • In the type we will select the option Fulltext "ngramstring".
  • In the Processors tab, we will activate the Html filter for the field "Rendered HTML output".

4. We create contents:

  • Two Beta content type: one with content in the body field and one without content
  • Two Beta Alpha type: a content that refers to one of the Beta content and another to the other

5. Index the content and check the results in Solr. We will see how in these cases, in which the fields are empty, the rendered entity is indexed, instead of not indexing the field.

Proposed resolution

Currently the Abstrac Class FieldsProcessorPluginBase, when processing the field, only checks if the result of the processing is an empty string, and not if it is an empty array. The latter is what the Html filter returns. It is proposed to include this check to fix this problem.

Issue fork search_api-3257550

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lpeidro created an issue. See original summary.

lpeidro’s picture

Issue summary: View changes

lpeidro’s picture

Added Patch.

lpeidro’s picture

Status: Active » Needs review
lpeidro’s picture

Assigned: lpeidro » Unassigned
drunken monkey’s picture

Thanks for reporting this issue and already providing a patch!
I could indeed reprodruce the problem, though your fix only seems to work in some scenarios. The attached is a more comprehensive fix, I think/hope, and also comes with test coverage.
Would be great if you could test/rewiew to see if this still resolves the problem for you, too.

lpeidro’s picture

Ok, I will test it. Thanks.

lpeidro’s picture

Assigned: Unassigned » lpeidro
lpeidro’s picture

Status: Needs review » Reviewed & tested by the community

The patch https://www.drupal.org/project/search_api/issues/3257550#comment-14532268 was tested and work perfectly.

Many thanks.

lpeidro’s picture

Assigned: lpeidro » Unassigned

  • drunken monkey committed d1e190d on 8.x-1.x
    Issue #3257550 by drunken monkey, lpeidro: Fixed wrong handling of empty...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Good to hear, thanks a lot for testing! And sorry for the long delay.
Committed. Thanks again!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.