spellcheck.inc 896 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * @file
  4. * Contains the SearchApiSpellcheckSolr class.
  5. */
  6. /**
  7. * Spellcheck class which can provide spelling suggestions. The constructor
  8. * populates the instance with any suggestions returned by Solr.
  9. */
  10. class SearchApiSpellcheckSolr extends SearchApiSpellcheck {
  11. /**
  12. * Constructs a SearchApiSpellcheckSolr object.
  13. *
  14. * If Solr has returned spelling suggestion then loop through them and add
  15. * them to this spellcheck service.
  16. *
  17. * @param object $response
  18. * The Solr response object.
  19. */
  20. function __construct($response) {
  21. if (isset($response->spellcheck->suggestions)) {
  22. $suggestions = $response->spellcheck->suggestions;
  23. foreach ($suggestions as $word => $data) {
  24. foreach ($data->suggestion as $suggestion) {
  25. $this->addSuggestion(new SearchApiSpellcheckSuggestion($word, $suggestion));
  26. }
  27. }
  28. }
  29. }
  30. }