Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Add custom search fields to search in frontend?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1298 Views
  • mco
    Community Member
    14 Posts

    Add custom search fields to search in frontend? Link to this post


    maybe this has been asked a lot of times but I don't get it running...

    I want to add some additional fields of my SiteTree object to be available for fulltext search (the one in the front-end)

    So in my Page.php if have

    class Page extends SiteTree {
    static $db = array(
    'Teaser' => 'Text',
    'TinyURL' => 'Varchar(255)'

       static $searchable_fields = array (
          'Teaser' => array(
             'field' => 'TextField',
             'filter' => 'PartialMatchFilter',
             'title' => 'Teaser Text'

    No i entered some text in the Teaser field in the backend and expected the page to be found using the frontend-search.
    AR: wasn't found...

    Did i miss something?
    I use the default search implementation in the Page_Controler:

    public function SearchForm() {
          $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
          $fields = new FieldSet(
           new TextField("Search", "", $searchText)
          $actions = new FieldSet(
           new FormAction('results', 'Search')

           return new SearchForm($this, "SearchForm", $fields, $actions);

       public function results($data, $form) {

          $results = $form->getResults();
           $data = array(
    'Result' => $results,
    'Query' => $form->getSearchQuery(),
           'Title' => 'Search Results'

    return $this->customise($data)->renderWith(array('Article_proc', 'Page'));

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.