【问题标题】:Lucene: exact matches aren't shown firstLucene:不首先显示完全匹配
【发布时间】:2013-10-13 14:25:41
【问题描述】:

我正在使用演示 IndexFiles 和 SearchFiles 类来索引和搜索 org.apache.lucene.demo 数据包中的内容。

我的问题是,当我使用包含多个单词的查询时,我没有得到完全匹配的结果。例如:

Enter query:
"natural language"
Searching for: "natural language"
298 total matching documents
1. download\researchers.uq.edu.au\fields-of-research\natural-language-processing
.txt
2. download\researchers.uq.edu.au\research-project\16267.txt
3. download\researchers.uq.edu.au\research-project\16279.txt
4. download\researchers.uq.edu.au\research-project\18361.txt
5. download\www.uq.edu.au\news\%3Farticle%3D2187.txt
6. download\researchers.uq.edu.au\researcher\2115.txt
7. download\ceit.uq.edu.au\content\2013-2014-summer-research-scholarship-project
s-dr-alan-cody%3Fpage%3D1.txt
8. download\ceit.uq.edu.au\content\2013-2014-summer-research-scholarship-project
s-dr-alan-cody%3Fpage%3D2.txt
9. download\ceit.uq.edu.au\content\2013-2014-summer-research-scholarship-project
s-dr-alan-cody.txt
10. download\www.ceit.uq.edu.au\content\2013-2014-summer-research-scholarship-pr
ojects-dr-alan-cody.txt
Press (n)ext page, (q)uit or enter number to jump to a page.

与以下结果不同:

Enter query:
natural language
Searching for: natural language
54307 total matching documents
1. download\cyberschool.library.uq.edu.au\display_resource.phtml%3Frid%3D190.txt

2. download\cyberschool.library.uq.edu.au\display_resource.phtml%3Frid%3D576.txt

3. download\cyberschool.library.uq.edu.au\display_resource.phtml%3Frid%3D46.txt
4. download\espace.library.uq.edu.au\view\UQ%3A166163.txt
5. download\cyberschool.library.uq.edu.au\display_resource.phtml%3Frid%3D108.txt

6. download\cyberschool.library.uq.edu.au\display_resource.phtml%3Frid%3D70.txt
7. download\cyberschool.library.uq.edu.au\display_resource.phtml%3Frid%3D708.txt

8. download\researchers.uq.edu.au\fields-of-research\natural-language-processing
.txt
9. download\researchers.uq.edu.au\research-project\16267.txt
10. download\cyberschool.library.uq.edu.au\display_resource.phtml%3Frid%3D117.tx
t
Press (n)ext page, (q)uit or enter number to jump to a page.

例如第一个匹配的文档甚至不包含“语言”关键字。

如果我在IndexSearcher 类中使用explain() 方法,那么我将得到第一个结果:

1. download\cyberschool.library.uq.edu.au\display_resource.phtml%3Frid%3D190.txt
0.70643383 = (MATCH) sum of:
  0.5590494 = (MATCH) weight(contents:natural in 62541) [DefaultSimilarity], result of:
    0.5590494 = score(doc=62541,freq=4.0 = termFreq=4.0
), product of:
      0.8091749 = queryWeight, product of:
        4.4216847 = idf(docFreq=13111, maxDocs=401502)
        0.18300149 = queryNorm
      0.6908882 = fieldWeight in 62541, product of:
        2.0 = tf(freq=4.0), with freq of:
          4.0 = termFreq=4.0
        4.4216847 = idf(docFreq=13111, maxDocs=401502)
        0.078125 = fieldNorm(doc=62541)
  0.1473844 = (MATCH) weight(contents:language in 62541) [DefaultSimilarity], result of:
    0.1473844 = score(doc=62541,freq=1.0 = termFreq=1.0
), product of:
      0.5875679 = queryWeight, product of:
        3.2107275 = idf(docFreq=44012, maxDocs=401502)
        0.18300149 = queryNorm
      0.25083807 = fieldWeight in 62541, product of:
        1.0 = tf(freq=1.0), with freq of:
          1.0 = termFreq=1.0
        3.2107275 = idf(docFreq=44012, maxDocs=401502)
        0.078125 = fieldNorm(doc=62541)

如果我点击下一步并找到这样的结果:

19. download\www.uq.edu.au\news\%3Farticle%3D2187.txt
0.47449595 = (MATCH) sum of:
  0.2795247 = (MATCH) weight(contents:natural in 35173) [DefaultSimilarity], result of:
    0.2795247 = score(doc=35173,freq=4.0 = termFreq=4.0
), product of:
      0.8091749 = queryWeight, product of:
        4.4216847 = idf(docFreq=13111, maxDocs=401502)
        0.18300149 = queryNorm
      0.3454441 = fieldWeight in 35173, product of:
        2.0 = tf(freq=4.0), with freq of:
          4.0 = termFreq=4.0
        4.4216847 = idf(docFreq=13111, maxDocs=401502)
        0.0390625 = fieldNorm(doc=35173)
  0.19497125 = (MATCH) weight(contents:language in 35173) [DefaultSimilarity], result of:
    0.19497125 = score(doc=35173,freq=7.0 = termFreq=7.0
), product of:
      0.5875679 = queryWeight, product of:
        3.2107275 = idf(docFreq=44012, maxDocs=401502)
        0.18300149 = queryNorm
      0.33182758 = fieldWeight in 35173, product of:
        2.6457512 = tf(freq=7.0), with freq of:
          7.0 = termFreq=7.0
        3.2107275 = idf(docFreq=44012, maxDocs=401502)
        0.0390625 = fieldNorm(doc=35173)

哪个页面本身包含确切的关键字“自然语言”。所以我的问题是:

1) 为什么 Lucene 不首先显示完全匹配?

2) 为什么 Lucene 显示的结果甚至不包含关键字?

3) 我可以在哪里/如何更改它,以便它首先显示完全匹配的,然后显示更相关的?

【问题讨论】:

    标签: java lucene rank scoring


    【解决方案1】:

    1 - 不打算这样做。请参阅Lucene query syntax 上的文档。查询natural language 是由两个词组成的查询。就其本身而言,Lucene 并不倾向于将这些术语放在一起。如果你想找到完全匹配,短语查询是正确的方法,比如"natural language"

    2 - 您包含解释的两个结果都包含两个术语的匹配项,请参阅:

    0.2795247 = (MATCH) weight(contents:natural in 35173) [DefaultSimilarity], result of:
      0.2795247 = score(doc=35173,freq=4.0 = termFreq=4.0
    ...
    0.19497125 = (MATCH) weight(contents:language in 35173) [DefaultSimilarity], result of:
      0.19497125 = score(doc=35173,freq=7.0 = termFreq=7.0
    

    根据 Lucene,它在该文档中找到了 4 次“自然”一词,在内容字段(我假设这是您的默认字段)中找到了 7 次“语言”。

    3 - 查看查询解析器语法,看看什么对您最有意义。听起来您可能会发现 Proximity Searches 很有用。

    如果您只想简单地获得短语匹配,然后是其他人,您可以使用以下内容:

    "natural language" natural language
    

    【讨论】:

    • 谢谢,但Proximity Search 实际上不会单独查找单词。所以这不是我所追求的
    • 当然,这就是提供另一种方法的原因,将单独的术语查询与短语查询结合​​起来,应该可以很好地发挥作用。这在某种程度上是不够的吗?
    • 我已经想过实际上,但对于较大的查询,即使是 4 个关键字,我也会有 3 个查询,其中包括 2 个词、2 个 3 词的查询和查询本身。我已经开发了一种算法来查找需要 O(n^3) 时间的子查询,所以如果您考虑 10 个关键字查询,那并不是那么好。我想知道是否可以将邻近搜索与默认搜索结合起来?
    • 这与您在此处提出的问题有些不同,并且在评论空间中并没有真正充分地描述,我不认为。您可能想提出一个新问题,以便进一步充实这一点。
    • 为什么它仍然属于我认为的第三个问题?如果我可以将邻近搜索与默认搜索结合起来,我可以提升邻近搜索的结果,这会给我更高的分数,还是我错了?
    猜你喜欢
    • 2014-08-23
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多