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 /

Customize search to omit assets folder


Reply


4 Posts   643 Views

Avatar
webmmsd

Community Member, 10 Posts

17 January 2012 at 6:53am

Hello,

I would like my search results to not show anything from the "assets" folder. How can I keep that folder out of the search results.

Here's my page_results.ss file:
<div class="viewport results-page">
   <div class="content clearfix" style="padding:40px;">
   <h1>Search Results</h1>
   <% if Results %>
    <ul id="SearchResults">
    <% control Results %>
    <li>
    <% if MenuTitle %>
    <h3><a class="searchResultHeader" href="$Link">$MenuTitle</a></h3>
    <% else %>
    <h3><a class="searchResultHeader" href="$Link">$Title</a></h3>
    <% end_if %>
          <% if Content %>
       $Content.FirstParagraph(NoHTML)
          <% end_if %>
    <a class="readMoreLink" href="$Link" title="Read more about &quot;{$Title}&quot;">Read more about &quot;{$Title}&quot;...</a>
    </li>
    <% end_control %>
    </ul>
    <% else %>
    <p>Sorry, your search query did not return any results.</p>
    <% end_if %>

    <% if Results.MoreThanOnePage %>
    <div id="PageNumbers">
    <% if Results.NotLastPage %>
    <a class="next" href="$Results.NextLink" title="View the next page">Next</a>
    <% end_if %>
    <% if Results.NotFirstPage %>
    <a class="prev" href="$Results.PrevLink" title="View the previous page">Prev</a>
    <% end_if %>
    <span>
    <% control Results.SummaryPagination(5) %>
    <% if CurrentBool %>
    $PageNum
    <% else %>
    <a href="$Link" title="View page number $PageNum">$PageNum</a>
    <% end_if %>
    <% end_control %>
    </span>

    </div>
    <% end_if %>
   </div>
</div>

Thank You,
Alex

Avatar
SamTheJarvis

Community Member, 24 Posts

18 January 2012 at 3:27am

function results($data, $form, $request) {
      $form->classesToSearch(array('Page', 'SiteTree'));
      $data = array(
         'Results' => $form->getResults(),
         'Query' => $form->getSearchQuery(),
         'Title' => _t('SearchForm.SearchResults', 'Search Results')
      );
      return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
   }

Above is my overloaded "results" method.

You can set the classesToSearch on your form in your form action. The above will only search in the Page and SiteTree tables.

Hope that helps.

Avatar
swaiba

Forum Moderator, 1799 Posts

18 January 2012 at 8:20am

or this...

http://doc.silverstripe.org/sapphire/en/trunk/changelogs/2.4.6#security-user-uploaded-files-searchable-when-using-fulltextsearchable

Avatar
SamTheJarvis

Community Member, 24 Posts

15 February 2012 at 9:57am

Thanks swaiba, that's a better solution.