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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

Increase amount of search results


Go to End


4 Posts   1575 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.