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.

Customising the CMS /

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

Increase amount of search results


Go to End


4 Posts   1978 Views

Avatar
shakingpaper

Community Member, 15 Posts

9 May 2011 at 5:57pm

Am wondering how I would go about increasing the amount of search results from the default 10?

Cheers!

Avatar
Ben_W

Community Member, 80 Posts

10 May 2011 at 12:01pm

Mate, you need to post your code here, and be more specific, so people here can understand your problems better.

Avatar
Ben_W

Community Member, 80 Posts

10 May 2011 at 12:12pm

Assuming you are using the following:

/**
	 * Site search form 
	 */ 
	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);
	}
	
	/**
	 * Process and render search results
	 */
	function results($data, $form){
	  	$data = array(
	     	'Results' => $form->getResults(),
	     	'Query' => $form->getSearchQuery(),
	      	'Title' => 'Search Results'
	  	);

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

then in the function results() modify the second line like following:

        function results($data, $form){
	  	$data = array(
	     	'Results' => $form->getResults(20), //add the number of search results as param
	     	'Query' => $form->getSearchQuery(),
	      	'Title' => 'Search Results'
	  	);

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

Avatar
shakingpaper

Community Member, 15 Posts

10 May 2011 at 2:50pm

Thanks Ben - perfect.

Apologies, I completely forgot to post the code but I was using the standard Silverstripe tutorial stuff.