README.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. Search facets
  2. -------------
  3. This module allows you to create facetted searches for any search executed via
  4. the Search API, no matter if executed by a search page, a view or any other
  5. module. The only thing you'll need is a search service class that supports the
  6. "search_api_facets" feature. Currently, the "Database search" and "Solr search"
  7. modules supports this.
  8. This module is built on the Facet API [1], which is needed for this module to
  9. work.
  10. [1] http://drupal.org/project/facetapi
  11. Information for site builders
  12. -----------------------------
  13. For creating a facetted search, you first need a search. Create or find some
  14. page displaying Search API search results, either via a search page, a view or
  15. by any other means. Now go to the configuration page for the index on which
  16. this search is executed.
  17. If the index lies on a server supporting facets (and if this module is enabled),
  18. you'll notice a "Facets" tab. Click it and it will take you to the index' facet
  19. configuration page. You'll see a table containing all indexed fields and options
  20. for enabling and configuring facets for them.
  21. For a detailed explanation of the available options, please refer to the Facet
  22. API documentation.
  23. - Creating facets via the URL
  24. Facets can be added to a search (for which facets are activated) by passing
  25. appropriate GET parameters in the URL. Assuming you have an indexed field with
  26. the machine name "field_price", you can filter on it in the following ways:
  27. - Filter for a specific value. For finding only results that have a price of
  28. exactly 100, pass the following $options to url() or l():
  29. $options['query']['f'][] = 'field_price:100';
  30. Or manually append the following GET parameter to a URL:
  31. ?f[0]=field_price:100
  32. - Search for values in a specified range. The following example will only return
  33. items that have a price greater than or equal to 100 and lower than 500.
  34. Code: $options['query']['f'][] = 'field_price:[100 TO 500]';
  35. URL: ?f[0]=field_price%3A%5B100%20TO%20500%5D
  36. - Search for values above a value. The next example will find results which have
  37. a price greater than or equal to 100. The asterisk (*) stands for "unlimited",
  38. meaning that there is no upper limit. Filtering for values lower than a
  39. certain value works equivalently.
  40. Code: $options['query']['f'][] = 'field_price:[100 TO *]';
  41. URL: ?f[0]=field_price%3A%5B100%20TO%20%2A%5D
  42. - Search for missing values. This example will filter out all items which have
  43. any value at all in the price field, and will therefore only list items on
  44. which this field was omitted. (This naturally only makes sense for fields
  45. that aren't required.)
  46. Code: $options['query']['f'][] = 'field_price:!';
  47. URL: ?f[0]=field_price%3A%21
  48. - Search for present values. The following example will only return items which
  49. have the price field set (regardless of the actual value). You can see that it
  50. is actually just a range filter with unlimited lower and upper bound.
  51. Code: $options['query']['f'][] = 'field_price:[* TO *]';
  52. URL: ?f[0]=field_price%3A%5B%2A%20TO%20%2A%5D
  53. Note: When filtering a field whose machine name contains a colon (e.g.,
  54. "author:roles"), you'll have to additionally URL-encode the field name in these
  55. filter values:
  56. Code: $options['query']['f'][] = rawurlencode('author:roles') . ':100';
  57. URL: ?f[0]=author%253Aroles%3A100
  58. - Issues
  59. If you find any bugs or shortcomings while using this module, please file an
  60. issue in the project's issue queue [1], using the "Facets" component.
  61. [1] http://drupal.org/project/issues/search_api
  62. Information for developers
  63. --------------------------
  64. - Features
  65. If you are the developer of a SearchApiServiceInterface implementation and want
  66. to support facets with your service class, too, you'll have to support the
  67. "search_api_facets" feature. You can find details about the necessary additions
  68. to your class in the example_servive.php file. In short, you'll just, when
  69. executing a query, have to return facet terms and counts according to the
  70. query's "search_api_facets" option, if present.
  71. In order for the module to be able to tell that your server supports facets,
  72. you will also have to change your service's supportsFeature() method to
  73. something like the following:
  74. public function supportsFeature($feature) {
  75. return $feature == 'search_api_facets';
  76. }
  77. There is also a second feature defined by this module, namely
  78. "search_api_facets_operator_or", for supporting "OR" facets. The requirements
  79. for this feature are also explained in the example_servive.php file.
  80. - Query option
  81. The facets created follow the "search_api_base_path" option on the search query.
  82. If set, this path will be used as the base path from which facet links will be
  83. created. This can be used to show facets on pages without searches – e.g., as a
  84. landing page.
  85. - Hidden variable
  86. The module uses one hidden variable, "search_api_facets_search_ids", to keep
  87. track of the search IDs of searches executed for a given index. It is only
  88. updated when a facet is displayed for the respective search, so isn't really a
  89. reliable measure for this.
  90. In any case, if you e.g. did some test searches and now don't want them to show
  91. up in the block configuration forever after, just clear the variable:
  92. variable_del("search_api_facets_search_ids")