JavaLucene:使用跨度获取文档中的匹配数

JavaLucene:使用跨度获取文档中的匹配数,java,lucene,Java,Lucene,如何使用spans对象为一个SpanarQuery获取文档中的所有匹配项,我知道了,但不确定如何继续 for(int i =0; i < splitwords.length ; i++) { sQuery[i] = new SpanTermQuery(new Term(field,splitwords[i])); }

如何使用spans对象为一个SpanarQuery获取文档中的所有匹配项,我知道了,但不确定如何继续

     for(int i =0; i < splitwords.length ; i++)
                     {
                         sQuery[i] = new SpanTermQuery(new Term(field,splitwords[i]));
                     }
                     SpanQuery queryCount = new SpanNearQuery(sQuery, 0, true);
                     int numspans = 0;
                     Spans span = queryCount.getSpans(reader);
                     int docId;
                     while(span.next())
                     {
                         numspans++;
                         docId = span.doc();
                         System.out.println(span.end() - span.start());
                     }
for(int i=0;i

我是否能够获取当前文档中的所有匹配项(匹配项计数)?

这将为您提供一个哈希表,其中包含每个文档ID的匹配数:

Hashtable<Integer, Integer> hits = new Hashtable<Integer, Integer>();
while (spans.next() == true)
{
     int docID = spans.doc();
     int hit = hits.get(docID) != null ? hits.get(docID) : 0;
     hit++;
     hits.put(docID, hit);
}
Hashtable hits=newhashtable();
while(span.next()==true)
{
int docID=span.doc();
int hit=hits.get(docID)!=null?hits.get(docID):0;
hit++;
点击。点击(docID,点击);
}