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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

[Solved] Searching dataobject


Go to End


3 Posts   4625 Views

Avatar
NickJacobs

Community Member, 148 Posts

16 April 2009 at 5:31pm

Edited: 02/05/2009 2:55pm

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?

Avatar
NickJacobs

Community Member, 148 Posts

22 April 2009 at 11:41am

Can anyone help with this??

Avatar
NickJacobs

Community Member, 148 Posts

2 May 2009 at 2:55pm

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