diff --git a/search/ContentControllerSearchExtension.php b/search/ContentControllerSearchExtension.php index b0ad72d12..ab0d9c03d 100644 --- a/search/ContentControllerSearchExtension.php +++ b/search/ContentControllerSearchExtension.php @@ -1,38 +1,40 @@ owner->request) { $searchText = $this->owner->request->getVar('Search'); } - + $fields = new FieldSet( new TextField('Search', false, $searchText) ); $actions = new FieldSet( new FormAction('results', _t('SearchForm.GO', 'Go')) ); - return new SearchForm($this->owner, 'SearchForm', $fields, $actions); + $form = new SearchForm($this->owner, 'SearchForm', $fields, $actions); + $form->classesToSearch(FulltextSearchable::$searchableClasses); + return $form; } /** * Process and render search results. - * + * * @param array $data The raw request data submitted by user * @param SearchForm $form The form instance that was submitted * @param SS_HTTPRequest $request Request generated for this action diff --git a/search/FulltextSearchable.php b/search/FulltextSearchable.php index b1fa092c1..b5b4e9ffc 100644 --- a/search/FulltextSearchable.php +++ b/search/FulltextSearchable.php @@ -1,13 +1,14 @@ 'Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords', 'File' => 'Filename,Title,Content' ); - + if(!is_array($searchableClasses)) $searchableClasses = array($searchableClasses); foreach($searchableClasses as $class) { if(isset($defaultColumns[$class])) { @@ -25,25 +26,26 @@ class FulltextSearchable extends DataObjectDecorator { throw new Exception("FulltextSearchable::enable() I don't know the default search columns for class '$class'"); } } - + self::$searchableClasses = $searchableClasses; + Object::add_extension("ContentController", "ContentControllerSearchExtension"); } - + function __construct($searchFields) { if(is_array($searchFields)) $this->searchFields = implode(',', $searchFields); else $this->searchFields = $searchFields; parent::__construct(); } - + function extraStatics($class = null, $extension = null) { if($extension && preg_match('/\([\'"](.*)[\'"]\)/', $extension, $matches)) { $searchFields = $matches[1]; - + return array( 'indexes' => array( "SearchFields" => Array( - 'type'=>'fulltext', - 'name'=>'SearchFields', + 'type'=>'fulltext', + 'name'=>'SearchFields', 'value'=> $searchFields ), ) diff --git a/search/SearchForm.php b/search/SearchForm.php index ce720a2c6..d06f29c68 100755 --- a/search/SearchForm.php +++ b/search/SearchForm.php @@ -78,6 +78,15 @@ class SearchForm extends Form { $legalClasses = array_intersect($classes, array('SiteTree', 'File')); $this->classesToSearch = $legalClasses; } + + /** + * Get the classes to search + * + * @return array + */ + function getClassesToSearch() { + return $this->classesToSearch; + } /** * Return dataObjectSet of the results using $_REQUEST to get info from form. diff --git a/tests/search/ContentControllerSearchExtensionTest.php b/tests/search/ContentControllerSearchExtensionTest.php new file mode 100644 index 000000000..afe35a739 --- /dev/null +++ b/tests/search/ContentControllerSearchExtensionTest.php @@ -0,0 +1,13 @@ +SearchForm(); + + $this->assertEquals(array('File'), $form->getClassesToSearch()); + } +} \ No newline at end of file