Problem/Motivation

This issue looks like it is related to issue #1202416: Search is not working with node access turned on

The indexing engine will not index comments (and therefore also replies in the forum) if some contect access module is enabled.

Case:

  1. set up content access and search
  2. disable access to a node for anonymous users
  3. create a node
  4. add comments
  5. index through cron or force it through the admin interface
  6. search for some text in the node: the node will be found
  7. search for some text in the comment: the node will NOT be found

Proposed resolution

Personnally I have circumvented this by some modifications in the comment.module file:

  1. create a specialized comment_get_thread_without_NA() function, copied from comment_get_thread() but without the addTag statements.
  2. call this function from comment_node_update_index

But I'm no Drupal pro. There must be better ways.

Remaining tasks

transform this into a patch (I'm incapable of doing that)

User interface changes

Comments will be found again.

API changes

none that I see.

Comments

David4514’s picture

I am having the same problem. However, I am on Drupal 7.12 and I think the issue you identify #1202416: Search is not working with node access turned on has been closed with a patch pushed back in August. If that is the case, this is a different problem.

David4514’s picture

Version: 7.8 » 7.12

I think the issue is different. In issue #1202416, search was not returning results consistently. In our case, comments are not being indexed at all so there is no possibility of search retrieving any results from comments.

I had opened an issue #1457364: Enabling Content Access disables Comments being indexed for Search for Content Access. But now I am not sure that this is not a core issue instead.

David4514’s picture

I do not like hacking core, but I have not found any other solutions. Below is a patch that was applied to Drupal 7.12 on my test site to implement what @jbateau suggested.

I would not have a clue on how to build a test for this. From my testing, the search request still honors permissions in displaying search results. This patch just allows all comments to be indexed independent of node_access.

Richard_1618’s picture

Thank you very much - worked for me!!

ropaolle’s picture

I tested your patch too and on a clean site it works. But not with my production db. There must be something more to it. I'll keep on searching :).

EDIT: After rebuilding the node permissions it seems to work at lest sometimes. I think there is something related to the comment permissions also.

ropaolle’s picture

To make this work I had to do two things.

  1. Make sure that all roles that have search permission also have the view comment permission. If not no comments are indexed at all. A comment in the function comment_node_update_index says "Prevent indexing of comments if there are any roles that can search but not view comments.".
  2. Apply the patch in #3. Thank you.
natemow’s picture

Status: Active » Reviewed & tested by the community

Confirmed that the patch in #3 works, if permissions for search and comments match per #6; have included in the build for our new distro project as well.

David_Rothstein’s picture

Version: 7.12 » 8.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs backport to D7

This would need to go into Drupal 8 first and is a tricky subject (see for example #680992: comments are added to search index without checking access for a related issue). Would have to be very careful but in theory I guess it could be backported?

We shouldn't add a whole new duplicate function though.... This would need to reuse existing code as much as possible, and then also make certain that the comments aren't displayed to users who should not have access to them.

David_Rothstein’s picture

Issue summary: View changes

corrected form

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.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

catch’s picture

Issue summary: View changes
Issue tags: +Needs tests, +Bug Smash Initiative

This looks like it's probably still valid. Would be useful to have some test coverage - that comments are indexed regardless of node access, but that search only shows results based on node access.

https://api.drupal.org/api/drupal/core%21modules%21comment%21comment.mod...

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.