1

I'm using search_file_attachments module for my search, And also Search combine module to show all the results in one page. In the search results page, I like to maintain a structure. I need to show the node title instead of attached file name, and redirect to node url instead of attached file path when a user click on a result. So implement the template_preprocess_search_results() in my module overwrite the results. I tried to figure out the array result using devel.

function template_preprocess_search_result(&$variables) {
  dpm($variables);
}

And this my Devel results:

enter image description here

I cannot see any node details here, I guess this module only searching files in the folders. I'm finding a way to get the node details related to this results. Hope you guys got my question, Thanks in advance,

1

Finally I ended up with some advanced search modules, Which made the search so much better. I used Apache solr and Apache solr attachments modules. This gave me ability to make my search results in a customized way via hooks. I use hook_apachesolr_process_results() to change my results.

First I add a extra field to the file type entities in the solr index, which contain the node title.

/**
 * Implements hook_apachesolr_index_document_build().
 */
function mymodule_apachesolr_index_document_build(ApacheSolrDocument $document, $entity, $entity_type, $env_id) {
    //dsm($entity_type);
    //if the type is file
    if($entity_type == 'file'){
        //add a field node title
        $title = code for getting the node tile of this file
        $document->addField('ts_field_node_title', $title);
    }
}

Now this extra field will be available in your search results. So you can directly use the title instead of file name.

/**
* Implements hook_apachesolr_process_results().
*/
function mymodule_apachesolr_process_results(&$arg) {

    for($i = 0, $l = count($arg); $i < $l; $i++) {
        //if entity type is file change the title
        if($arg[$i]['node']->entity_type != 'node'){
           $arg[$i]['title'] = $arg[$i]['fields']['ts_field_node_title'];
        }
    }

}

Peace! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.