stw-on/craft-extended-search

为元素搜索检索更多上下文

4.0.0 2024-09-17 08:02 UTC

This package is auto-updated.

Last update: 2024-09-17 08:03:02 UTC


README

该存储库是 https://github.com/mustasj-as/expanded-search 的分支,它是从 Craft 2 转移到 Craft 3 的 https://github.com/composedcreative/craft-expandedsearch。它扩展了 Craft 的搜索功能,为您提供了搜索结果的上下文。

要求

此插件需要 Craft CMS 3.1.0 或更高版本。

安装

要安装此插件,请按照以下说明操作。

  1. 打开您的终端并进入您的 Craft 项目

    cd /path/to/project
    
  2. 然后告诉 Composer 加载插件

    composer require stw-on/craft-extended-search
    
  3. 在控制面板中,转到设置 → 插件,然后点击“安装”按钮以安装扩展搜索。

使用扩展搜索

第一个参数是搜索词。将自动进行盐化:*{term}* 第二个是设置。

在您的搜索结果模板中

{% set results = craft.extendedSearch.search(query, { sections: ['news'], length: 150 }) %}
{% for result in results %}
    <strong data-field="{{ result.matchedField }}">{{ result.entry.title }}</strong><br>
    <p>{{result.matchedValue}}</p>
    <a href="{{ result.element.url }}">{{ result.element.url }}</a>
{% else %}
    <p>Sorry, no results for {{ query }}.</p>
{% endfor %}