示例#1
0
 public function updateExtensibleSearchPageCMSFields(FieldList $fields)
 {
     if ($this->owner->SearchEngine === get_class($this)) {
         $types = SiteTree::page_type_classes();
         $source = array_combine($types, $types);
         // add in any explicitly configured
         asort($source);
         $source = $this->owner->updateSource($source);
         $parsers = $this->owner->getQueryBuilders();
         $options = array();
         foreach ($parsers as $key => $objCls) {
             $obj = new $objCls();
             $options[$key] = $obj->title;
         }
         $fields->addFieldToTab('Root.Main', new DropdownField('QueryType', _t('ExtensibleSearchPage.QUERY_TYPE', 'Query Type'), $options), 'Content');
         ksort($source);
         $source = array_merge($source, ExtensibleSearchPage::config()->additional_search_types);
         $types = MultiValueDropdownField::create('SearchType', _t('ExtensibleSearchPage.SEARCH_ITEM_TYPE', 'Search items of type'), $source);
         $fields->addFieldToTab('Root.Main', $types, 'Content');
         $objFields = $this->owner->getSelectableFields();
         $sortFields = $objFields;
         // Remove content and groups from being sortable (as they are not relevant).
         unset($sortFields['Content']);
         unset($sortFields['Groups']);
         $fields->replaceField('SortBy', new DropdownField('SortBy', _t('ExtensibleSearchPage.SORT_BY', 'Sort By'), $sortFields));
         $fields->addFieldToTab('Root.Main', MultiValueDropdownField::create('SearchOnFields', _t('ExtensibleSearchPage.INCLUDE_FIELDS', 'Search On Fields'), $objFields), 'Content');
         $fields->addFieldToTab('Root.Main', MultiValueTextField::create('ExtraSearchFields', _t('SolrSearch.EXTRA_FIELDS', 'Custom solr fields to search')), 'Content');
         $boostVals = array();
         for ($i = 1; $i <= static::BOOST_MAX; $i++) {
             $boostVals[$i] = $i;
         }
         $fields->addFieldToTab('Root.Main', new KeyValueField('BoostFields', _t('ExtensibleSearchPage.BOOST_FIELDS', 'Boost values'), $objFields, $boostVals), 'Content');
         $fields->addFieldToTab('Root.Main', $f = new KeyValueField('BoostMatchFields', _t('ExtensibleSearchPage.BOOST_MATCH_FIELDS', 'Boost fields with field/value matches'), array(), $boostVals), 'Content');
         $f->setRightTitle('Enter a field name, followed by the value to boost if found in the result set, eg "title:Home" ');
         $fields->addFieldToTab('Root.Main', $kv = new KeyValueField('FilterFields', _t('ExtensibleSearchPage.FILTER_FIELDS', 'Fields to filter by')), 'Content');
         $fields->addFieldToTab('Root.Main', new HeaderField('FacetHeader', _t('ExtensibleSearchPage.FACET_HEADER', 'Facet Settings')), 'Content');
         $fields->addFieldToTab('Root.Main', new MultiValueDropdownField('FacetFields', _t('ExtensibleSearchPage.FACET_FIELDS', 'Fields to create facets for'), $objFields), 'Content');
         $fields->addFieldToTab('Root.Main', new MultiValueTextField('CustomFacetFields', _t('ExtensibleSearchPage.CUSTOM_FACET_FIELDS', 'Additional fields to create facets for')), 'Content');
         $facetMappingFields = $objFields;
         if ($this->owner->CustomFacetFields && ($cff = $this->owner->CustomFacetFields->getValues())) {
             foreach ($cff as $facetField) {
                 $facetMappingFields[$facetField] = $facetField;
             }
         }
         $fields->addFieldToTab('Root.Main', new KeyValueField('FacetMapping', _t('ExtensibleSearchPage.FACET_MAPPING', 'Mapping of facet title to nice title'), $facetMappingFields), 'Content');
         $fields->addFieldToTab('Root.Main', new KeyValueField('FacetQueries', _t('ExtensibleSearchPage.FACET_QUERIES', 'Fields to create query facets for')), 'Content');
         $fields->addFieldToTab('Root.Main', new NumericField('MinFacetCount', _t('ExtensibleSearchPage.MIN_FACET_COUNT', 'Minimum facet count for inclusion in facet results'), 2), 'Content');
     }
     // Make sure previously existing hooks are carried across.
     $this->owner->extend('updateSolrCMSFields', $fields);
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $types = ClassInfo::dataClassesFor('DataObject');
     array_shift($types);
     asort($types);
     $source = array_combine($types, $types);
     $source = array_merge($source, ExtensibleSearchPage::config()->additional_search_types);
     $fields->replaceField('Title', new DropdownField('Title', _t('Solr.TYPE_CONFIG_TITLE', 'Data type'), $source));
     if ($this->Title) {
         $keys = $this->getFieldsFor($this->Title);
         $vals = array('default' => _t('Solr.DEFAULT_MAPPING', 'Default type'), ':field_as' => _t('Solr.CASE_INSENSITIVE', 'Case Insensitive text'), ':field_ms' => _t('Solr.CASE_SENSITIVE', 'Case Sensitive, untokenised text'));
         $fields->replaceField('FieldMappings', new KeyValueField('FieldMappings', _t('Solr.FIELD_MAPPINGS', 'Indexed fields'), $keys, $vals, $this->FieldMappings));
     } else {
         $fields->removeByName('FieldMappings');
     }
     return $fields;
 }