Lucene:完全不显示完全匹配 [英] Lucene: exact matches aren't shown first

查看:79
本文介绍了Lucene:完全不显示完全匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the demo IndexFiles and SearchFiles classes to index and search which are in org.apache.lucene.demo packet.

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

My issue is when I use a query that contains more than a word, I am not getting results that have the exact match. For instance:

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.

例如,第一个匹配的文档甚至都不包含语言"关键字.

For instance the first matching document does not even contain "language" keyword.

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

If I use explain() method within IndexSearcher class then I am getting this result for 1st one:

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)

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

If I click next and find a result such as this:

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)

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

which page itself contains exact keyword "natural language". So my questions are:

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

1) Why Lucene does not show exact matches first?

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

2) Why Lucene shows a result that does not even contain a keyword?

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

3) Where/how can I change that so that it would first show exact matching ones and then more relevant ones?

推荐答案

1-并非旨在.请参阅 Lucene上的文档查询语法.查询natural language是由两个术语组成的查询.就其本身而言,Lucene并不倾向于将术语紧密地结合在一起.如果要查找完全匹配的内容,则短语查询是正确的方法,例如"natural language"

1 - It isn't intended to. See the documentation on Lucene query syntax. The query natural language is a query made up of two terms. On their own, Lucene has no preference for the terms be close together. If you want to find exact matches, a phrase query is the correct approach, like "natural language"

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

2 - Both results in which you included an explaination do contain matches for both terms, see:

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次.

According to Lucene, it found the term "natural" 4 times in that document, and "language" 7 times, in the content field (which I assume is your default field).

3-查看查询解析器语法,以了解最适合您的语法.听起来您可能会发现邻近搜索有用.

3 - Look over the query parser syntax, to see what makes the most sense to you. It sounds like you might find Proximity Searches useful.

如果您只想简单地获取词组匹配,然后再进行其他匹配,则可以使用以下方式:

If you just want to simply get phrase matches followed by others, you could use something along the lines of:

"natural language" natural language

这篇关于Lucene:完全不显示完全匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆