BUGFIX: Search didn't respect searchableClasses passed to FulltextSearchable::enable() (from r111464)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112905 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-19 03:54:51 +00:00
parent 0d19b45155
commit dd1c02cd90
4 changed files with 42 additions and 16 deletions

View File

@ -27,7 +27,9 @@ class ContentControllerSearchExtension extends Extension {
$actions = new FieldSet( $actions = new FieldSet(
new FormAction('results', _t('SearchForm.GO', 'Go')) 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;
} }
/** /**

View File

@ -7,6 +7,7 @@
*/ */
class FulltextSearchable extends DataObjectDecorator { class FulltextSearchable extends DataObjectDecorator {
protected $searchFields; protected $searchFields;
static $searchableClasses;
/** /**
* Enable the default configuration of MySQL full-text searching on the given data classes. * Enable the default configuration of MySQL full-text searching on the given data classes.
@ -25,6 +26,7 @@ class FulltextSearchable extends DataObjectDecorator {
throw new Exception("FulltextSearchable::enable() I don't know the default search columns for class '$class'"); throw new Exception("FulltextSearchable::enable() I don't know the default search columns for class '$class'");
} }
} }
self::$searchableClasses = $searchableClasses;
Object::add_extension("ContentController", "ContentControllerSearchExtension"); Object::add_extension("ContentController", "ContentControllerSearchExtension");
} }

View File

@ -79,6 +79,15 @@ class SearchForm extends Form {
$this->classesToSearch = $legalClasses; $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. * Return dataObjectSet of the results using $_REQUEST to get info from form.
* Wraps around {@link searchEngine()}. * Wraps around {@link searchEngine()}.

View File

@ -0,0 +1,13 @@
<?php
class ContentControllerSearchExtensionTest extends SapphireTest {
function testCustomSearchFormClassesToTest() {
FulltextSearchable::enable('File');
$page = new Page();
$controller = new ContentController($page);
$form = $controller->SearchForm();
$this->assertEquals(array('File'), $form->getClassesToSearch());
}
}