gpt4 book ai didi

java - Lucene:首先不显示精确匹配

转载 作者:行者123 更新时间:2023-12-01 04:18:24 24 4
gpt4 key购买 nike

我正在使用演示 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)我可以在哪里/如何更改它,以便它首先显示完全匹配的内容,然后显示更相关的内容?

最佳答案

1 - 无意这样做。请参阅 Lucene query syntax 上的文档。查询自然语言是由两个术语组成的查询。就其本身而言,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

关于java - Lucene:首先不显示精确匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19217634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com