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.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3257550-7--fix_empty_text_after_html_filter.patch | 4.46 KB | drunken monkey |
| #7 | 3257550-7--fix_empty_text_after_html_filter--tests_only.patch | 2.89 KB | drunken monkey |
Issue fork search_api-3257550
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
Comment #2
lpeidro commentedComment #4
lpeidro commentedAdded Patch.
Comment #5
lpeidro commentedComment #6
lpeidro commentedComment #7
drunken monkeyThanks 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.
Comment #8
lpeidro commentedOk, I will test it. Thanks.
Comment #9
lpeidro commentedComment #10
lpeidro commentedThe patch https://www.drupal.org/project/search_api/issues/3257550#comment-14532268 was tested and work perfectly.
Many thanks.
Comment #11
lpeidro commentedComment #14
drunken monkeyGood to hear, thanks a lot for testing! And sorry for the long delay.
Committed. Thanks again!