【问题标题】:Count total frequency of a word in a SOLR index计算 SOLR 索引中单词的总频率
【发布时间】:2016-12-07 22:06:10
【问题描述】:

如果我在 SOLR 索引中搜索一个单词,我会得到包含该单词的文档的文档计数,但如果该单词在文档中包含的次数更多,则每个文档的总计数仍为 1。

我需要计算每个返回的文档在字段中出现搜索词的次数。

我阅读了Word frequency in SolrSOLR term frequency 并启用了术语向量组件,但它不起作用。

我以这种方式配置了我的字段:

<field name="text_text" type="textgen" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true" />

但如果我进行以下查询:

http://localhost:8888/solr/sources/select?q=text_text%3A%22Peter+Pan%22&fl=text_text&wt=json&indent=true&tv.tf

我没有任何计数:

{
  "responseHeader":{
    "status":0,
    "QTime":1,
    "params":{
      "fl":"text_text",
      "tv.tf":"",
      "indent":"true",
      "q":"text_text:\"Peter Pan\"",
      "wt":"json"}},
  "response":{"numFound":12,"start":0,"docs":[
      {
        "text_text":"Text of the document"},
      {
        "text_text":"Text of the document"},
      {
        "text_text":"Text of the document"},
      {
        "text_text":"Text of the document"},
      {
        "text_text":"Text of the document"},
      {
        "text_text":"Text of the document"},
      {
        "text_text":"Text of the document"},
      {
        "text_text":"Text of the document"}]
  }}

我看到“numFound”值为 12,但“彼得潘”一词在所有 12 个文档中出现了 20 次。

请你帮我找出哪里错了吗?

非常感谢!

【问题讨论】:

  • 参数 tv.tf 存在,但可以将空字符串测试为布尔值 false。在您的查询tv=true&amp;tv.tf=true 中尝试使用这些参数。
  • @Mat :你得到答案了吗?我也有同样的麻烦。请你帮帮我好吗?
  • @iNikkz:对不起,我不记得我在哪里使用这个功能,但我有一个模糊的记忆,我没有解决它,我用另一种方式计算了词频,不是直接来自索尔。对不起。
  • @Mat:好的。谢谢。我有解决方案。试试看。 (I) 总词频 => http://localhost:8983/solr/collection1/spell?q=theq&amp;wt=json&amp;indent=true&amp;fl=ttf(term,the) 和 (II) 词频 => http://localhost:8983/solr/collection1/spell?q=gram:%22ago%22&amp;rows=100&amp;fl=gram,termfreq(gram,ago)

标签: solr word-frequency


【解决方案1】:

我认为首先你的例子是行不通的,因为“彼得潘”不是一个词或术语——它是一个短语。找到短语频率的挑战的一个很好的讨论在这里:

termfreq for a phrase

我会用一个单词而不是一个短语来重试你的例子,看看它是否适合你。

【讨论】:

    【解决方案2】:

    试试这个在响应中创建词频的结构:

    http://localhost:8983/solr/core/select?indent=on&q=solr&fl=field,termfreq("field","term")&wt=json
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-07
      • 1970-01-01
      • 2019-01-27
      • 2023-03-22
      • 2018-06-27
      • 2015-06-06
      相关资源
      最近更新 更多