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.

Form Questions

2.4 Search form and empty searches


Reply

6 Posts   1028 Views

Avatar
priithansen

18 November 2010 at 10:38am Community Member, 25 Posts

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!

Avatar
priithansen

25 November 2010 at 4:27am Community Member, 25 Posts

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

Avatar
Corry

12 December 2010 at 7:09pm Community Member, 17 Posts

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.

Avatar
swaiba

13 December 2010 at 3:08am (Last edited: 13 December 2010 10:32pm), Forum Moderator, 1796 Posts

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

Avatar
Corry

13 December 2010 at 2:09pm (Last edited: 13 December 2010 2:12pm), Community Member, 17 Posts

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

Avatar
swaiba

13 December 2010 at 10:32pm Forum Moderator, 1796 Posts

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