heimrichhannot / contao-search-bundle
此插件包含Contao搜索的增强功能。
Requires
- php: ^8.0
- contao/core-bundle: ^4.13 || ^5.0
- heimrichhannot/contao-utils-bundle: ^2.134 || ^3.0
- symfony/config: ^5.4 || ^6.0
- symfony/console: ^5.4 || ^6.0
- symfony/deprecation-contracts: ^1.0 || ^2.0 || ^3.0
- symfony/event-dispatcher-contracts: ^1.0 || ^2.0 || ^3.0
- symfony/http-kernel: ^5.4 || ^6.0
- symfony/polyfill-php80: ^v1.27.0
- symfony/translation-contracts: ^1.0 || ^2.0 || ^3.0
Suggests
- smalot/pdfparser: Needed for pdf parsing. Minimum version 0.18.2.
Conflicts
- smalot/pdfparser: <0.18.2
README
此插件包含Contao搜索的增强功能。您可以选择启用或禁用所有功能,以便仅获取所需的功能。
特性
- PDF搜索
- 设置最大搜索词数
- 搜索模块的页面过滤器
- 相关搜索内容元素
- 记录搜索词
用法
安装
- 安装composer插件:
composer require heimrichhannot/contao-search-bundle
- 可选: 安装guzzle HTTP客户端:
composer require guzzlehttp/guzzle
(重建搜索索引命令需要) - 可选: 安装Smalot PdfParser:
"smalot/pdfparser": "^2.3"
(PDF搜索需要,最低支持版本为0.18.2) - 在项目配置中启用/禁用您需要的功能(请参阅配置章节)并清除缓存
- 更新数据库
最大搜索词数
-
请确保
huh_search.disable_max_keyword_filter
设置为 false(默认为 false) -
将关键词数量设置为一个大于0的值以启用
-
如果您想输出超过最大关键词数量的用户通知,请选择
mod_search_searchbundle
模块模板或在您喜欢的位置输出$this->maxKeywordsExceededMessage
模板变量。 -
如果您需要支持德语等特殊字母的语言,您可以将额外的字符传递给
huh_search.valid_word_chars
选项以获得正确的单词计数。默认情况下,德语的重音符号和eszett已经预配置。请注意,通过设置此选项,您将覆盖默认值(因此如果您想支持它们,您需要在您的配置中添加它们)。
示例
// mod_search.html5 <?php if ($this->maxKeywordsExceededMessage): ?> <p class="header"><?= $this->maxKeywordsExceededMessage ?></p> <?php endif; ?> <?php if ($this->header): ?> <p class="header"><?= $this->header ?> (<?= $this->duration ?>)</p> <?php endif; ?>
- 如果您想自定义消息,请覆盖
huh_search.module.max_keywords_exceeded_message
的翻译键(使用Symfony翻译)。%count%
(提供的关键词数量)和%max%
(允许的最大关键词数量)作为占位符值提供。
按页面过滤搜索结果
相关搜索内容元素
此元素基本上是内容超链接元素(也使用相同的模板),但它保留搜索参数。它专为与新闻过滤器一起使用而设计,以便链接到具有不同过滤器配置的另一个搜索模块。
- 在带有搜索模块的页面上创建一个相关搜索链接内容元素
- 将另一个带有搜索模块的页面设置为目标
搜索关键词日志
要记录搜索关键词,只需将 huh_search.enable_search_log
设置为 true。之后您将在日志文件夹中找到 huh_search_log
-文件,其中包含日期时间格式的csv列表和关键词。最多存储7天(您可以通过自定义huh_search_log通道的monolog设置来更改此时间段)。
PDF搜索
要为Contao搜索启用PDF索引,需要以下步骤
-
将
huh_search.pdf_indexer.enabled
设置为 true# config/config.yml (Contao 4.9) or app/Resources/config.yml (Contao 4.4) huh_search: pdf_indexer: enabled: true
-
将
"smalot/pdfparser": "^0.18"
添加为composer依赖 -
重建搜索索引
有关PDF索引器的更多配置选项,请参阅配置参考。
配置
完整的配置参考
# Default configuration for extension with alias: "huh_search" huh_search: # Configure the pdf indexer. pdf_indexer: # Enable pdf indexing for search. enabled: false # Max characters to process and store from a pdf file. 0 means no limit. max_indexed_characters: 2000 # Maximum file size of a pdf that can be processed by the pdf parser to prevent memory overflow or process timeout. Specify in KiB. 0 means no limit. 1024KiB = 1MB. max_file_size: 8096 # Enable or disable search filter for search module enable_search_filter: true # Enable or disable max keyword filter for search module disable_max_keyword_filter: false # Enable a search keyword logging. enable_search_log: false # Set additional chars that should be not break a word (used for charlist parameter of str_word_count function). valid_word_chars: ÄäÖöÜüẞß
鸣谢
PDF搜索集成由 fanthomas communications 赞助。