Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Increase amount of search results

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

Page: 1
Go to End
Author Topic: 1064 Views
  • shakingpaper
    Avatar
    Community Member
    15 Posts

    Increase amount of search results Link to this post

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

    Cheers!

  • Ben_W
    Avatar
    Community Member
    80 Posts

    Re: Increase amount of search results Link to this post

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

  • Ben_W
    Avatar
    Community Member
    80 Posts

    Re: Increase amount of search results Link to this post

    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'));
       }

  • shakingpaper
    Avatar
    Community Member
    15 Posts

    Re: Increase amount of search results Link to this post

    Thanks Ben - perfect.

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

    1064 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.