apachesolr_search.inc 1.6 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. */
  16. function _custom_search_apachesolr_search($variables) {
  17. // Set default path in case the core search page path isn't set yet.
  18. $path = 'search/apachesolr_search';
  19. $solr_info = apachesolr_search_page_load('core_search');
  20. if (isset($solr_info['search_path'])) {
  21. // Use the configured Solr search path instead of default path.
  22. $path = $solr_info['search_path'];
  23. }
  24. $type = $path . '/' . $variables['keywords'];
  25. $keys = array();
  26. if (count($variables['types']) && !in_array('all', $variables['types'])) {
  27. foreach ($variables['types'] as $t) {
  28. $keys['f[' . count($keys) . ']'] = 'bundle:' . $t;
  29. }
  30. }
  31. if (module_exists('taxonomy') && count($variables['terms'])) {
  32. // get all fields info to get correct filter names
  33. $fields = field_info_fields();
  34. $taxonomy_fields = array();
  35. foreach ($fields as $name => $settings) {
  36. if ($settings['type'] == 'taxonomy_term_reference') {
  37. $voc = taxonomy_vocabulary_machine_name_load($settings['settings']['allowed_values'][0]['vocabulary']);
  38. $taxonomy_fields[$voc->vid] = $name;
  39. }
  40. }
  41. // build keys for taxonomy
  42. foreach ($variables['terms'] as $t) {
  43. $vocid = taxonomy_term_load($t)->vid;
  44. $keys['f[' . count($keys) . ']'] = 'im_' . $taxonomy_fields[$vocid] . ':' . $t;
  45. }
  46. }
  47. return array('path' => $type, 'query' => $keys);
  48. }