Dejsa Cocan
Dejsa Cocan

Reputation: 1569

SilverStripe (3.6.2) Search returning assets folder contents

I haven't enabled Search on SilverStripe before, but it seems pretty easy. I've followed steps from 2 other projects (although they are 3.5 version projects but not sure that makes a difference or not) that have search enabled as well as the tutorial offered on SilverStripe's site, and for some reason, I'm getting asset folder items (i.e. images) in my search results. It only seems to happen if I click to search and nothing has been entered into the search field.

There should be no asset items returned at any time for search, and if there is no search query, then there should be a message saying nothing was entered or something. I noticed that using the default $SearchForm setup provided by the basic install gives me the desired results, but not for the form I'm using (which does work on 2 other SilverStripe sites--I checked and confirmed).

I'm not sure what I'm missing? I feel like everything is done correctly, and I would like to use the setup I have now to give me more styling ability:

From _config.php:

FulltextSearchable::enable();

From my Header.ss file:

 <!-- SEARCH BAR -->
<form class="navbar-form navbar-left nav-right-left search-form" id="SearchForm_SearchForm" action="/home/SearchForm" method="get" enctype="application/x-www-form-urlencoded">
    <fieldset style="font-size: 0;">
        <div class="field text nolabel search-holder">
            <input name="Search" placeholder="Search" class="form-control search-field text nolabel active search-box" />
        </div>
        <div class="ja-search-box">
            <button class="icon search-button smiths-search-btn" type="submit"><i class="glyphicon glyphicon-search pull-right"></i></button>
        </div>
    </fieldset>
</form>

The Search Results page:

<div class="main" role="main">
    <div class="container">
        <div class="row">
            <div class="col-xs-12">
                <div id="Content" class="searchResults">
                    <h1 class="brand-red">$Title</h1>

                    <% if $Query %>
                        <p class="searchQuery">You searched for &quot;{$Query}&quot;</p>
                    <% end_if %>

                    <% if $Results %>
                        <ul id="SearchResults">
                            <% loop $Results %>
                                <li>
                                    <h4>
                                        <a href="$Link">
                                            <% if $MenuTitle %>
                                                $MenuTitle
                                            <% else %>
                                                $Title
                                            <% end_if %>
                                        </a>
                                    </h4>
                                    <% if $Content %>
                                        <p>$Content.LimitWordCountXML</p>
                                    <% end_if %>
                                    <a class="readMoreLink" href="$Link" title="Read more about &quot;{$Title}&quot;">Read more about &quot;{$Title}&quot;...</a>
                                </li>
                            <% end_loop %>
                        </ul>
                    <% else %>
                        <p>Sorry, your search query did not return any results.</p>
                    <% end_if %>

                    <% if $Results.MoreThanOnePage %>
                        <div id="PageNumbers">
                            <div class="pagination">
                                <% if $Results.NotFirstPage %>
                                    <a class="prev" href="$Results.PrevLink" title="View the previous page">&larr;</a>
                                <% end_if %>
                                <span>
                                    <% loop $Results.Pages %>
                                        <% if $CurrentBool %>
                                            $PageNum
                                        <% else %>
                                            <a href="$Link" title="View page number $PageNum" class="go-to-page">$PageNum</a>
                                        <% end_if %>
                                    <% end_loop %>
                                </span>
                                <% if $Results.NotLastPage %>
                                    <a class="next" href="$Results.NextLink" title="View the next page">&rarr;</a>
                                <% end_if %>
                            </div>
                            <p>Page $Results.CurrentPage of $Results.TotalPages</p>
                        </div>
                    <% end_if %>
                </div>
            </div>
        </div>
    </div>
</div>

Upvotes: 1

Views: 88

Answers (1)

Gavin Bruce
Gavin Bruce

Reputation: 1809

By default, the full text search will search array('SiteTree', 'File')

http://api.silverstripe.org/en/3.1/class-FulltextSearchable.html

I would try changing your FulltextSearchable::enable(); line to FulltextSearchable::enable(array('SiteTree'));

I haven't tried this before and am not sure if it will work.

Upvotes: 2

Related Questions