How to add DataObject to search results using $SearchForm?

**Silverstripe Version:5.1

I want to add a DataObject to be included in the Search results using the built in $SearchForm.

Unfortuntately the following was not sufficient:

    private static $searchable_fields = [

According to the documentation: “please use Object::add_extension() directly:”


so I added it to my _config.php

FulltextSearchable::enable([SiteTree::class]); // this works (files not showing any more)
Product::add_extension("FulltextSearchable('Title')"); // doesn't work, please see error message below

When I do myproject.local/dev/build?flush, I get the following error:
ERROR [Emergency]: Uncaught InvalidArgumentException: Object::add_extension() - Can’t find extension class for “FulltextSearchable” IN GET /dev/build?flush

I have added the

    private static $create_table_options = [
        MySQLSchemaManager::ID => 'ENGINE=MyISAM',

What else do I need to do?

Can anybody please let me know how to get DataObjects included into the search results of $SearchForm?

Thanks and Happy Easter.

I’m guessing you may need to pass the fully qualified class name of FulltextSearchable into the add_extension() method, because in the extensible class, it’s checking that parameter with class_exists()

Extensible class on github

eg. Product::add_extension("SilverStripe\ORM\Search\FulltextSearchable('Title')");

That really is a complete guess though!

Hi Tim,
Thank you very much.

That definitely solved the dev/build error and I got “Index Product.SearchFields: created as fulltext (“Title”)” :grinning:, but unfortunately when I search for a product, it doesn’t come up in the search result.

Do you have any idea why this might be?

OK, this isn’t something I’ve had to deal with for ages (like, years), so there’s a little bit of guesswork again.

According to the docs here:

The SearchForm class is hardcoded to only search in the Page and File classes. So, you’ll probably need to replace that class in order to add your own dataobject to the search. (You can do this using Injector fairly easily). The SearchForm class is actually pretty simple, so hopefully it won’t be a big chore to do.

This is the standard class: silverstripe-cms/code/Search/SearchForm.php at 5 · silverstripe/silverstripe-cms · GitHub

Injector docs:

Hi Tim,
Thanks for your help.
After a lot of googling I finally found this hidden gem: which did the trick.
Just mention it here in case somebody else has the same problem.