123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- function hook_synonyms_extractor_info() {
- return array(
-
-
- 'ApiSynonymsSynonymsExtractor',
- );
- }
- class ApiSynonymsSynonymsExtractor extends AbstractSynonymsExtractor {
-
- static public function fieldTypesSupported() {
- return array('text', 'number_integer', 'number_float', 'number_decimal');
- }
-
- static public function synonymsExtract($items, $field, $instance, $entity, $entity_type) {
- $synonyms = array();
- foreach ($items as $item) {
- $synonyms[] = $item['value'];
- }
- return $synonyms;
- }
-
- static public function processEntityFieldQuery($tag, EntityFieldQuery $query, $field, $instance) {
- $query->fieldCondition($field, 'value', '%' . $tag . '%', 'LIKE');
- }
-
- static public function mergeEntityAsSynonym($items, $field, $instance, $synonym_entity, $synonym_entity_type) {
- $synonym = entity_label($synonym_entity_type, $synonym_entity);
- switch ($field['type']) {
- case 'text':
- break;
-
- case 'number_integer':
- case 'number_float':
- case 'number_decimal':
- if (!is_numeric($synonym)) {
- return array();
- }
- break;
- }
- return array(array(
- 'value' => $synonym,
- ));
- }
- }
|