定制 plasticstudio/search 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

plasticstudio/search

Composer 安装命令:

composer require plasticstudio/search

包简介

Search engine for Silverstripe websites - forked from jaedb/search

README 文档

README

The built-in SilverStripe search form is a very simple search engine. This plugin takes SQL-based searching to the next level, without requiring the implementation of a full-blown search engine like Solr or Elastic Search. It is designed to bring data-oriented filters on top of the simple text search functionality.

Requirements

  • Silverstripe 6
  • For Silverstripe 4/5 see 1.x

Usage

  • Create a SearchPage instance (typically at the root of your website). This page only is used to display results, so please refrain from creating multiple instances.
  • Configure your website's _config/config.yml (or add _config/search.yml) to define search parameters.
  • Run dev/build to instansiate your new configuration (this will also automatically create an instance of SearchPage if one does not exist).
  • To overwrite the default SearchPage tmeplate, add a template file to your application: templates/PlasticStudio/Search/Layout/SearchPage.ss

Upgrading from SS5 to SS6

Rename $SearchForm to $BasicSearchForm in page templates

Upgrading from jaedb/search

Ensure you review the search config and update it to match the example config in this repo. Key changes:

  1. Table: 'SiteTree_Live' -> Table: 'Page_Live'
  2. Add JoinTables: ['SiteTree_Live']

Elemental

  • Elemental search is included
  • On page or Element save, all content from all Elements is saved to a field called ElementalSearchContent on sitetree.
  • Simply include 'SiteTree_Live.ElementalSearchContent' to the list of page columns
  • Currently there is no way to exclude individual elements from being included.
  • Run IndexPageContentForSearchTask to index element content

Configuration

  • types: associative list of types to search
    • Label: front-end field label
    • Table: the object's primary table (note _Live suffix for versioned objects)
    • ClassName: full ClassName
    • ClassNameShort: namespaced ClassName
    • Filters: a list of filters to apply pre-search (maps to DataList->Filter(key => value))
    • Columns: columns to search for query string matches (format Table.Column)
  • filters: associative list of filter options
    • Structure: defines the filter's relational structure (must be one of db, has_one or many_many)
    • Label: front-end field label
    • Table: relational subject's table
    • Column: column to filter on
    • Operator: SQL filter operator (ie >, <, =)
    • JoinTables: associative list of relationship mappings (use the key from the types array)
      • Table: relational join table
      • Column: column to join by
  • sorts: associative list of sort options. These are used to popoulate a "Sort by" dropdown field in the Advanced Search Form. Sort order of search results will default to the top item in this list.
    • Label: front-end field label
    • Sort: SQL sort string
  • search_form_placeholder_text: Change search input field placeholder text (defaults to "Keywords")
  • submit_button_text: Text to use on search form submit button (defaults to "Search")

TODO: defaults: Default attributes or settings, as opposed to those submitted through the search form.

Indexing Dataobjects

The search checks canView permissions for Dataobjects before indexing, so you likely need to add:

    public function canView($member = null)
    {
        return true;
    }

Example configuration

---
Name: search
Before:
    - '#site'
---
PlasticStudio\Search\SearchPageController:
  types:
    docs:
      Label: 'Documents'
      Table: 'File_Live'
      ClassName: 'SilverStripe\Assets\File'
      ClassNameShort: 'File'
      Filters:
        File_Live.ShowInSearch: '1'
        File_Live.ClassName:  '''Silverstripe\\Assets\\File''' # You need to TRIPLE-ESCAPE in order to pass this as a string to the query
      Columns: ['File_Live.Title','File_Live.Description','File_Live.Name']
    pages:
      Label: 'Pages'
      ClassName: 'Page'
      ClassNameShort: 'Page'
      Table: 'Page_Live'
      Filters: 
        SiteTree_Live.ShowInSearch: '1'
      JoinTables: ['SiteTree_Live']
      Columns: ['SiteTree_Live.Title','SiteTree_Live.MenuTitle','SiteTree_Live.Content', 'SiteTree_Live.ElementalSearchContent']
  filters:
    updated_before:
      Structure: 'db'
      Label: 'Updated before'
      Column: 'LastEdited'
      Operator: '<'
    updated_after:
      Structure: 'db'
      Label: 'Updated after'
      Column: 'LastEdited'
      Operator: '>'
    tags:
      Structure: 'many_many'
      Label: 'Tags'
      ClassName: 'Tag'
      Table: 'Tag'
      JoinTables:
        docs: 
          Table: 'File_Tags'
          Column: 'FileID'
        pages: 
          Table: 'Page_Tags'
          Column: 'PageID'
      authors:
        Structure: 'many_many'
        Label: 'Authors'
        ClassName: 'Member'
        Table: 'Member'
        JoinTables:
          pages: 
            Table: 'Page_Authors'
            Column: 'PageID'
  sorts:
    title_asc:
      Label: 'Title (A-Z)'
      Sort: 'Title ASC'
    title_desc:
      Label: 'Title (Z-A)'
      Sort: 'Title DESC'
    published_asc:
      Label: 'Publish date (newest first)'
      Sort: 'DatePublished DESC'
    published_desc:
      Label: 'Publish date (oldest first)'
      Sort: 'DatePublished ASC'
  search_form_placeholder_text: 'Keywords'
  submit_button_text: 'Go'
  ## TODO:
  ## defaults:
    ## sort: 'Title ASC'

plasticstudio/search 适用场景与选型建议

plasticstudio/search 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.64k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 09 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「silverstripe」 「silverstripesearch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 plasticstudio/search 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 plasticstudio/search 我们能提供哪些服务?
定制开发 / 二次开发

基于 plasticstudio/search 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-09-07