为什么 CloudSearch 无法在文件名文本字段中找到子字符串匹配项?
Why won't CloudSearch find substring matches in filename text field?
我有一个带有 filename
文本字段的 CloudSearch 域。我的问题是文本查询不会匹配(某些)具有我认为(逻辑上)应该的文件名的文档。如果我有这些文件名的文档:
- 'cars'
- 'Cars Movie.jpg'
- 'cars.pdf'
- 'cars#.jpg'
我执行了 'cars' 的简单文本查询,我得到了文件 #1、#2 和 #4,但 不是 #3。如果我搜索 'cars*'(或使用前缀进行结构化查询),我可以匹配 #3。这对我来说没有意义,尤其是 #4 匹配但 #3 不匹配。
TL;DR 这是因为标记化算法处理句点的方式。
当您执行文本搜索时,您是在针对已处理的数据而不是文字字段执行搜索。 (也许这应该是显而易见的,但我之前并不是这样想的。)
documentation 概述了文本的处理方式:
During indexing, Amazon CloudSearch processes text and text-array fields according to the analysis scheme configured for the field to determine what terms to add to the index. Before the analysis options are applied, the text is tokenized and normalized.
最终导致此行为的过程部分是标记化:
During tokenization, the stream of text in a field is split into separate tokens on detectable boundaries using the word break rules defined in the Unicode Text Segmentation algorithm.
According to the word break rules, strings separated by whitespace such as spaces and tabs are treated as separate tokens. In many cases, punctuation is dropped and treated as whitespace. For example, strings are split at hyphens (-) and the at symbol (@). However, periods that are not followed by whitespace are considered part of the token.
我看到问题中描述的匹配项的原因是因为文件扩展名作为单个标记包含在它们之前的任何内容中。如果我们回顾这个例子,并根据这些规则建立索引,那么搜索 'cars' returns 文档 #1、#2 和 #4 而不是 #3 是有道理的。
# Text Index
1 'cars' ['cars']
2 'Cars Movie.jpg' ['cars', 'movie.jpg']
3 'cars.pdf'. ['cars.pdf']
4 'cars#.jpg' ['cars', '.jpg']
可能的解决方案
似乎设置自定义分析方案可以解决此问题,但 none 中的选项(停用词、词干提取、同义词)可帮助您克服标记化问题。我认为要获得所需的行为,唯一可能的解决方案是在上传之前标记文件名(使用自定义算法),然后将标记存储在文本数组字段中。虽然设计一个支持多种语言的自定义标记化算法是一个大问题。
我有一个带有 filename
文本字段的 CloudSearch 域。我的问题是文本查询不会匹配(某些)具有我认为(逻辑上)应该的文件名的文档。如果我有这些文件名的文档:
- 'cars'
- 'Cars Movie.jpg'
- 'cars.pdf'
- 'cars#.jpg'
我执行了 'cars' 的简单文本查询,我得到了文件 #1、#2 和 #4,但 不是 #3。如果我搜索 'cars*'(或使用前缀进行结构化查询),我可以匹配 #3。这对我来说没有意义,尤其是 #4 匹配但 #3 不匹配。
TL;DR 这是因为标记化算法处理句点的方式。
当您执行文本搜索时,您是在针对已处理的数据而不是文字字段执行搜索。 (也许这应该是显而易见的,但我之前并不是这样想的。)
documentation 概述了文本的处理方式:
During indexing, Amazon CloudSearch processes text and text-array fields according to the analysis scheme configured for the field to determine what terms to add to the index. Before the analysis options are applied, the text is tokenized and normalized.
最终导致此行为的过程部分是标记化:
During tokenization, the stream of text in a field is split into separate tokens on detectable boundaries using the word break rules defined in the Unicode Text Segmentation algorithm.
According to the word break rules, strings separated by whitespace such as spaces and tabs are treated as separate tokens. In many cases, punctuation is dropped and treated as whitespace. For example, strings are split at hyphens (-) and the at symbol (@). However, periods that are not followed by whitespace are considered part of the token.
我看到问题中描述的匹配项的原因是因为文件扩展名作为单个标记包含在它们之前的任何内容中。如果我们回顾这个例子,并根据这些规则建立索引,那么搜索 'cars' returns 文档 #1、#2 和 #4 而不是 #3 是有道理的。
# Text Index
1 'cars' ['cars']
2 'Cars Movie.jpg' ['cars', 'movie.jpg']
3 'cars.pdf'. ['cars.pdf']
4 'cars#.jpg' ['cars', '.jpg']
可能的解决方案
似乎设置自定义分析方案可以解决此问题,但 none 中的选项(停用词、词干提取、同义词)可帮助您克服标记化问题。我认为要获得所需的行为,唯一可能的解决方案是在上传之前标记文件名(使用自定义算法),然后将标记存储在文本数组字段中。虽然设计一个支持多种语言的自定义标记化算法是一个大问题。