First off - thanks for bringing this functionality to Drupal 7 - much appreciated.

I have the module installed on a site I'm developing right now, but there is a small issue with it that I was able to fix with a tiny code change, and I'm hoping you'll consider it for inclusion in the module.

Currently, when this module hides part of a node from a non-privileged user, it also hides it from the search index. This means that the search system is only indexing what is displayed to non-privileged users.

I think it would be helpful if the search index was able to access as much as the node as is specified by the current view mode. If there is a custom "search index" view mode, then it would use that, otherwise it would use the default.

I was able to make this happen by changing one line of code in nopremium.module:

Before:

/**
 * Implementation of hook_node_view_alter().
 */
function nopremium_node_view_alter(&$build) {
  $node = $build['#node'];

  if (($build['#view_mode'] != 'teaser') && $node->premium && !nopremium_access_full_content($node)) {
    nopremium_alter_node($build);
  }
}

After:

/**
 * Implementation of hook_node_view_alter().
 */
function nopremium_node_view_alter(&$build) {
  $node = $build['#node'];

  if (($build['#view_mode'] != 'teaser' && $build['#view_mode'] != 'search_index') && $node->premium && !nopremium_access_full_content($node)) {
    nopremium_alter_node($build);
  }
}

Please considering accepting this patch. At the very least, I think this should be included as an option.

Thanks,
-mike

CommentFileSizeAuthor
#2 searchindex-1274378-2.patch544 bytesultimike

Comments

anrikun’s picture

Thanks!
If you have some time, could you please turn this into a real patch?

Also, a question:
After applying the patch and indexing, what happens when a non-privileged user try to search some keywords that are in the premium (hidden to non-privileged users) part? Do results from the premium part show up?
Can you please test this and tell me?

ultimike’s picture

StatusFileSize
new544 bytes

A proper patch is attached.

With the patch applied, premium content is not displayed in the search results - it is only available for searching via the search index.

Thanks,
-mike

anrikun’s picture

Status: Active » Needs review

Thanks!

anrikun’s picture

Status: Needs review » Fixed

Committed to 7.x-1.x. Thanks!

Status: Fixed » Closed (fixed)

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