Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lucene评分问题_Lucene_Information Retrieval_Scoring - Fatal编程技术网

Lucene评分问题

Lucene评分问题,lucene,information-retrieval,scoring,Lucene,Information Retrieval,Scoring,我对Lucene的评分函数有个问题,我想不出来。到目前为止,我已经能够编写此代码来复制它 package lucenebug; import java.util.Arrays; import java.util.List; import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; i

我对Lucene的评分函数有个问题,我想不出来。到目前为止,我已经能够编写此代码来复制它

package lucenebug;

import java.util.Arrays;
import java.util.List;

import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;

public class Test {
    private static final String TMP_LUCENEBUG_INDEX = "/tmp/lucenebug_index";

    public static void main(String[] args) throws Throwable {
        SimpleAnalyzer analyzer = new SimpleAnalyzer();
        IndexWriter w = new IndexWriter(TMP_LUCENEBUG_INDEX, analyzer, true);
        List<String> names = Arrays
                .asList(new String[] { "the rolling stones",
                        "rolling stones (karaoke)",
                        "the rolling stones tribute",
                        "rolling stones tribute band",
                        "karaoke - the rolling stones" });
        try {
            for (String name : names) {
                System.out.println("#name: " + name);
                Document doc = new Document();
                doc.add(new Field("name", name, Field.Store.YES,
                        Field.Index.TOKENIZED));
                w.addDocument(doc);
            }
            System.out.println("finished adding docs, total size: "
                    + w.docCount());

        } finally {
            w.close();
        }

        IndexSearcher s = new IndexSearcher(TMP_LUCENEBUG_INDEX);
        QueryParser p = new QueryParser("name", analyzer);
        Query q = p.parse("name:(rolling stones)");
        System.out.println("--------\nquery: " + q);

        TopDocs topdocs = s.search(q, null, 10);
        for (ScoreDoc sd : topdocs.scoreDocs) {
            System.out.println("" + sd.score + "\t"
                    + s.doc(sd.doc).getField("name").stringValue());
        }
    }
}
我就是不明白为什么《滚石》和《滚石颂歌》有着同样的相关性。根据lucene的说法,一个字段的标记越多,标准化因子应该越小,因此
滚石乐队的贡品
应该比
滚石乐队的分数更低


有什么想法吗?

我可以在Lucene 2.3.1上复制它,但不知道为什么会发生这种情况。

长度标准化因子计算为
1/sqrt(numTerms)
(您可以在

此结果不会直接存储在索引中。此值乘以指定字段的提升值。然后,最终结果将以8位编码,如中所述,这是一种有损编码,意味着精细细节将丢失

若您想看到长度规范化的实际应用,请尝试使用以下语句创建文档

the rolling stones tribute a b c d e f g h i j k 
这将在您可以看到的长度规格化值中创建足够的差异


现在,根据您使用的示例,如果您的字段只有很少的标记,那么您可以根据自己的公式为文档/字段设置boost值,这基本上是短字段的更高boost值。或者,您可以创建自定义相似性并覆盖legthNorm()方法。

您使用的是什么Lucene版本(链接2.4的API文档)?在Lucene 2.9中,默认情况下不会返回分数,您必须提供TopFieldCollector:@gossamer:我对Lucene 2.3、2.4和2.9运行了相同的代码。结果相同。没错,8位编码将
boost*lengthNorm
四舍五入,并导致问题。在索引期间将字段boost设置为100是一个足够干净的方法我的解决办法。@Shashikant Kore谢谢!
the rolling stones tribute a b c d e f g h i j k