Posted by pmarreddy on June 15, 2009 at 3:09pm
Jump to:
| Project: | Apache Solr Search Integration |
| Version: | 6.x-1.0-alpha6 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
can somebody help me how to customize result snippet of a apache solr result. i need to display no of votes for that specific node in the result snippet
i need to understand 1. how to index votes field 2. how to show the value in result snippet
Comments
#1
i was only able to access comment_count] => [created] => [id] => [name] => [nid] => [title] => [type] => [uid] => [url] => [score] => [body]
these variables, how can i access other variable like status, vote,.... from the index ( i don't want to access the database)
#2
Look at the README.txt
In the "Developers" section @pwolanin has outlined all the hooks available and what they do. If you are still confused, please re-post your question with specific questions about the code.
Jacob
#3
thank you for the reply, now i understood i need to handle hook_apachesolr_cck_fields_alter(&$mappings) and add the field to the index.
i just want to know what are the default fields that are indexed i mean status, promote and sticky fields of a node should be indexed by default right? or do we have to map them too.
i just want to know which fields are indexed by default and which one's we have to?
#4
Most or all of the standard node fields are indexed, including promote and sticky. There are already bias settings available for those fields.
Note, however, that not all fields are returned in the search results - only those being asked for in the fl param.
#5
pmarreddy - I am curious; how does one access 'nid' etc. in the '_fields:protected' array of the 'Apache_Solr_Document' object?
Thanks.
#6
thanks pwolanin for the reply, what you said is right i need to add more fields to the fl param for access.
in apachesolr_search.module
$results[] = array(
'link' => url($doc->path),
'type' => apachesolr_search_get_type($doc->type),
'title' => $doc->title,
'user' => theme('username', $doc),
'date' => $doc->created,
'node' => $doc,
'extra' => $extra,
'score' => $doc->score,
'snippet' => $snippet,
);
i am trying to print the $node object but i can access snippet, info and title in search-result.tpl.php , can u point me how to get access to the $node(doc object) in the template file.
<?phpprint $snippet;
?>
/////this works
<?phpprint_r($node);
?>
///// this doesn't work
hi rrlange, i am a newbe to drupal and i have no idea how i am just trying to figure it out. i think if i can get access to the $node object in the template file i can print nid or what ever i want. can i?
#7
see: http://api.drupal.org/api/function/template_preprocess_search_result/6
try:
print_r($result['node']);or just:
print_r($result);Or write your own preprocess function.
#8
Perhaps this might help:
I added this function to my theme function in order to show node teasers instead of what's returned by Solr:
function mytheme_preprocess_search_result(&$variables) {if ($variables['result']['node']->nid) {
$node = node_load($variables['result']['node']->nid);
$variables['snippet'] = node_view($node, TRUE, TRUE, FALSE); // node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE)
}
}
This modifies the snippet variable which is shown below the node title in the search results screen.
#9
thanks pwolanin it worked, that is all i need to know.
#10
thanks janusman, but my requirment is to get the data from the index itself not form the database.
as specified by pwolanin you can use the result object to get the node id or any variable from the index with out ever touching the database
<?phpprint $result['node']->nid;
?>
thanks for the alternative solution of getting the required data from database.
#11
This was so useful to me, thank you