Updated: Comment #11

Problem/Motivation

Under some circumstances, comment reply links, other comment-related links, and comment forms are rendered into the search index and search results. They shouldn't be.

To reproduce:

1. Grant permission to anonymous users to add and view comments.

2. Add a node with comments enabled.

3. Add a comment to the node.

4. Run cron to index.

5. Search for 'reply' or 'permalink'. Ideally, you should not find your node.

6. Search for something that is in the node. You should not see any reply/edit/delete links in the results or text from the comment form.

Test results

Bug 1: In step 5, you can search for "reply" or "permalink" and find the node. So, these are being added to the search index. (You cannot search for "delete" or "edit". The search index is built based on what an anonymous user would see, and they do not have comment admin.)

Bug 2: In step 6, if you search for something near the end of the node body, you will see "permalink" in the results. If you search for something near the end of the comment body, you will see "reply edit delete" in the results. [As of August 20, 2014 this part is not a problem any more in Drupal 8; still a problem in 7]

This is a problem in Drupal 8 and Drupal 7.

Proposed resolution

Make sure these links and text are not included when the Comment module renders comments for search indexing and search results.

Remaining tasks

Patch, with tests.

User interface changes

API changes

Better searching, without "reply" and "permalink".

Original report by @pwolanin

Seems that comment module does a poor job of implementing hook_node_update_index(). I see that the text "Log in or register to post comments" and "Permalink" are rendered into the text for the node as sent to the search index.

This is really a comment module bug, but it's only relevant to search, so marking it for search.module

Perhpas comment module needs an addition module (not just full/teaser) for comment_view_multiple()?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

This issue seems to be related to both
#903392: "Add new comment" text appears in search result snippet
and
#721374: "Add new comment" is put into the search index along with each node

Both of these are marked closed/fixed. I thought this issue would also have been fixed along with those, but maybe not.

pwolanin’s picture

Trying now with core node search I see the text "delete edit reply" at the end of search results, which seems to be the same problem (comment links are rendered). Probably comment module re-renders the results.

For apachesolr we currently build a snippet using just what's in the search index.

I can see evidence of the same bug since core node search matches all nodes with comments when I search for the the words "register" or "register post", but the words don't appear in the snippet.

The call chain causing the problem seems to be:

comment_node_update_index()
comment_view_multiple()
comment_view()
comment_build_content()
comment_links()

So the bug is multi-fold:

  1. comment_build_content() is not looking for 'search_index' or 'search_result' $view_mode to skip links
  2. comment_node_update_index() is not setting the $view_mode to 'search_index'
  3. comment_node_update_index() doesn't take a $view_mode param.
  4. node_search_execute() calls $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node); without being able to set the $view_mode to 'search_result'.
pwolanin’s picture

Status: Active » Needs review
FileSize
1.1 KB

Here's a minimal patch - it fixes #1 and #2 in the list above. #3/#4 might be considered a feature request and are not essential for resolving the bug.

pwolanin’s picture

for fun, here's a git formatted patch.

jhodgdon’s picture

The patch looks like it should fix the problem. Perhaps a test?

The test should:
a) add a node with comments enabled
b) make sure if you search for 'register' that you don't see the node in the results
c) make sure if you search for something that is in the node, you don't see the reply/edit/delete links in the results (if you have comment admin privs).

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests

I just tested this in a somewhat recent Drupal 8.x and also in 7.23.

a) If you have content without any comments, there is nothing bad happening. You don't see anything about adding comments when you search.

b) If you add a comment to the content (and run cron to index), however, you do see the "reply delete" from the comment links in the search results page. This is true in 7 and 8. So we need to port this patch to 8, add a test for it, and then backport the test and patch to 7.

c) As a note, you cannot search for "reply" or "delete". So this is only a problem in the rendering of search results, and these are not getting into the index.

jhodgdon’s picture

Title: Comment module renders text like "Log in or register to post comments" into the search index » Comment module renders "reply" and other links in search results
Issue summary: View changes
jhodgdon’s picture

I also noticed that if you have the "count page views" turned on in the Statistics module, and you somehow manage to get it to count your page views (that feature of statistics.module is currently broken but you can do a database insert to simulate it), then you get "10 views" at the start of your search result snippet. I'm not sure whether this gets into the search index or not.

I've also noticed that the node title is shown at the end of the search result snippet, which is odd to say the least.

So this all seems related but we could file a separate issue I guess... Really we need a generic way to deal with modules that add stuff to the node view array that would be silly to show in search results snippets.

jhodgdon’s picture

Title: Comment module renders "reply" and other links in search results » Comment module renders "reply" and other links in search index/results

I had a thought this morning and revisited the testing I did in #6. It's worse than I thought...

If anonymous users have permission to add comments, then "Reply" is actually added to the search index, along with "permalink". If anonymous users do not have the ability to add comments, then you don't get "Reply" in the search index, but assuming they have the ability to view comments, "permalink" is added to the index.

This isn't very good.

jhodgdon’s picture

This is most likely going to be fixed for 8.x in
#2141929: Comment link or form is added to print view mode.
hopefully anyway! When that gets in we should retest this issue.

jhodgdon’s picture

Version: 8.x-dev » 7.x-dev
Issue summary: View changes

#2141929: Comment link or form is added to print view mode. went in and I retested, updated the issue summary.

This is no longer a problem in Drupal 8.x, since that fix went in.

Probably it will vanish from 7.x when/if the patch is ported, but I'll leave this issue open in 7.x until then.

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Issue summary: View changes

Whoops. I forgot a crucial step in testing: adding a comment to the node. So, I retested. Still a problem in 8.x. Updated summary.

jhodgdon’s picture

Huh. It looks like this will most likely be fixed in 8.x by:
#1901110: Improve the UX for comment bundle pages and comment field settings
and/or
#1920044: Move comment field settings that relate to rendering to formatter options
which I think should add settings that will allow us to turn off the links when we're in the search index/results view modes.

So I'm postponing this again... I've asked on those issues what the plan is. If they are not planning to put in settings for this, we'll need to put in a kludgy fix instead.

jhodgdon’s picture

Status: Postponed » Needs work

Well, now [#19901110] has been closed as a duplicate of #1920044: Move comment field settings that relate to rendering to formatter options, and the latter issue is not looking like it will get fixed in anything resembling a timely manner.

So I guess we need to kludge this instead. Sigh.

andypost’s picture

andypost’s picture

jhodgdon’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests +Needs backport to D7
FileSize
3.13 KB

I wrote a test for this today. It looks like not all of the bugs in the issue summary are still there in 8.x [updated summary], but this test should ensure that they don't come back (assuming we fix the remaining bugs and commit this test and the patch).

For fixing this, we may have a lesser kludge to do if we wait for #2271349: Node and Comment ops links should be display components (which can be disabled) to land. This adds the ability for comments to have a display mode that would exclude links. However, we'd still have to do something of a kludge, to make it so that if you are rendering a node in one of the search-related display modes, you'd somehow make sure the comments were rendered in a similar display mode. This association is not present in the current patch on that issue.

Status: Needs review » Needs work

The last submitted patch, 17: 1113832-test-FAIL.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Active

Good, the test bot agrees. This test fails in the expected way. Setting back to Active since this patch is not fixing the problem, only presenting a viable test.

jhodgdon’s picture

moshe weitzman’s picture

Status: Active » Fixed

Pretty sure this is fixed. See \Drupal\comment\CommentLinkBuilder::buildCommentedEntityLinks

jhodgdon’s picture

Status: Fixed » Needs review

OK, let's run the test above again and see if it passes.

And then if it does, let's DEFINITELY add this test so it doesn't break again! This has been a long-standing bug.

And then we still need to backport something to D7 if possible...

jhodgdon queued 17: 1113832-test-FAIL.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 17: 1113832-test-FAIL.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Needs review
FileSize
3.04 KB

Test fail due to reroll needed... straight reroll...

Status: Needs review » Needs work

The last submitted patch, 25: 1113832-test-only-25.patch, failed testing.

The last submitted patch, 25: 1113832-test-only-25.patch, failed testing.

jhodgdon’s picture

According to the test results, "reply" and "permalink" are still being added to the index: the test tries searching for these terms, and the search is returning a node result (it shouldn't).

So it appears that this issue was not actually fixed yet.

jhodgdon’s picture

The function cited in #21, \Drupal\comment\CommentLinkBuilder::buildCommentedEntityLinks, is for building the entity-level links (e.g. node-level) -- like "jump to first comment" and "add new comment". It's not about building the links on each comment, like "permalink" and "reply" (the subject of this bug).

So this function is (rightfully) not outputting the node-level links if the node is being rendered in search_index view mode, which is good, but it doesn't fix this bug.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

apaderno’s picture

Version: 8.6.x-dev » 8.9.x-dev

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Title: Comment module renders "reply" and other links in search index/results » [PP-1] Comment module renders "reply" and other links in search index/results
Status: Needs work » Postponed
Issue tags: +Bug Smash Initiative
Related issues: +#2324719: Node indexing - should use view mode for comments, not hook

Postponing this on #1920044: Move comment field settings that relate to rendering to formatter options again, we should fix that, then add test coverage (and possibly default display settings) for the specific bug here. We didn't get the kludge fix done six years later, so concentrating efforts on the longer term fix won't necessarily be slower.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.