Created
November 20, 2013 17:01
-
-
Save mrded/7566818 to your computer and use it in GitHub Desktop.
Drupal: Add custom field to Search API Solr index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_entity_property_info_alter(). | |
*/ | |
function example_search_api_property_entity_property_info_alter(&$info) { | |
$info['node']['properties']['created_week_day'] = array( | |
'type' => 'text', | |
'label' => t('Week day of node creation'), | |
'sanitized' => TRUE, | |
'getter callback' => 'example_search_api_property_weekday_getter_callback', | |
); | |
$info['node']['properties']['test_multiple_field'] = array( | |
'type' => 'list<text>', | |
'label' => t('Test multiple text'), | |
'sanitized' => TRUE, | |
'getter callback' => 'example_search_api_property_random_text_getter_callback', | |
); | |
} | |
/** | |
* Getter callback for created_week_day property. | |
*/ | |
function example_search_api_property_weekday_getter_callback($item) { | |
return format_date($item->created, 'custom', 'D'); | |
} | |
/** | |
* Getter callback for multiple field. | |
*/ | |
function example_search_api_property_random_text_getter_callback($item) { | |
$strings = array('one', 'two', 'three', 'four', 'five'); | |
$number = rand(1, 5); | |
$values = array(); | |
while ($number > 0) { | |
$values[] = $strings[rand(0, 4)]; | |
$number--; | |
} | |
return $values; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment