-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Searching subclasses of Page #1
Comments
I have encountered this issue as well, it is a scenario I would definitly like to support and I thought Silverstripe would automatically perform a join onto parent objects when filtering. Apparently however this is not the case (or my code is incorrect in some way), so I am trying to work out how to get this working and any help would be greatly appreciated :-). |
I'm in the midst of coding my own search routine. I handle therelationships by checking for the presence of "." in the search field, and only add fulltext indexes on fields that belong to the Class table. Here's a quick preview; $searchClasses = array(
'SiteTree' => array('Title','Content'),
'Article' => array('Author','Summary','SiteTree.Title','SiteTree.Content'),
'Attorney' => array('Email','SideContent','DirectPhone','DirectFax','SiteTree.Content','SiteTree.Title'),
'Practice' => array('SiteTree.Title','SiteTree.Content'),
'Region' => array('Summary','SiteTree.Title','SiteTree.Content'),
);
SearchableExtension::enable($searchClasses); class SearchableExtension extends DataExtension
{
public static $searchClasses = array();
public static function enable($searchClasses = array())
{
foreach ($searchClasses as $class => $fields) {
$tableFields = array_filter($fields,
function ($var)
{
return (strpos($var, '.') === false);
});
if (! empty($tableFields)) {
//@todo ONLY if mysql version < 5.6
Config::inst()->update($class, 'create_table_options',
array(
'MySQLDatabase' => 'ENGINE=MyISAM'
));
$tableFieldsStr = implode(',',
array_map(
function ($var)
{
return sprintf('"%s"', $var);
}, $tableFields));
$class::add_extension("FulltextSearchable('$tableFieldsStr')");
}
}
self::$searchClasses = $searchClasses;
}
public static function get_extra_config($class, $extensionClass, $args)
{
return array(
'indexes' => array(
'SearchFields' => array(
'type' => 'fulltext',
'name' => 'SearchFields',
'value' => $args[0]
)
)
);
}
} |
Ok, I think I can see what you are doing. It would be be a little less reliant on configuration if the enable method tried to automatically detect if the class provided is an extension and if the fields to search exist on that class or the parent... Not sure how to though, will have to have a ponder... |
Is it possible to search objects that extend
Page
? For instance;I have a type,
Article
that extendsPage
and provides the following extra fields; Author and Summary. SilverStripe will create a database table named Article that containts the above fields as columns, but borrows upon the SiteTree table for the Content and Title field.I want to be able to search by Author, Summary text, Content text, and Title.. and add the following to _config;
This results in:
As those [Content, Title] fields don't exist on the Article table.
Does the module support this scenario?
Many thanks for any ideas.
~ Brice
The text was updated successfully, but these errors were encountered: