Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

[Solved] Searching dataobject


3 Posts   2023 Views


16 April 2009 at 5:31pm (Last edited: 2 May 2009 2:55pm), Community Member, 144 Posts

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

The dataobject is 'Product' and has

static $searchable_fields = array(

The form/ search function is:

public function SearchForm() {
      $context = singleton('Product')->getDefaultSearchContext();
      $fields = $context->getSearchFields();
      $form = new Form($this, "SearchForm",
         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

...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?


22 April 2009 at 11:41am Community Member, 144 Posts

Can anyone help with this??


2 May 2009 at 2:55pm Community Member, 144 Posts

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