Index: README.txt =================================================================== RCS file: README.txt diff -N README.txt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ README.txt 18 Jul 2009 21:22:46 -0000 @@ -0,0 +1,47 @@ + +API +========================== +hook_exhibit_apachesolr_item($result) + * add custom $item rows + +hook_exhibit_apachesolr_field() + * add custom $fields + +For Example +/** + * Implementation of hook_exhibit_apachesolr_item(). + */ +function mymodule_exhibit_apachesolr_item($result) { + // group_id that the node is a member of + if (module_exists('og') && module_exists('apachesolr_og')) { + $item['group_id'] = $result['node']->im_og_gid[0]; //AF check this guessing + $sql = "SELECT * FROM {og} WHERE nid = %d"; + $obj = db_fetch_object(db_query($sql, $item['group_id'])); + } + + // Number of comments + if (module_exists('comment')) { + $item['comment_count'] = $result['node']->comment_count; + } + + // Add firstname and last name + $sql = "SELECT fn.field_first_name_value, ln.field_last_name_value + FROM {node} n + LEFT JOIN {content_field_last_name} ln ON n.vid = ln.vid + LEFT JOIN {content_field_first_name} fn ON n.vid = fn.vid + WHERE n.type LIKE 'profile' AND n.uid = %d"; + $obj = db_fetch_object(db_query($sql, $result['node']->uid)); + + $item['firstname'] = $obj->field_first_name_value; + $item['lastname'] = $obj->field_last_name_value; + return $item; +} + +/** + * Implementation of hook_exhibit_apachesolr_field(). + */ +function mymodule_exhibit_apachesolr_field() { + $fields['firstname'] = array('valueType' => 'item'), + $fields['lastname'] = array('valueType' => 'item'), + return $fields; +} Index: exhibit_apachesolr.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/exhibit/contrib/exhibit_apachesolr/exhibit_apachesolr.module,v retrieving revision 1.1 diff -u -p -r1.1 exhibit_apachesolr.module --- exhibit_apachesolr.module 28 Jan 2009 22:32:54 -0000 1.1 +++ exhibit_apachesolr.module 18 Jul 2009 21:22:46 -0000 @@ -16,5 +16,13 @@ function exhibit_apachesolr_menu() { 'access arguments' => array('access exhibits'), 'file' => 'exhibit_apachesolr.pages.inc', ), + 'admin/settings/exhibit_apachesolr' => array( + 'title' => 'Exhibit Apachesolr', + 'description' => 'Configure Exhibit Apachesolr.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('exhibit_apachesolr_admin'), + 'file' => 'exhibit_apachesolr.pages.inc', + 'access arguments' => array('administer exhibit feeds'), + ), ); } Index: exhibit_apachesolr.pages.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/exhibit/contrib/exhibit_apachesolr/exhibit_apachesolr.pages.inc,v retrieving revision 1.1 diff -u -p -r1.1 exhibit_apachesolr.pages.inc --- exhibit_apachesolr.pages.inc 28 Jan 2009 22:32:54 -0000 1.1 +++ exhibit_apachesolr.pages.inc 18 Jul 2009 21:22:46 -0000 @@ -1,5 +1,5 @@ array('label' => t('Result'), 'pluralLabel' => t('Results'))); $fields = array( 'score' => array('valueType' => 'number'), - 'author' => array('valueType' => 'item'), 'created' => array('valueType' => 'date'), 'type' => array('valueType' => 'item'), 'url' => array('valueType' => 'url'), ); - $results = apachesolr_search_search('search', $keys); + + $extra_field = module_invoke_all('exhibit_apachesolr_field'); + $fields = array_merge($fields, $extra_field); + + try { + $results = apachesolr_search_execute($keys, '', '', '', 0, 'exhibit_apachesolr_search'); + } + catch (Exception $e) { + watchdog('Exhibit Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR); + apachesolr_failure(t('Solr search'), is_null($query) ? $keys : $query->get_query_basic()); + } + foreach ($results as $result) { - $items[] = exhibit_compact_item(array( + $item = array( 'type' => 'search', 'id' => $result['link'], 'label' => $result['title'], - 'author' => $result['user'], + 'uid' => $result['node']->uid, 'created' => gmstrftime(EXHIBIT_DATE_FORMAT, $result['date']), 'score' => $result['score'], 'snippet' => $result['snippet'], 'node_type' => $result['type'], 'url' => $result['link'], - )); + 'nid' => $result['node']->nid, + 'changed' => gmstrftime(EXHIBIT_DATE_FORMAT, $result['node']->changed), + ); + + // Call hook_exhibit_apachesolr_item(). + $extra_item = module_invoke_all('exhibit_apachesolr_item', $result); + $item = array_merge($item, $extra_item); + $items[] = exhibit_compact_item($item); } $filename = drupal_get_path('module', 'exhibit') .'/exhibit.pages.inc'; require_once $filename; exhibit_output('application/json', drupal_to_js(exhibit_json($items, $types, $fields))); -} \ No newline at end of file +} + +function exhibit_apachesolr_admin() { + $form = array(); + $form['exhibit_apachesolr_rows'] = array( + '#type' => 'textfield', + '#title' => t('Number of Results'), + '#default_value' => variable_get('exhibit_apachesolr_rows', 100), + '#description' => t('Maximum number of results for Exhibit Apachesolr Feed.'), + ); + return system_settings_form($form); +} + +/** + * Implementation of hook_apachesolr_modify_query() from apachesolr module. + */ +function exhibit_apachesolr_apachesolr_modify_query(&$query, &$params, $caller) { + if ($caller == 'exhibit_apachesolr_search') { + $params['rows'] = variable_get('exhibit_apachesolr_rows', 100); + } +}