123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- <?php
- function hook_search_info() {
- return array(
- 'title' => 'Content',
- 'path' => 'node',
- 'conditions_callback' => 'callback_search_conditions',
- );
- }
- function hook_search_access() {
- return user_access('access content');
- }
- function hook_search_reset() {
- db_update('search_dataset')
- ->fields(array('reindex' => REQUEST_TIME))
- ->condition('type', 'node')
- ->execute();
- }
- function hook_search_status() {
- $total = db_query('SELECT COUNT(*) FROM {node} WHERE status = 1')->fetchField();
- $remaining = db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.status = 1 AND d.sid IS NULL OR d.reindex <> 0")->fetchField();
- return array('remaining' => $remaining, 'total' => $total);
- }
- function hook_search_admin() {
-
- $form['content_ranking'] = array(
- '#type' => 'fieldset',
- '#title' => t('Content ranking'),
- );
- $form['content_ranking']['#theme'] = 'node_search_admin';
- $form['content_ranking']['info'] = array(
- '#value' => '<em>' . t('The following numbers control which properties the content search should favor when ordering the results. Higher numbers mean more influence, zero means the property is ignored. Changing these numbers does not require the search index to be rebuilt. Changes take effect immediately.') . '</em>'
- );
-
- $options = drupal_map_assoc(range(0, 10));
- foreach (module_invoke_all('ranking') as $var => $values) {
- $form['content_ranking']['factors']['node_rank_' . $var] = array(
- '#title' => $values['title'],
- '#type' => 'select',
- '#options' => $options,
- '#default_value' => variable_get('node_rank_' . $var, 0),
- );
- }
- return $form;
- }
- function hook_search_execute($keys = NULL, $conditions = NULL) {
-
- $query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
- $query->join('node', 'n', 'n.nid = i.sid');
- $query
- ->condition('n.status', 1)
- ->addTag('node_access')
- ->searchExpression($keys, 'node');
-
- $query->setOption('type', 'n.type');
- $query->setOption('language', 'n.language');
- if ($query->setOption('term', 'ti.tid')) {
- $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
- }
-
- if (!$query->executeFirstPass()) {
- return array();
- }
-
- _node_rankings($query);
-
- $find = $query
- ->limit(10)
- ->execute();
- $results = array();
- foreach ($find as $item) {
-
- $node = node_load($item->sid);
- node_build_content($node, 'search_result');
- $node->body = drupal_render($node->content);
-
- $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node);
-
- $node->rendered .= ' ' . module_invoke('taxonomy', 'node_update_index', $node);
- $extra = module_invoke_all('node_search_result', $node);
- $results[] = array(
- 'link' => url('node/' . $item->sid, array('absolute' => TRUE)),
- 'type' => check_plain(node_type_get_name($node)),
- 'title' => $node->title,
- 'user' => theme('username', array('account' => $node)),
- 'date' => $node->changed,
- 'node' => $node,
- 'extra' => $extra,
- 'score' => $item->calculated_score,
- 'snippet' => search_excerpt($keys, $node->body),
- );
- }
- return $results;
- }
- function hook_search_page($results) {
- $output['prefix']['#markup'] = '<ol class="search-results">';
- foreach ($results as $entry) {
- $output[] = array(
- '#theme' => 'search_result',
- '#result' => $entry,
- '#module' => 'my_module_name',
- );
- }
- $output['suffix']['#markup'] = '</ol>' . theme('pager');
- return $output;
- }
- function hook_search_preprocess($text) {
-
- return $text;
- }
- function hook_update_index() {
- $limit = (int)variable_get('search_cron_limit', 100);
- $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);
- foreach ($result as $node) {
- $node = node_load($node->nid);
-
-
- variable_set('node_cron_last', $node->changed);
-
- node_build_content($node, 'search_index');
- $node->rendered = drupal_render($node->content);
- $text = '<h1>' . check_plain($node->title) . '</h1>' . $node->rendered;
-
- $extra = module_invoke_all('node_update_index', $node);
- foreach ($extra as $t) {
- $text .= $t;
- }
-
- search_index($node->nid, 'node', $text);
- }
- }
- function callback_search_conditions($keys) {
- $conditions = array();
- if (!empty($_REQUEST['keys'])) {
- $conditions['keys'] = $_REQUEST['keys'];
- }
- if (!empty($_REQUEST['sample_search_keys'])) {
- $conditions['sample_search_keys'] = $_REQUEST['sample_search_keys'];
- }
- if ($force_keys = config('sample_search.settings')->get('force_keywords')) {
- $conditions['sample_search_force_keywords'] = $force_keys;
- }
- return $conditions;
- }
|