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:
- set up content access and search
- disable access to a node for anonymous users
- create a node
- add comments
- index through cron or force it through the admin interface
- search for some text in the node: the node will be found
- 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:
- create a specialized comment_get_thread_without_NA() function, copied from comment_get_thread() but without the addTag statements.
- 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
Comment #1
David4514 commentedI 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.
Comment #2
David4514 commentedI 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.
Comment #3
David4514 commentedI 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.
Comment #4
Richard_1618 commentedThank you very much - worked for me!!
Comment #5
ropaolle commentedI 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.
Comment #6
ropaolle commentedTo make this work I had to do two things.
Comment #7
natemow commentedConfirmed 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.
Comment #8
David_Rothstein commentedThis 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.
Comment #8.0
David_Rothstein commentedcorrected form
Comment #17
catchThis 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...