【问题标题】:SilverStripe (3.6.2) Search returning assets folder contentsSilverStripe (3.6.2) 搜索返回的资产文件夹内容
【发布时间】:2017-11-02 14:22:44
【问题描述】:

我之前没有在 SilverStripe 上启用搜索,但它看起来很简单。我已经按照启用搜索的其他 2 个项目(尽管它们是 3.5 版本项目,但不确定是否有所不同)以及 SilverStripe 网站上提供的教程的步骤进行操作,出于某种原因,我得到了资产我的搜索结果中的文件夹项目(即图像)。只有当我点击搜索并且没有在搜索字段中输入任何内容时才会出现这种情况。

在任何时候都不应该返回任何资产项进行搜索,如果没有搜索查询,那么应该有一条消息说什么都没有输入或什么的。我注意到使用基本安装提供的默认 $SearchForm 设置给了我想要的结果,但不适用于我正在使用的表单(它在其他 2 个 SilverStripe 站点上工作——我检查并确认了)。

我不确定我错过了什么?我觉得一切都做得正确,我想使用我现在拥有的设置来给我更多的造型能力:

来自_config.php:

FulltextSearchable::enable();

来自我的 Header.ss 文件:

 <!-- 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>

搜索结果页面:

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

【问题讨论】:

    标签: search silverstripe


    【解决方案1】:

    默认全文搜索会搜索array('SiteTree', 'File')

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

    我会尝试将您的 FulltextSearchable::enable(); 行更改为 FulltextSearchable::enable(array('SiteTree'));

    我以前没有尝试过,不确定它是否会起作用。

    【讨论】:

    • 啊,好的。我试了一下,它似乎成功了。谢谢!
    猜你喜欢
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多