Hi
I'm using 2.4.4 and implementing a search based on the tutorial 4 - Site search one (http://doc.silverstripe.org/sapphire/en/tutorials/4-site-search.
I want to filter out all images, files and folders from the search results. This bit works fine but causes problems when displaying these results using pagination. I'm using $Results.TotalItems in the ss file and this returns the total number of results INCLUDING the filtered out ones. For example, might get 23 results with 6 "File"s - pagination shows 3 pages - first page might have 8 results, second page 9 results, third page no results. How would I filter and then display results on the entire set rather than what is currently happening - filtering by page?
An aside: How do I change/set the number of results returned for each page? Would this help solve the issue?
I also want to restrict search terms to 4 characters or above - hence the line $searchQueryLength = strlen($searchQuery);
How would I do this?
(I know mySQL defaults to indexing 4 chars but my ISP won't decrease ft_min_word_len so searches of less than 4 chars return inconsistent results.)
Code is below:
function results($data, $form){
$searchQuery = $form->getSearchQuery();
$searchQueryLength = strlen($searchQuery);
$results = $form->getResults();
/* Filters out results not to be displayed */
foreach($results AS $result) {
if($result->ClassName == "Image") $results->remove($result);
if($result->ClassName == "File") $results->remove($result);
if($result->ClassName == "Folder") $results->remove($result);
}
$data = array(
'Results' => $results,
'Query' => $form->getSearchQuery(),
'Title' => 'Search Results'
);
$this->Query = $form->getSearchQuery();
return $this->customise($data)->renderWith(array('Search_results', 'Page'));
}
Hoping someone can point me in the right direction.
Thank you in advance, Mark