Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [Solved] Searching dataobject

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

Page: 1
Go to End
Author Topic: 1994 Views
  • NickJacobs
    Avatar
    Community Member
    144 Posts

    [Solved] Searching dataobject Link to this post

    Hi, I'm trying to implement the custom search context code from the wiki here. I'm using the following:

    The dataobject is 'Product' and has

    static $searchable_fields = array(
       'Description',
       'ProductCode'
       );

    The form/ search function is:

    public function SearchForm() {
          $context = singleton('Product')->getDefaultSearchContext();
          $fields = $context->getSearchFields();
          $form = new Form($this, "SearchForm",
             $fields,
             new FieldSet(
                new FormAction('doSearch')
             )
          );
          return $form;
       }
       public function doSearch($data, $form) {
          $context = singleton('Product')->getDefaultSearchContext();
          $results = $context->getResults($data);
          return $this->customise(array(
             'Results' => $results
          ))->renderWith('Page_results');
       }

    ...but, this gives me 2 fields on the form (Description & Product Code). I really only want one form field on the front-end of the site (ie keywords) but want it to search both Description and product code.

    Any ideas on this?

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: [Solved] Searching dataobject Link to this post

    Can anyone help with this??

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: [Solved] Searching dataobject Link to this post

    Unclecheese posted a snippet which addresses this issue here[/link]

    1994 Views
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.