3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1542 Views |
-
search form results , block image searching

19 February 2010 at 10:03am
Hi
I'm using standard search form function
function SearchForm() {
$searchText = isset($this->Query) ? $this->Query : '';
$fields = new FieldSet(
new TextField("Search", "", $searchText)
);
$actions = new FieldSet(
new FormAction('results', 'find product')
);return new SearchForm($this, "SearchForm", $fields, $actions);
}
/**
* Process and render search results
*/
function results($data, $form){
if($form->getSearchQuery() == NULL) {
$data = array(
'Results' => '',
'Query' => '',
'Title' => 'Your results'
);
} else {
$data = array(
'Results' => $form->getResults(),
'Query' => $form->getSearchQuery(),
'Title' => 'Your results'
);
}return $this->customise($data)->renderWith(array('Results_Page', 'Page'));
}but it also searchs image files
if file has a name for example:kitchen_image_2.jpg
and i want to search "kitchen" , one of the results is this image
also if i have a folder "kitchen" with many images, they also are including to search resultso my question is
how to block image searching ? -
Re: search form results , block image searching

22 February 2010 at 8:44am
In your Page Controller you'll have a method called SearchForm(). The last line should read:
return new SearchForm($this, "SearchForm", $fields, $actions);
Change this to:
$form = new SearchForm($this, "SearchForm", $fields, $actions);
$form->classesToSearch(array('SiteTree'));
return $form; -
Re: search form results , block image searching

22 February 2010 at 10:47pm
maby you can help with with second problem
also with image in serach results : )i have product page with
has_one {
'Img' => 'Image'
}but standard search form only searching in the SiteTree so i cant display product image
how to modify this search form function to display images ? -
Re: search form results , block image searching

3 April 2011 at 8:50am
If you know that one form needs to search Files and Pages and the other searches JUST the pages and it's ALWAYS going to be like that, couldn't you hardcode a parameter in your template for your overloaded SearchForm() function?
-
Re: search form results , block image searching

31 May 2013 at 6:22am
Not sure if this is the best method, but seems to work as well. In sapphire/search/FulltextSearchable.php, around line 40 it says:
static function enable($searchableClasses = array('SiteTree', 'File')) {
$defaultColumns = array(
'SiteTree' => 'Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords',
'File' => 'Filename,Title,Content'
);which is therefore searching both items in SiteTree and items in File. I had users uploading resumes through the site and those were showing in search results! To counter this, I simply deleted the 'File' information from search and now that line looks like:
static function enable($searchableClasses = array('SiteTree')) {
$defaultColumns = array(
'SiteTree' => 'Title,MenuTitle,Content,MetaTitle,MetaDescription,MetaKeywords'
);Now when I search on the site the uploaded resumes don't show up in search results. Again, not sure if this is the best or preferred method, but seems to work.
| 1542 Views | ||
|
Page:
1
|
Go to Top |




