Lucene匹配所有的信息Collector

一、继承Collector接口实现这样的一个自定义类

public class TestCollectors extends Collector{

	private Scorer socore;
	//这个是否为有序排列的 ture可以接受无序排列
	@Override
	public boolean acceptsDocsOutOfOrder() {
		return true;
	}
                   //返回文档的ID编号 被执行很多次的根据匹配的文档数目。
	@Override
	public void collect(int arg0) throws IOException {
		System.out.println(this.getClass().getName()+"==="+arg0);
	}
                  //通知程序进行下一个阶段?具体不清楚
	@Override
	public void setNextReader(AtomicReaderContext arg0) throws IOException {
		System.out.println(arg0.reader());
	}
                 //返回一个评分但是只执行了一次?具体不清楚
	@Override
	public void setScorer(Scorer arg0) throws IOException {
		System.out.println(this.getClass().getName()+"======"+arg0.score());
       this.socore=arg0;		
	}

}

 二、搜索的时候装载进去

Collector c=new TestCollectors();
search.search(query_2, c);

 

猜你喜欢

转载自xiaozhou09.iteye.com/blog/1868117