gpt4 book ai didi

solr - 包含多个单词的elasticsearch短语频率.tf()

转载 作者:行者123 更新时间:2023-12-03 02:05:43 26 4
gpt4 key购买 nike

我想访问由多个单词组合而成的短语的频率
例如“绿色能源”

我可以访问“绿色”和“能源”的TF,例如:

"function_score":
{
"filter" : {
"terms" : { "content" : ["energy","green"]}
},
"script_score": {
"script": "_index['content']['energy'].tf() + _index['content']['green'].tf()",
"lang":"groovy"
}
}

这很好。但是,我怎样才能找到“绿色能源”一词的频率
_index['content']['green energy'].tf() 

不起作用

最佳答案

我认为这取决于您如何索引数据以及搜索时有什么要求。例如,如果您有“可以节省的间接绿色能源”(意味着“绿色”和“能源”彼此接近),并且希望脚本与“绿色能源”“匹配”并给您一个tf( )评估,那么您需要相应地索引数据。就像您说的那样-“绿色能源”一词的频率归结为产生该术语“绿色能源”。

在您的情况下,一个想法是对"content"使用另一个字段,但使用"shingles"分析器:

PUT /some_index
{
"settings": {
"analysis": {
"filter": {
"my_shingle_filter": {
"type": "shingle",
"min_shingle_size": 2,
"max_shingle_size": 2,
"output_unigrams": false
}
},
"analyzer": {
"my_shingle_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"my_shingle_filter"
]
}
}
}
},
"mappings": {
"some_type": {
"properties": {
"content": {
"type": "string",
"index": "analyzed",
"fields": {
"with_shingles": {
"type": "string",
"analyzer": "my_shingle_analyzer"
}
}
}
}
}
}
}

在功能评分中,您将引用 .with_shingles字段:
{
"query": {
"function_score": {
"filter": {
"terms": {
"content": [
"energy",
"green"
]
}
},
"script_score": {
"script": "_index['content.with_shingles']['green energy'].tf()",
"lang": "groovy"
}
}
}
}

这只是一个示例,证明您需要相应地索引数据,以便获得所需的 .tf()。在我的示例中,我假设您要搜索确切的术语“绿色能源”,因此我使用了“带状疱疹”,对于上面的示例来说,该文本会生成如下分析的术语列表: "content.with_shingles": ["energy to","green energy","indirect green","to spare"]

关于solr - 包含多个单词的elasticsearch短语频率.tf(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26604313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com