termFreq 函数查询如何在 Apache Solr 中工作
How does termFreq function query work in Apache Solr
我正在尝试使用其 API、
查询 solr 索引
http://localhost:8983/solr/documents/select?defType=func&q=termfreq(contents,'hello)&wt=json
我已经为 3 个文档建立了索引,其中 2 个 documents/records 有术语 "hello" 但它 returns 所有文档。
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"termfreq(contents,'hello')",
"defType":"func",
"indent":"on",
"wt":["json",
"json"],
"_":"1538568705504"}},
"response":{"numFound":3,"start":0,"docs":[
{*here I have docs*}
]
}
我只期待包含单词 hello 及其在这些文档中出现的文档。
我说得对还是我没有正确理解这个函数?
您不能在 Solr 中使用类似的函数。要仅检索出现术语 hello
的文档,并将计数作为分数,请使用:
q=content:hello _val_:"termfreq(contents,'hello')"
查询的第一部分将结果集限制为 content
字段中具有 hello
的文档,而第二部分 invokes the function query parser 通过魔术 _val_
场地。该函数的结果被指定为文档的分数,有效地返回匹配的文档和这些文档中给定术语的计数。
如果您不想将其分配为分数,您也应该能够直接在字段列表 (fl=termfreq(contents,'hello'),score,foo
) 中使用 termfreq(contents, 'hello')
。
我正在尝试使用其 API、
查询 solr 索引http://localhost:8983/solr/documents/select?defType=func&q=termfreq(contents,'hello)&wt=json
我已经为 3 个文档建立了索引,其中 2 个 documents/records 有术语 "hello" 但它 returns 所有文档。
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"termfreq(contents,'hello')",
"defType":"func",
"indent":"on",
"wt":["json",
"json"],
"_":"1538568705504"}},
"response":{"numFound":3,"start":0,"docs":[
{*here I have docs*}
]
}
我只期待包含单词 hello 及其在这些文档中出现的文档。
我说得对还是我没有正确理解这个函数?
您不能在 Solr 中使用类似的函数。要仅检索出现术语 hello
的文档,并将计数作为分数,请使用:
q=content:hello _val_:"termfreq(contents,'hello')"
查询的第一部分将结果集限制为 content
字段中具有 hello
的文档,而第二部分 invokes the function query parser 通过魔术 _val_
场地。该函数的结果被指定为文档的分数,有效地返回匹配的文档和这些文档中给定术语的计数。
如果您不想将其分配为分数,您也应该能够直接在字段列表 (fl=termfreq(contents,'hello'),score,foo
) 中使用 termfreq(contents, 'hello')
。