apachesolr_search.inc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * Path generation for Apache Solr Search.
  5. *
  6. * Available vars:
  7. * $keywords: user input
  8. * $types: content types (machine names[])
  9. * $terms: taxonomy terms (tids[])
  10. * $keys: complete search phrase, as core would have done it
  11. *
  12. * To return:
  13. * the complete search path
  14. */
  15. function _custom_search_apachesolr_search($variables, &$keys, $fields) {
  16. // Use the search info for the apachesolr module to get the search path.
  17. $solr_info = apachesolr_search_search_info();
  18. $type = 'search/' . $solr_info['path'] . '/' . $variables['keywords'];
  19. $keys = array();
  20. if (count($variables['types']) && !in_array('all', $variables['types'])) {
  21. foreach ($variables['types'] as $t) {
  22. $keys['fq[' . count($keys) . ']'] = 'bundle:' . $t;
  23. }
  24. }
  25. if (module_exists('taxonomy') && count($variables['terms'])) {
  26. // Get all fields info to get correct filter names.
  27. $taxonomy_fields = array();
  28. foreach ($fields as $name => $settings) {
  29. if ($settings['type'] == 'taxonomy_term_reference') {
  30. $voc = taxonomy_vocabulary_machine_name_load($settings['settings']['allowed_values'][0]['vocabulary']);
  31. $taxonomy_fields[$voc->vid] = $name;
  32. }
  33. }
  34. // Build keys for taxonomy.
  35. foreach ($variables['terms'] as $t) {
  36. $vocid = taxonomy_term_load($t)->vid;
  37. $keys['fq[' . count($keys) . ']'] = 'im_' . $taxonomy_fields[$vocid] . ':' . $t;
  38. }
  39. }
  40. foreach (module_implements('custom_search_apachesolr_processing') as $module) {
  41. $function = $module . '_custom_search_apachesolr_processing';
  42. if (function_exists($function)) {
  43. call_user_func_array($function, array(&$keys, $fields, $variables['other']));
  44. }
  45. }
  46. return array('path' => $type, 'query' => $keys);
  47. }