writer.close();
/*
* Verify the index
*/
Searcher searcher = new IndexSearcher(dir, true);
searcher.setSimilarity(new SimpleSimilarity());
Term a = new Term("noTf", term);
Term b = new Term("tf", term);
Term c = new Term("noTf", "notf");
Term d = new Term("tf", "tf");
TermQuery q1 = new TermQuery(a);
TermQuery q2 = new TermQuery(b);
TermQuery q3 = new TermQuery(c);
TermQuery q4 = new TermQuery(d);
searcher.search(q1,
new CountingHitCollector() {
private Scorer scorer;
@Override
public final void setScorer(Scorer scorer) {
this.scorer = scorer;
}
@Override
public final void collect(int doc) throws IOException {
//System.out.println("Q1: Doc=" + doc + " score=" + score);
float score = scorer.score();
assertTrue(score==1.0f);
super.collect(doc);
}
});
//System.out.println(CountingHitCollector.getCount());
searcher.search(q2,
new CountingHitCollector() {
private Scorer scorer;
@Override
public final void setScorer(Scorer scorer) {
this.scorer = scorer;
}
@Override
public final void collect(int doc) throws IOException {
//System.out.println("Q2: Doc=" + doc + " score=" + score);
float score = scorer.score();
assertEquals(1.0f+doc, score, 0.00001f);
super.collect(doc);
}
});
//System.out.println(CountingHitCollector.getCount());
searcher.search(q3,
new CountingHitCollector() {
private Scorer scorer;
@Override
public final void setScorer(Scorer scorer) {
this.scorer = scorer;
}
@Override
public final void collect(int doc) throws IOException {
//System.out.println("Q1: Doc=" + doc + " score=" + score);
float score = scorer.score();
assertTrue(score==1.0f);
assertFalse(doc%2==0);
super.collect(doc);
}
});
//System.out.println(CountingHitCollector.getCount());
searcher.search(q4,
new CountingHitCollector() {
private Scorer scorer;
@Override
public final void setScorer(Scorer scorer) {
this.scorer = scorer;
}
@Override
public final void collect(int doc) throws IOException {
float score = scorer.score();
//System.out.println("Q1: Doc=" + doc + " score=" + score);
assertTrue(score==1.0f);
assertTrue(doc%2==0);
super.collect(doc);
}
});
//System.out.println(CountingHitCollector.getCount());
BooleanQuery bq = new BooleanQuery();
bq.add(q1,Occur.MUST);
bq.add(q4,Occur.MUST);
searcher.search(bq,
new CountingHitCollector() {
@Override
public final void collect(int doc) throws IOException {
//System.out.println("BQ: Doc=" + doc + " score=" + score);
super.collect(doc);
}
});
assertTrue(15 == CountingHitCollector.getCount());
searcher.close();
dir.close();
}