Source of file CwpSearchBoostExtension.php
Size: 2,050 Bytes - Last Modified: 2021-12-24T06:43:21+00:00
/var/www/docs.ssmods.com/process/src/src/Extensions/CwpSearchBoostExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | <?php namespace CWP\Search\Extensions; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\TextareaField; use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\ORM\DataExtension; /** * Adds field boosting capabilities to fulltext search for pages */ class CwpSearchBoostExtension extends DataExtension { /** * Quality to boost the 'SearchBoost' field by. * Default boost is 2x * * @config * @var string */ private static $search_boost = '2'; private static $db = [ 'SearchBoost' => 'Text', ]; /** * Adds boost fields to this page * * @param FieldList $fields */ public function updateCMSFields(FieldList $fields) { $pageInfoTitle = _t(__CLASS__ . '.PAGEINFO', 'Page info and SEO'); $boostTitle = _t(__CLASS__ . '.SearchBoost', 'Boost Keywords'); $boostNote = _t( __CLASS__ . '.SearchBoostNote', '(Only applies to the search results on this site e.g. not on Google search)' ); $boostDescription = _t( __CLASS__ . '.SearchBoostDescription', 'Enter keywords separated by comma ( , ) for which to boost the ranking of this page ' . 'within the search results on this site.' ); $boostField = TextareaField::create('SearchBoost', $boostTitle) ->setRightTitle($boostNote) ->setDescription($boostDescription); if ($meta = $fields->fieldByName('Root.Main.Metadata')) { // Rename metafield if it exists $meta->setTitle($pageInfoTitle); $fields->insertBefore('MetaDescription', $boostField); } else { // Else create new field to store SEO $fields->addFieldToTab( 'Root.Main', ToggleCompositeField::create( 'Metadata', $pageInfoTitle, [ $boostField, ] ) ); } } } |