heimrichhannot/contao-search-bundle

此插件包含Contao搜索的增强功能。

安装: 751

依赖: 0

建议者: 0

安全: 0

星级: 0

观察者: 7

分支: 3

开放问题: 1

类型:contao-bundle

3.0.0 2024-02-20 16:03 UTC

This package is auto-updated.

Last update: 2024-09-20 17:23:08 UTC


README

此插件包含Contao搜索的增强功能。您可以选择启用或禁用所有功能,以便仅获取所需的功能。

特性

  • PDF搜索
  • 设置最大搜索词数
  • 搜索模块的页面过滤器
  • 相关搜索内容元素
  • 记录搜索词

用法

安装

  1. 安装composer插件: composer require heimrichhannot/contao-search-bundle
  2. 可选: 安装guzzle HTTP客户端: composer require guzzlehttp/guzzle(重建搜索索引命令需要)
  3. 可选: 安装Smalot PdfParser: "smalot/pdfparser": "^2.3"(PDF搜索需要,最低支持版本为0.18.2)
  4. 在项目配置中启用/禁用您需要的功能(请参阅配置章节)并清除缓存
  5. 更新数据库

最大搜索词数

  1. 请确保 huh_search.disable_max_keyword_filter 设置为 false(默认为 false)

  2. 将关键词数量设置为一个大于0的值以启用

    Search engine module max keyword input

  3. 如果您想输出超过最大关键词数量的用户通知,请选择 mod_search_searchbundle 模块模板或在您喜欢的位置输出 $this->maxKeywordsExceededMessage 模板变量。

  4. 如果您需要支持德语等特殊字母的语言,您可以将额外的字符传递给 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; ?>
  1. 如果您想自定义消息,请覆盖 huh_search.module.max_keywords_exceeded_message 的翻译键(使用Symfony翻译)。%count%(提供的关键词数量)和%max%(允许的最大关键词数量)作为占位符值提供。

按页面过滤搜索结果

  1. 在您的配置中启用 huh_search.enable_search_filter(默认启用)

  2. 创建或编辑您的搜索引擎模块,并根据您的喜好设置搜索过滤器部分

    Search engine module filter section

相关搜索内容元素

此元素基本上是内容超链接元素(也使用相同的模板),但它保留搜索参数。它专为与新闻过滤器一起使用而设计,以便链接到具有不同过滤器配置的另一个搜索模块。

  1. 在带有搜索模块的页面上创建一个相关搜索链接内容元素
  2. 将另一个带有搜索模块的页面设置为目标

搜索关键词日志

要记录搜索关键词,只需将 huh_search.enable_search_log 设置为 true。之后您将在日志文件夹中找到 huh_search_log-文件,其中包含日期时间格式的csv列表和关键词。最多存储7天(您可以通过自定义huh_search_log通道的monolog设置来更改此时间段)。

PDF搜索

要为Contao搜索启用PDF索引,需要以下步骤

  1. 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
  2. "smalot/pdfparser": "^0.18" 添加为composer依赖

  3. 重建搜索索引

有关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 赞助。