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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

2.4 Search form and empty searches


Go to End


6 Posts   1762 Views

Avatar
priithansen

Community Member, 25 Posts

18 November 2010 at 10:38am

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

Community Member, 25 Posts

25 November 2010 at 4:27am

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

Avatar
Corry

Community Member, 17 Posts

12 December 2010 at 7:09pm

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

Forum Moderator, 1899 Posts

13 December 2010 at 3:08am

Edited: 13/12/2010 10:32pm

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

Community Member, 17 Posts

13 December 2010 at 2:09pm

Edited: 13/12/2010 2:12pm

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

Forum Moderator, 1899 Posts

13 December 2010 at 10:32pm

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