csoellinger / silverstripe-ps-search
Silverstripe网站的搜索引擎 - 由plasticstudio/search分支而来,该分支又来自jaedb/search
1.1.2
2023-03-23 10:58 UTC
Requires
This package is auto-updated.
Last update: 2024-09-23 14:23:42 UTC
README
!!! 注意:这是一个从 https://github.com/PlasticStudio/Search 分支而来的版本,并且仅存在直到有拉取请求被接受。如果它们不被接受,此插件将尝试保持与现有分支相同的功能。与分支的区别是一些配置功能,如include_css或include_js或扩展的JoinTables。如果拉取请求被合并,我将删除此存储库,您应该回到 https://github.com/PlasticStudio/Search。
Silverstripe内置的搜索表单是一个非常简单的搜索引擎。此插件将基于SQL的搜索提升到下一个层次,无需实现如Solr或Elastic Search这样的完整搜索引擎。它旨在在简单的文本搜索功能之上提供面向数据的筛选。
要求
- SilverStripe 4
使用方法
- 创建一个
SearchPage
实例(通常位于您网站的根目录)。此页面仅用于显示结果,因此请避免创建多个实例。 - 配置您网站的
_config/config.yml
(或添加_config/search.yml
)以定义搜索参数。 - 运行
dev/build
以实例化新配置(这将自动创建一个SearchPage
实例,如果尚不存在的话)。 - 要覆盖默认的
SearchPage
模板,请将模板文件添加到您的应用程序中:templates/PlasticStudio/Search/Layout/SearchPage.ss
Elemental
- 包含Elemental搜索
- 在页面或Element保存时,所有Element的内容都保存到sitetree上的名为
ElementalSearchContent
的字段。 - 只需将
'SiteTree_Live.ElementalSearchContent'
添加到页面列列表中即可。 - 目前还没有方法可以排除个别元素不被包含。
- 运行IndexPageContentForSearchTask以索引元素内容
配置
include_css
:包含搜索默认样式(true
/false
)include_js
:包含搜索默认脚本(true
/false
)types
:要搜索的类型关联列表Label
:前端字段标签Table
:对象的默认表(注意版本化对象的_Live
后缀)ClassName
:完整的ClassNameClassNameShort
:命名空间化的ClassNameJoinTables
:连接表。(格式JoinTable
或JoinTable.Column
或JoinTable.Column: JoinTableOn.Column
或JoinTable: [JoinTableFrom.Column: JoinTableOn.Column]
。下面有示例)Filters
:应用搜索前的筛选器列表Columns
:用于查询字符串匹配的列(格式Table.Column
)
filters
:筛选器选项关联列表Structure
:定义筛选器的关联结构(必须是db
、has_one
或many_many
之一)Label
:前端字段标签Table
:关联主题的表Column
:筛选的列Operator
:SQL筛选器运算符(例如>
、<
、=
)JoinTables
:关系映射的关联列表(使用types
数组中的key
)Table
:关联连接表Column
:连接的列
sorts
:排序选项的关联列表。这些用于在高级搜索表单中填充“按此排序”下拉字段。搜索结果的排序顺序将默认为此列表中的第一项。Label
:前端字段标签Sort
:SQL排序字符串
submit_button_text
:搜索表单提交按钮上使用的文本(默认为“搜索”)
待办事项:defaults
:默认属性或设置,与通过搜索表单提交的属性或设置相对。
示例配置
--- Name: search Before: - '#site' --- PlasticStudio\Search\SearchPageController: include_css: true include_js: true 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 # Or for most flexibility: (does the same like above) # File_Live.ClassName: # Operator: '=' # Value: '''Silverstripe\\Assets\\File''' # For images too.. # File_Live.ClassName: ['''Silverstripe\\Assets\\File''', '''Silverstripe\\Assets\\Image'''] 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'] # Another possible syntax (same result like above): # JoinTables: ['SiteTree_Live.ID'] # Another possible syntax (same result like above): # JoinTables: # - "SiteTree_Live.ID": "Page.ID" # Another possible syntax (same result like above): # JoinTables: # - "SiteTree_Live": # - "SiteTree_Live.ID": "Page.ID" 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' submit_button_text: 'Go' ## TODO: ## defaults: ## sort: 'Title ASC'