简体   繁体   English

Lucene。 如何计算每个文档的点击数?

[英]Lucene. how do I count the number of hits per document?

At StackOverflow I found this one In a Lucene / Lucene.net search, how do I count the number of hits per document? 在StackOverflow上,我发现了这一点。 在Lucene / Lucene.net搜索中,如何计算每个文档的点击数?

But I can not define SpanQuery from code below. 但是我不能从下面的代码定义SpanQuery。 I'm using Lucene 4.4.0(spanquery defining is different than older versions) 我正在使用Lucene 4.4.0(spanquery定义与旧版本不同)

IndexReader indexReader = // define your index reader here
SpanQuery spanQuery = // define your span query here
Spans spans = spanQuery.getSpans(indexReader);
int occurrenceCount = 0;
while (spans.next()) {
    occurrenceCount++;
}

Anybody can help? 有人可以帮忙吗? I would really appreciate full answer with an example 我真的很高兴有一个例子的完整答案

The easier way to get the total number of occurances of a term in the index, as per the linked-to answer, would be: 根据链接的答案,获取索引中某个术语出现总数的更简单方法是:

Term term = new Term("myfield", "myterm");
long numOccurances = indexReader.totalTermFreq(term);

For example 例如

SpanQuery spanQuery = new SpanTermQuery(new Term("myfield", "myterm"); // define your span query here`enter code here`

can be used when you are interested in a single term (This example looks for the term "myterm" in the field "myfield"). 可以在对单个术语感兴趣时使用(此示例在“ myfield”字段中查找术语“ myterm”)。

Look at the other SpanQuery implementations also (SpanOrQuery, SpanNearQuery, SpanNotQuery, ...) 还要看看其他SpanQuery实现(SpanOrQuery,SpanNearQuery,SpanNotQuery等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM