承接 mustasj/expanded-search 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mustasj/expanded-search

最新稳定版本:1.3.7

Composer 安装命令:

composer require mustasj/expanded-search

包简介

An expansion of Crafts search

README 文档

README

Ported https://github.com/composedcreative/craft-expandedsearch from Craft 2 to Craft 3. Is is an expansion of Crafts search, which gives you a context for search hits.

Screenshot

Requirements

This plugin requires Craft CMS 3.1.0 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

    cd /path/to/project
    
  2. Then tell Composer to load the plugin:

    composer require mustasj/expanded-search
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Expanded Search.

Using Expanded Search

The first parameter is the search term. Which will be salted automatically: *{term}* The second is settings.

Setting Type Purpose Default
length int Cuts off the search value at given length 300
section array/string section names to search in null (all sections)
sectionId array/int id of sections to search in null (all sections)
limit int how many results to return (pagination) 0 (all)
offset int how many results to skip (pagination) 0
subLeft bool to use fuzzy search left true
subRight bool to use fuzzy search right true

In your search results template

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

Expanded Search from Element API

To use the plugin from ElementAPI. Do a normal search and then for each result, you can fetch the ExpandedSearchModel from the service

'transformer' => function(Entry $entry) {
    $searchResults = ExpandedSearch::$plugin->expandedSearchService->expandSearchResults($entry, $query, $length);
    return [
        'id' => $entry->title,
        'title' => $entry->title,
        'matchedValue' => $searchResult->matchedValue,
        'matchedField' => $searchResult->matchedField
    ];
},

Expanded Search Roadmap

Some things to do, and ideas for potential features:

  • Release it
  • Add proper pagination within the plugin
  • Add handling for more fields

统计信息

  • 总下载量: 16.56k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-12