zinc/neos-search

该软件包最新版本(0.0.1)没有可用的许可证信息。

安装: 10

依赖关系: 0

建议者: 0

安全: 0

星星: 4

关注者: 1

分支: 3

开放问题: 1

类型:neos-package

0.0.1 2024-01-11 19:20 UTC

This package is auto-updated.

Last update: 2024-09-11 20:52:48 UTC


README

Neos CMS 提供轻量级全文和术语搜索。

项目目标

  • 易于设置
  • 硬件要求最小
  • 启用专业功能,如快速服务器端 Node-Querying 以“经济”的方式

快速入门

启动 Zinc 搜索索引

Zinc 文档

# DDEV config in .ddev/docker-compose.zincsearch.yaml:
version: '3.6'
services:
  zincsearch:
    container_name: ddev-${DDEV_SITENAME}-zincsearch
    hostname: ${DDEV_SITENAME}-zincsearch
    image: public.ecr.aws/zinclabs/zincsearch:0.4.9
    expose:
      - "4080"
    ports:
      - "4080"
    environment:
      - ZINC_FIRST_ADMIN_USER=admin
      - ZINC_FIRST_ADMIN_PASSWORD=Complexpass#123
      - ZINC_DATA_PATH=/usr/share/zincsearch/data
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT
    volumes:
      - ./zinc:/usr/share/zincsearch
      - ".:/mnt/ddev_config"

volumes:
  zincsearch:

安装和配置 Zinc.NeosSearch

composer require zinc/neos-search

Settings.Zinc.yaml

Zinc:
  NeosSearch:
    hostname: 'ddev-YOUR_DDEV_SITENAME-zincsearch'

配置节点类型

如何索引节点类型属性

Neos.Neos:Document:
  properties:
    title:
      search:
        zinc:
          mappingType: 'text'
          indexingValue: ${node.properties.title}
          fulltextValue: ${node.properties.title}

'Neos.Demo:Content.Text':
  properties:
    text:
      search:
        zinc:
          mappingType: 'text'
          fulltextValue: ${node.properties.text}

'Neos.NodeTypes.Navigation:Navigation':
  properties:
    selection:
      search:
        zinc:
          mappingType: 'keyword'
          indexingValue: ${value}

'Neos.Neos:Node':
  properties:
    '_creationDateTime':
      search:
        zinc:
          mappingType: 'date'
          indexingValue: ${value}

// ...

索引数据

./flow zinc:index

启用全文内容节点类型

'Zinc.NeosSearch:Content.Search':
  abstract: false

或创建服务器端查询.

现在搜索应该可以工作 🎉

常见问题/如何做

如何索引节点类型属性

每个属性都可以通过以下方式手动配置

Vendor:NodeType:
  properties:
    aPropertyName:
      search:
        zinc: []

可用选项

# If configured, this type is used for the field:
mappingType: 'text', 'bool', 'keyword' or 'date'

# If configured, this value is added to the index:
indexingValue: ${value}
or specific..
indexingValue: ${node.properties.aPropertyName}

# If Configured, this value is added to the closest document fulltext field:
indexingValue: ${value}
or specific..
fulltextValue: ${node.properties.aPropertyName}

启用队列索引器

Settings.Zinc.yaml

Zinc:
  NeosSearch:
    realtimeIndexing:
      enabled: true
      queue: true

# You can enable realtimeIndexing without queue.. but this has a performance impact while publishing content!

创建队列一次...

./flow queue:setup zincBatchIndexer

定期填充队列...

./flow zinc:index --queue

持续处理队列...

./flow job:work zincBatchIndexer

# If you need to run the job via cronjob,
you can keep the job worker running once with flock:
*/5 * * * * /usr/bin/flock --nonblock --no-fork /tmp/Flow/job-queue-worker-zincBatchIndexer.lockfile -c 'FLOW_CONTEXT=Production /home/www-data/project.com/releases/current/flow job:work --queue zincBatchIndexer --exit-after 1800'

查询构建器原型

示例

zincQueryObject = afx`
  <Zinc.NeosSearch:Query>
    <Zinc.NeosSearch:Query.Must>
      <Zinc.NeosSearch:Query.Term property="identifier" term="e9ffe2fe-e6d7-7025-50f1-6ecf2fa353c5" />
    </Zinc.NeosSearch:Query.Must>
  </Zinc.NeosSearch:Query>
`

可用原型

  • Zinc.NeosSearch:Query,必需
    • 默认属性
      • from = 0
      • size = 10
      • page = 0(替换 from
      • sort = null(例如 [{'properties__creationDateTime': 'desc'}]
      • stringify = false
  • Zinc.NeosSearch:Query.Should
    • 期望一个或多个嵌套原型
  • Zinc.NeosSearch:Query.Must
    • 期望一个或多个嵌套原型
  • Zinc.NeosSearch:Query.MustNot
    • 期望一个或多个嵌套原型
  • Zinc.NeosSearch:Query.Match
    • 默认属性
      • field = null
      • property = null(替换 field
      • query = null
      • fuzziness = 'AUTO'
      • boost = null
  • Zinc.NeosSearch:Query.Prefix
    • 默认属性
      • field = null
      • term = null
  • Zinc.NeosSearch:Query.Term
    • 默认属性
      • field = null
      • term = null
  • Zinc.NeosSearch:Query.Terms
    • 默认属性
      • field = null
      • terms = null

执行搜索查询

获取节点

result = ${ZincSearch.nodes(site, this.queryBuilder)} # does return an array of nodes
#    Array (
#        ... NodeInterfase items

获取原始结果

result = ${ZincSearch.raw(site, this.queryBuilder)}
#    [hits] => Array (
#            [total] => Array (
#                    [value] => 4
#                    [pages] => 1
#                )
#            [max_score] => 6.8515092967801
#            [hits] => Array (
#                ... raw search result items