在 Lucene/Lucene.net 搜索中,我如何计算每个文档的点击次数? [英] In a Lucene / Lucene.net search, how do I count the number of hits per document?

查看:23
本文介绍了在 Lucene/Lucene.net 搜索中,我如何计算每个文档的点击次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索一堆文档时,我可以轻松找到符合我搜索条件的文档数量:

When searching a bunch of documents, I can easily find the number of documents which match my search criteria:

Hits hits = Searcher.Search(query);
int DocumentCount = hits.Length();

如何确定文档中的总命中数?例如,假设我搜索congress"并返回 2 个文档.如何获得每个文档中出现大会"的次数?例如,假设会议"在文档 #1 中出现 2 次,在文档 #2 中出现 3 次.我正在寻找的结果是 5.

How do I determine the total number of hits within the documents? For example, let's say I search for "congress" and I get 2 documents back. How can I get the number of times "congress" occurs in each document? For example let's say "congress" occurs 2 times in document #1 and 3 times in document #2. The result I'm looking for is 5.

推荐答案

这是 Lucene Java,但应该适用于 Lucene.NET:

This is Lucene Java, but should work for Lucene.NET:

List docIds = // doc ids for documents that matched the query, 
              // sorted in ascending order 

int totalFreq = 0;
TermDocs termDocs = reader.termDocs();
termDocs.seek(new Term("my_field", "congress"));
for (int id : docIds) {
    termDocs.skipTo(id);
    totalFreq += termDocs.freq();
}

这篇关于在 Lucene/Lucene.net 搜索中,我如何计算每个文档的点击次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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