【问题标题】:Solr : How to solve this user caseSolr:如何解决这个用户案例
【发布时间】:2015-03-04 09:23:08
【问题描述】:

在 Solr 4.* 中,假设我有字段 "mytext"

  1. mytext”中的第一条记录是“working at ABC”。

  2. mytext”中的第二条记录是“working at ABC project ABC”。

现在当我搜索“Working at ABC”时,文档序列是

文档 1:“Working at ABC project ABC

文档 2:“Working at ABC

虽然根据计算它是有意义的,但第二个文档应该在顶部,因为它包含两次“ABC”(第二个文档的 TF 更高)。

但从用户的角度来看,当查询输入“在 ABC 工作”时,结果应该是

"Working at ABC"

"Working at ABC project ABC"

.

我该如何处理这种情况。 仅当“公司”和“项目”有重叠数据时才会出现此项目。就像在这种情况下它的“ABC”

谢谢

阿米特·阿加瓦尔

【问题讨论】:

  • 你必须问自己为什么doc2应该有更高的排名?它对用户更有意义,但为什么呢?否则你会一直循环下去,在另一种情况下你会遇到相反的情况。
  • 你总是可以覆盖模式文件中的相似性类,并提供你自己的实现来计算TF、IDF、范数等。我通常在有奇怪情况时这样做。

标签: solr lucene lucene.net solr4


【解决方案1】:

您可以为该字段设置omitTermFreqsAndPositions=true。只要包含规范,内容较短的字段将比内容较长的字段排名更高。

【讨论】:

  • 我会用这个字段重新索引 solr .. 我想这可能是我的答案......我会让你知道 .. 谢谢
【解决方案2】:

而不是更改 schema.xml 。我覆盖了始终返回 1 的 TF 函数。因此不受词频的影响。

如果有人在短字段上使用 Solr,那么这是我的自定义类

private static float ARR[] = { 0.0f, 1.5f, 1.25f, 1.0f, 0.875f, 0.75f, 0.625f, 0.5f, 0.4375f, 0.375f, 0.3125f};

  /** 
   * Implemented as a lookup for the first 10 counts, then
   * <code>1/sqrt(numTerms)</code>. This is to avoid term counts below
   * 11 from having the same lengthNorm after being stored encoded as
   * a single byte.
   */
  public float lengthNorm(FieldInvertState state) {
    int numTerms = state.getLength();
    String fieldName = state.getName();

    System.out.println("field is " + fieldName  + "   number of terms are  " + numTerms);
    if( numTerms <= 10 ) {
      // this shouldn't be possible, but be safe.
      if( numTerms < 0 ) { numTerms = 0; }

      return ARR[numTerms];
    }
    //else
    return (float)(1.0 / Math.sqrt(numTerms));
  }

  // For short fields , term frequency does not always lead to relevancy so returning 1.0 
  @Override
  public float tf(float freq) {
      return (float) 1.0;
  }

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    • 1970-01-01
    • 2021-05-20
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多