| 1 |
/* module-specific examples */
|
| 2 |
|
| 3 |
// hook_search
|
| 4 |
function hook_search($op = 'search', $keys = null) {
|
| 5 |
switch ($op) {
|
| 6 |
case 'name':
|
| 7 |
return t('Example');
|
| 8 |
break;
|
| 9 |
|
| 10 |
case 'search':
|
| 11 |
$results = array();
|
| 12 |
$rows = 20;
|
| 13 |
$items = solr_search_solr('example', $keys, $_GET['page'], $rows);
|
| 14 |
|
| 15 |
foreach ($items as $item){
|
| 16 |
$results[] = array(
|
| 17 |
'link' => url('node/'. $item['nid'], NULL, NULL, TRUE),
|
| 18 |
'title' => $item['title'],
|
| 19 |
'snippet' => search_excerpt($keys, $item['body']) // FIXME: use Solr Highlighter
|
| 20 |
);
|
| 21 |
}
|
| 22 |
|
| 23 |
return $results;
|
| 24 |
break;
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
// called by module_invoke_all('solr')
|
| 29 |
function hook_solr($op, $type, $node){
|
| 30 |
// limit to this type of node
|
| 31 |
if ($type != 'example') continue;
|
| 32 |
|
| 33 |
switch ($op){
|
| 34 |
// data to be posted to Solr for a node to be indexed
|
| 35 |
case 'data':
|
| 36 |
return sprintf(
|
| 37 |
'<add><doc><field name="nid">%s</field><field name="title">%s</field><field name="body">%s</field></doc></add>',
|
| 38 |
$node->nid,
|
| 39 |
htmlspecialchars($node->title, ENT_QUOTES),
|
| 40 |
htmlspecialchars($node->body, ENT_QUOTES)
|
| 41 |
);
|
| 42 |
|
| 43 |
// query handler to use for nodes of this type
|
| 44 |
case 'qt':
|
| 45 |
return 'dismax';
|
| 46 |
}
|
| 47 |
}
|
| 48 |
|
| 49 |
// called when nodes are updated
|
| 50 |
function hook_update_index(){
|
| 51 |
solr_update_solr('example');
|
| 52 |
}
|