首页 > 解决方案 > 如何将两个分析器包含到单个 SEARCH 语句中?

问题描述

我有一个feeds包含这样的文档的集合:

{
  "created": 1510000000,
  "find": [
    "title of the document",
    "body of the document"
  ],
  "filter": [
    "/example.com",
    "-en"
  ]
}

问题是它find包含全文片段,我们想要对其进行标记,例如使用text分析器,但filter包含我们想要作为一个整体比较的最终标记,例如使用identity分析器。

目标是合并findfilter一个自定义分析器中,或者使用两个 SEARCH 语句或其他东西来合并两个分析器。

我确实设法通过其中一个find或通过filter成功进行查询,但没有设法通过两者进行查询。这就是我查询的方式filter

我创建了一个feeds_search视图:

{
  "writebufferIdle": 64,
  "type": "arangosearch",
  "links": {
    "feeds": {
      "analyzers": [
        "identity"
      ],
      "fields": {
        "find": {},
        "filter": {},
        "created": {}
      },
      "includeAllFields": false,
      "storeValues": "none",
      "trackListPositions": false
    }
  },
  "consolidationIntervalMsec": 10000,
  "writebufferActive": 0,
  "primarySort": [],
  "writebufferSizeMax": 33554432,
  "consolidationPolicy": {
    "type": "tier",
    "segmentsBytesFloor": 2097152,
    "segmentsBytesMax": 5368709120,
    "segmentsMax": 10,
    "segmentsMin": 1,
    "minScore": 0
  },
  "cleanupIntervalStep": 2,
  "commitIntervalMsec": 1000,
  "id": "362444",
  "globallyUniqueId": "hD6FBD6EE239C/362444"
}

我创建了一个示例查询:

FOR feed IN feeds_search
SEARCH ANALYZER(feed.created < 9990000000 AND feed.created > 1500000000 
AND (feed.find == "title of the document")
AND (feed.`filter` == "/example.com" OR feed.`filter` == "-uk"), "identity")
SORT feed.created
LIMIT 20
RETURN feed

示例查询有效,因为find包含全文(identity分析器)。一旦我切换到text分析器,单个单词标记就适用于find,但filter不再适用。

我尝试使用 SEARCH 和 FILTER 的组合,这给了我想要的结果,但我认为它的性能可能比让 SEARCH 分析器完成整个事情要差。我看到这analyzers是视图语法中的一个数组,但我似乎无法为每个分析器设置单独的字段。

标签: arangodb

解决方案


分析器可以作为属性添加到fields. 中指定的analyzers是默认值,用于未为给定字段设置更具体的分析器的情况。

      "analyzers": [
        "identity"
      ],
      "fields": {
        "find": {
          "analyzers": [
            "text_en"
          ]
        },
        "filter": {},
        "created": {}
      },

致谢:ArangoDB 的 Simran


推荐阅读