SynonymsSynonymsExtractor.class.inc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Default Synonyms Extractor class that ships together with the Synonym module.
  5. */
  6. class SynonymsSynonymsExtractor extends AbstractSynonymsExtractor {
  7. public static function fieldTypesSupported() {
  8. return array('text', 'number_integer', 'number_float', 'number_decimal');
  9. }
  10. public static function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
  11. $synonyms = array();
  12. foreach ($items as $item) {
  13. $synonyms[] = $item['value'];
  14. }
  15. return $synonyms;
  16. }
  17. public static function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {
  18. $query->fieldCondition($field, 'value', '%' . $tag . '%', 'LIKE');
  19. }
  20. public static function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
  21. $synonym = entity_label($synonym_entity_type, $synonym_entity);
  22. switch ($field['type']) {
  23. case 'text':
  24. break;
  25. // We add synonyms for numbers only if $synonym is a number.
  26. case 'number_integer':
  27. case 'number_float':
  28. case 'number_decimal':
  29. if (!is_numeric($synonym)) {
  30. return array();
  31. }
  32. break;
  33. }
  34. return array(array(
  35. 'value' => $synonym,
  36. ));
  37. }
  38. }