Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » Limiting Search Results

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

Page: 1
Go to End
Author Topic: 2742 Views
  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Limiting Search Results Link to this post

    Hi,

    Just how is the silverstripe search doing it's thing. I went through the tutorial a long time ago and it works OK. But now my client is complaining as the results are:

    1. Fairly inaccurate
    2. Don't display a first paragraph of content as per the tutorial.
    3. Including searches through the entire Upload directory (PDF and Doc). These ones in particular are destroying the look of the result page, as the content returned contains weird spacing.

    All I can see in the code is this function in Page.php:

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

    Three key questions:

    1. How exactly is that code doing the entire search?
    2. How do I tell it to stay out of my Uploads directory?
    3. I haven't heard a peep about the new search system in 2.3, although I it appears to be built in. Will I have more luck with a 2.2 to 2.3 upgrade? Is there documentation for this if it has changed?

    Cheers
    Aaron

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Limiting Search Results Link to this post

    Have a look at the SearchForm class, thats where everything happens.
    No big changes since 2.2 for this, though. You'd need to subclass this and adjust
    to your needs - e.g. not to query File/Image subclasses.

    We've got a bunch of tickets in the queue concerning a new search implementation:
    http://open.silverstripe.com/ticket/3200
    http://open.silverstripe.com/ticket/3147
    http://open.silverstripe.com/ticket/3331
    http://open.silverstripe.com/ticket/3703

  • tsg
    Avatar
    Community Member
    7 Posts

    Re: Limiting Search Results Link to this post

    A quick and easy fix if you don't want images returned in your search results.

       function results($data, $form){

          $results = $form->getResults();

          foreach($results AS $result) {
             if($result->ClassName == "Image") $results->remove($result);
          }

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

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

  • Alex S
    Avatar
    Community Member
    30 Posts

    Re: Limiting Search Results Link to this post

    Hey,

    Cool fix, I was a little concerned that the contents of my assets folder was being shown in search results. One extra tweak I made was removal of the 'file' class from the results as well:

    if($result->ClassName == "File") $results->remove($result);

    Just in case that's any help to anyone.

    Alex

  • Alex S
    Avatar
    Community Member
    30 Posts

    Re: Limiting Search Results Link to this post

    Also,

    Useful to remove folders from results too, again, the uploads folder was being listed, which didn't work for me.

    if($result->ClassName == "Folder") $results->remove($result);

    Alex

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