- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
关于 EdgeNgram 如何处理数字有什么想法吗?
我正在使用 ElasticSearch 后端运行 haystack。我创建了一个 EdgeNgram 类型的索引字段。该字段将包含一个字符串,该字符串可能包含单词和数字。
当我使用部分词对该字段运行搜索时,它按预期运行。但是,如果我输入部分数字,我得不到我想要的结果。
例子:
我通过键入“edgen”搜索索引字段“EdgeNgram 12323”,然后我会得到返回给我的索引。如果我通过键入“123”来搜索相同的索引,我什么也得不到。
想法?
最佳答案
我在这里找到了解决 Haystack + Elasticsearch 中同样问题的方法。根据 uboness 和 ComoWhat 的提示,我编写了一个备用的 Haystack 引擎(我相信)它使 EdgeNGram 字段像对待单词一样对待数字字符串。其他人可能会受益,所以我想我会分享它。
from haystack.backends.elasticsearch_backend import ElasticsearchSearchEngine, ElasticsearchSearchBackend
class CustomElasticsearchBackend(ElasticsearchSearchBackend):
"""
The default ElasticsearchSearchBackend settings don't tokenize strings of digits the same way as words, so emplids
get lost: the lowercase tokenizer is the culprit. Switching to the standard tokenizer and doing the case-
insensitivity in the filter seems to do the job.
"""
def __init__(self, connection_alias, **connection_options):
# see http://stackoverflow.com/questions/13636419/elasticsearch-edgengrams-and-numbers
self.DEFAULT_SETTINGS['settings']['analysis']['analyzer']['edgengram_analyzer']['tokenizer'] = 'standard'
self.DEFAULT_SETTINGS['settings']['analysis']['analyzer']['edgengram_analyzer']['filter'].append('lowercase')
super(CustomElasticsearchBackend, self).__init__(connection_alias, **connection_options)
class CustomElasticsearchSearchEngine(ElasticsearchSearchEngine):
backend = CustomElasticsearchBackend
关于python - ElasticSearch:EdgeNgrams 和数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13636419/
我正在尝试为索引设置一个新的映射。它将支持由 ES 提供支持的部分关键字搜索和自动完成请求。 带有空白标记器的 edgeNGram 标记过滤器似乎是一种可行的方法。到目前为止,我的设置看起来像这样:
当我在一个字段上搜索时,评分似乎没有考虑字段的长度(即文本较长的文档与较短的文档的评分相同,并且出于某种原因放在前面)。不确定我做错了什么。 字段索引如下: "name": { "ty
我有大约一百万条记录的 Elasticsearch 索引。 我想对 Elasticsearch 索引中的2个字段,名称和ID(总共约10个)进行多前缀搜索。 创建EdgeNGram自动完成过滤器是否有
关于 EdgeNgram 如何处理数字有什么想法吗? 我正在使用 ElasticSearch 后端运行 haystack。我创建了一个 EdgeNgram 类型的索引字段。该字段将包含一个字符串,该字
我最近一直在尝试使用 Django Haystack (v2.1.0) 和 Elasticsearch (v0.90.5) 作为我的搜索引擎在我的网络应用程序上实现全文搜索。我的目标是能够通过一个查询
我正在尝试制作 部分搜索 工作,寻找 “sw” “瑞典” “瑞典” 应该匹配“瑞典” 我环顾四周,就是无法让它工作 Rails Code 我正在使用 this code从轮胎 repo 作为模板代码。
我们有一个符合 OData 的 API,可以将部分全文搜索需求委托(delegate)给 Elasticsearch 集群。 由于 OData 表达式可能变得非常复杂,因此我们决定将它们简单地转换为等
当我使用带有 edgengram (min=3, max=7, front) + term_vector=with_positions_offsets 的分析器时 文档有 text = "CouchD
我有一个大约 40k 行的数据集,每行有 4 个字段。现在我想对文本框中的这 4 个字段使用自动完成机制(在显示建议之前必须将这 4 个字段中的值连接成一个字符串)。哪种查询会更好地扩展和执行?在 E
我有一个大约 40k 行的数据集,每行有 4 个字段。现在我想对文本框中的这 4 个字段使用自动完成机制(在显示建议之前必须将这 4 个字段中的值连接成一个字符串)。哪种查询会更好地扩展和执行?在 E
假设我有 5 部电影片名: 无太阳 珊莎 这也是 Solr 古德 唯一幸存者 我想实现一个具有这种预期行为的自动完成搜索字段: “Sans”> Sans Soleil,Sansa “Sans so”
我有三个带有“用户名”字段的文档: '布里安迪利' 'briangumble' 'briangriffen' 当我搜索“brian”时,我按预期得到了所有三个,但是当我搜索“briandilley”时
编辑 3 :我现在使用的解决方法是从我的查询和索引字段中去除除字母、数字和空格以外的任何内容。这会产生所需的行为,但它在很大程度上是一种解决方法而不是真正的解决方案,而且我仍然想了解 Solr 为什么
我是一名优秀的程序员,十分优秀!