如何将两个分析器包含到单个 SEARCH 语句中?
How to include two analyzers into a single SEARCH statement?
我有一个 feeds
collection 文件是这样的:
{
"created": 1510000000,
"find": [
"title of the document",
"body of the document"
],
"filter": [
"/example.com",
"-en"
]
}
created
包含纪元时间戳
find
包含一组全文片段,例如文本的标题和 body
filter
是一个包含更多搜索标记的数组,例如主题标签、域、语言环境
问题是 find
包含我们想要标记化的全文片段,例如使用 text
分析器,但 filter
包含我们想要作为一个整体进行比较的最终标记,例如使用 identity
分析器。
目标是将 find
和 filter
组合成一个自定义分析器,或者使用两个 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
是一个数组,但我似乎无法为每个分析器设置单独的字段。
分析器可以作为 属性 添加到 fields
中的每个字段。 analyzers
中指定的是默认值,用于在未为给定字段设置更具体的分析器的情况下使用。
"analyzers": [
"identity"
],
"fields": {
"find": {
"analyzers": [
"text_en"
]
},
"filter": {},
"created": {}
},
致谢:ArangoDB 的 Simran
我有一个 feeds
collection 文件是这样的:
{
"created": 1510000000,
"find": [
"title of the document",
"body of the document"
],
"filter": [
"/example.com",
"-en"
]
}
created
包含纪元时间戳find
包含一组全文片段,例如文本的标题和 bodyfilter
是一个包含更多搜索标记的数组,例如主题标签、域、语言环境
问题是 find
包含我们想要标记化的全文片段,例如使用 text
分析器,但 filter
包含我们想要作为一个整体进行比较的最终标记,例如使用 identity
分析器。
目标是将 find
和 filter
组合成一个自定义分析器,或者使用两个 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
是一个数组,但我似乎无法为每个分析器设置单独的字段。
分析器可以作为 属性 添加到 fields
中的每个字段。 analyzers
中指定的是默认值,用于在未为给定字段设置更具体的分析器的情况下使用。
"analyzers": [
"identity"
],
"fields": {
"find": {
"analyzers": [
"text_en"
]
},
"filter": {},
"created": {}
},
致谢:ArangoDB 的 Simran