Comments

dishabhadra’s picture

dishabhadra created an issue.

Apache solr not having User role filter. So add new filter User Role based on that Content and User result will be shown.

dishabhadra’s picture

Assigned: Unassigned » dishabhadra

/**
* hook_apachesolr_index_document_build().
* @param ApacheSolrDocument $document
* @param unknown $entity
* @param unknown $entity_type
* @param unknown $env_id
*/
function hook_apachesolr_index_document_build(ApacheSolrDocument $document, $entity, $entity_type, $env_id) {
$uid = $entity->uid;
$user_data = user_load($uid);
$user_role = $user_data->roles;
foreach($user_role as $role) {
$document->setMultiValue('sm_user_role', $role);
}
}

/**
* hook_apachesolr_query_alter().
* @param unknown $query
*/
function hook_apachesolr_query_alter(&$query) {
// Add the parameter.
$query->addParam('fl', 'sm_user_role');
// Add filter of user role.
$query->addFilter('sm_user_role','administrator');
}

dishabhadra’s picture

Status: Active » Fixed
dishabhadra’s picture

Assigned: dishabhadra » Unassigned
dishabhadra’s picture

Status: Fixed » Needs review
hitesh.koli’s picture

Status: Needs review » Reviewed & tested by the community
jgrubb’s picture

Hi dishabhadra,

The goal of this patch is to be able to search everyone who has a certain role? Search "editor" and be able to get results that are all the editors?

jgrubb’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)
dishabhadra’s picture

Hi jgrubb,

Yes the goal of this patch is to get the content and user result of particular role.

Eg. If there are two roles editor and librarian. So we want the content and user data of only editor should be shown in to serach result.

The above patch will be helpful in that case.

jgrubb’s picture

Hi dishabhadra, this seems like too specific a use case for this module, and would fit better in a custom module. Thank you for sharing the code to accomplish this task, though!

<?php

/**
 * hook_apachesolr_index_document_build().
 * @param ApacheSolrDocument $document
 * @param unknown $entity
 * @param unknown $entity_type
 * @param unknown $env_id
 */
function hook_apachesolr_index_document_build(ApacheSolrDocument $document, $entity, $entity_type, $env_id)
{
    $uid = $entity->uid;
    $user_data = user_load($uid);
    $user_role = $user_data->roles;
    foreach ($user_role as $rid => $role) {
        $document->setMultiValue('sm_user_role', $role);
    }
}

/**
 * hook_apachesolr_query_alter().
 * @param unknown $query
 */
function hook_apachesolr_query_alter(&$query)
{
// Add the parameter.
    $query->addParam('fl', 'sm_user_role');
// Add filter of user role.
    $query->addFilter('sm_user_role', 'administrator');
}
jgrubb’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)