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.

Customising the CMS

Increase amount of search results


Reply

4 Posts   1088 Views

Avatar
shakingpaper

9 May 2011 at 5:57pm Community Member, 15 Posts

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

Cheers!

Avatar
Ben_W

10 May 2011 at 12:01pm Community Member, 80 Posts

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

Avatar
Ben_W

10 May 2011 at 12:12pm Community Member, 80 Posts

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

10 May 2011 at 2:50pm Community Member, 15 Posts

Thanks Ben - perfect.

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