Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • AdvancedSearchForm
  • ContentControllerSearchExtension
  • EndsWithFilter
  • ExactMatchFilter
  • ExactMatchMultiFilter
  • FulltextFilter
  • FulltextSearchable
  • GreaterThanFilter
  • LessThanFilter
  • NegationFilter
  • PartialMatchFilter
  • SearchContext
  • SearchFilter
  • SearchForm
  • StartsWithFilter
  • StartsWithMultiFilter
  • SubstringFilter
  • WithinRangeFilter
 1 <?php
 2 /**
 3  * Provides a simple search engine for your site based on the MySQL FULLTEXT index
 4  * 
 5  * @package sapphire
 6  * @subpackage search
 7  */
 8 class FulltextSearchable extends DataObjectDecorator {
 9     protected $searchFields;
10     
11     /**
12      * Enable the default configuration of MySQL full-text searching on the given data classes.
13      */
14     static function enable($searchableClasses = array('SiteTree', 'File')) {
15         $defaultColumns = array(
16             'SiteTree' => 'Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords',
17             'File' => 'Filename,Title,Content'
18         );
19         
20         if(!is_array($searchableClasses)) $searchableClasses = array($searchableClasses);
21         foreach($searchableClasses as $class) {
22                         if(method_exists($class, 'defaultSearchColumns')){
23                             $c = singleton($class);
24                             $defaultColumnsContex = $c->defaultSearchColumns();
25                             Object::add_extension($class, "FulltextSearchable('{$defaultColumnsContex}')");
26                         }else{
27                             if(isset($defaultColumns[$class])) {
28                                     Object::add_extension($class, "FulltextSearchable('{$defaultColumns[$class]}')");
29                             } else {
30                                     throw new Exception("FulltextSearchable::enable() I don't know the default search columns for class '$class'");
31                             }
32                         }
33         }
34         
35         Object::add_extension("ContentController", "ContentControllerSearchExtension");
36     }
37     
38     function __construct($searchFields) {
39         if(is_array($searchFields)) $this->searchFields = implode(',', $searchFields);
40         else $this->searchFields = $searchFields;
41         parent::__construct();
42     }
43     
44     function extraStatics($class = null, $extension = null) {
45         if($extension && preg_match('/\([\'"](.*)[\'"]\)/', $extension, $matches)) {
46             $searchFields = $matches[1];
47         
48             return array(
49                 'indexes' => array(
50                     "SearchFields" => Array(
51                         'type'=>'fulltext', 
52                         'name'=>'SearchFields', 
53                         'value'=> $searchFields
54                     ),
55                 )
56             );
57         }
58     }
59 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0