Source of file DataDiscovery.php
Size: 1,832 Bytes - Last Modified: 2021-12-23T10:25:26+00:00
/var/www/docs.ssmods.com/process/src/src/Symbiote/Elastica/DataDiscovery.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | <?php namespace Symbiote\Elastica; /** * * * @author marcus */ class DataDiscovery extends \DataExtension { //put your code here private static $db = [ 'BoostTerms' => 'MultiValueField', ]; public function updateCMSFields(\FieldList $fields) { $fields->addFieldsToTab('Root.Tagging', $mvf = \MultiValueTextField::create('BoostTerms', 'Boost for these keywords')); $mvf->setRightTitle("Enter the word 'important' to boost this item in any search it appears in"); } /** * Sets appropriate mappings for fields that need to be subsequently faceted upon * @param type $mappings */ public function updateElasticMappings($mappings) { $mappings['BoostTerms'] = ['type' => 'keyword']; $mappings['Categories'] = ['type' => 'keyword']; $mappings['Keywords'] = ['type' => 'text']; $mappings['Tags'] = ['type' => 'keyword']; if ($this->owner instanceof \SiteTree) { // store the SS_URL for consistency $mappings['SS_URL'] = ['type' => 'text']; } } public function updateSearchableData($fieldValues) { $fieldValues['BoostTerms'] = $this->owner->BoostTerms->getValues(); // expects taxonomy terms here... if ($this->owner->hasMethod('Terms')) { $categories = $this->owner->Terms()->column('Name'); $currentCats = isset($fieldValues['Categories']) ? $fieldValues['Categories'] : []; $fieldValues['Categories'] = array_merge($currentCats, $categories); $fieldValues['Keywords'] = implode(' ', $categories); } if ($this->owner instanceof \SiteTree) { // store the SS_URL for consistency $fieldValues['SS_URL'] = $this->owner->RelativeLink(); } } } |