Jump to:

1999 Posts in 1408 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » 2.4 Search form and empty searches

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

Page: 1
Go to End
Author Topic: 1000 Views
  • priithansen
    Avatar
    Community Member
    25 Posts

    2.4 Search form and empty searches Link to this post

    Hello I'm very new with SS but really enjoying the experience so far and would like to thank for this wonderful project.

    But I'm stuck with the search function that exists starting with version 2.4
    The one where You but FulltextSearchable::enable(); into _config and $SearchForm. to template.

    The problem is it works a little bit too well and I dont't know how to restrict it. If I do a empty search it finds all the error pages and Upload folder as well. search for "error" find the pages too even though I have tried changing the error pages search option.

    Any ideas how to keep that from appearing in the search?

    Any help appreciated!

  • priithansen
    Avatar
    Community Member
    25 Posts

    Re: 2.4 Search form and empty searches Link to this post

    Nobody has any ideas how to restrict the built in search function?

  • Corry
    Avatar
    Community Member
    17 Posts

    Re: 2.4 Search form and empty searches Link to this post

    I've noticed the same problem.

    I went to the behaviour tab for 'Page not found' and checked that "Show in search?" was not ticked. However search is still listing the page.

    Is there a fix? I'm using SS 2.4.1 at the moment.

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: 2.4 Search form and empty searches Link to this post

    look for this in your Page.php

    function results($data, $form){
       $data = array(
          'Results' => $form->getResults(),
          'Query' => $form->getSearchQuery(),
          'Title' => 'Search Results'
       );

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

    replace with something like this...

    function results($data, $form){
       
       $dosResults = new DataObjectSet();
       
       if (!empty($data['Search'])) {
          $dosResults = $form->getResults();
       }
       
       $data = array(
          'Results' => $dosResults,
          'Query' => $form->getSearchQuery(),
          'Title' => 'Search Results'
       );

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

  • Corry
    Avatar
    Community Member
    17 Posts

    Re: 2.4 Search form and empty searches Link to this post

    Thanks for the reply. That code didn't work for me ... wouldn't parse the if statement (unexpected "}").

    However in the meantime I upgraded the website to SS version 2.4.3 and commented out the line in my existing search function that appeared to be superfluous.

    Not sure which action helped but 'page not found' is no longer being shown in my search results.

    function results($data, $form){
    $data = array(
    'Results' => $form->getResults(),
    'Query' => $form->getSearchQuery(),
    'Title' => 'Search Results'
    )
    // $this->Query = $form->getSearchQuery();
    return $this->customise($data)->renderWith(array('Page_results', 'Page'));
    }

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: 2.4 Search form and empty searches Link to this post

    Glad it worked out with you. that code was untested and I've just seen one typo that I've fixed for the record, it ain't cut&paste, but I've done something like it before

    1000 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.