Methods Summary |
---|
private void | doTestCaching(java.lang.String field, org.apache.lucene.search.function.FieldScoreQuery$Type tp)
// prepare expected array types for comparison
HashMap expectedArrayTypes = new HashMap();
expectedArrayTypes.put(FieldScoreQuery.Type.BYTE, new byte[0]);
expectedArrayTypes.put(FieldScoreQuery.Type.SHORT, new short[0]);
expectedArrayTypes.put(FieldScoreQuery.Type.INT, new int[0]);
expectedArrayTypes.put(FieldScoreQuery.Type.FLOAT, new float[0]);
IndexSearcher s = new IndexSearcher(dir);
Object innerArray = null;
for (int i=0; i<10; i++) {
FieldScoreQuery q = new FieldScoreQuery(field,tp);
Hits h = s.search(q);
assertEquals("All docs should be matched!",N_DOCS,h.length());
if (i==0) {
innerArray = q.valSrc.getValues(s.getIndexReader()).getInnerArray();
log(i+". compare: "+innerArray.getClass()+" to "+expectedArrayTypes.get(tp).getClass());
assertEquals("field values should be cached in the correct array type!", innerArray.getClass(),expectedArrayTypes.get(tp).getClass());
} else {
log(i+". compare: "+innerArray+" to "+q.valSrc.getValues(s.getIndexReader()).getInnerArray());
assertSame("field values should be cached and reused!", innerArray, q.valSrc.getValues(s.getIndexReader()).getInnerArray());
}
}
// verify new values are reloaded (not reused) for a new reader
s = new IndexSearcher(dir);
FieldScoreQuery q = new FieldScoreQuery(field,tp);
Hits h = s.search(q);
assertEquals("All docs should be matched!",N_DOCS,h.length());
log("compare: "+innerArray+" to "+q.valSrc.getValues(s.getIndexReader()).getInnerArray());
assertNotSame("cached field values should not be reused if reader as changed!", innerArray, q.valSrc.getValues(s.getIndexReader()).getInnerArray());
|
private void | doTestExactScore(java.lang.String field, org.apache.lucene.search.function.FieldScoreQuery$Type tp)
IndexSearcher s = new IndexSearcher(dir);
Query q = new FieldScoreQuery(field,tp);
TopDocs td = s.search(q,null,1000);
assertEquals("All docs should be matched!",N_DOCS,td.totalHits);
ScoreDoc sd[] = td.scoreDocs;
for (int i=0; i<sd.length; i++) {
float score = sd[i].score;
log(s.explain(q,sd[i].doc));
String id = s.getIndexReader().document(sd[i].doc).get(ID_FIELD);
float expectedScore = expectedFieldScore(id); // "ID7" --> 7.0
assertEquals("score of "+id+" shuould be "+expectedScore+" != "+score, expectedScore, score, TEST_SCORE_TOLERANCE_DELTA);
}
|
private void | doTestRank(java.lang.String field, org.apache.lucene.search.function.FieldScoreQuery$Type tp)
IndexSearcher s = new IndexSearcher(dir);
Query q = new FieldScoreQuery(field,tp);
log("test: "+q);
QueryUtils.check(q,s);
Hits h = s.search(q);
assertEquals("All docs should be matched!",N_DOCS,h.length());
String prevID = "ID"+(N_DOCS+1); // greater than all ids of docs in this test
for (int i=0; i<h.length(); i++) {
String resID = h.doc(i).get(ID_FIELD);
log(i+". score="+h.score(i)+" - "+resID);
log(s.explain(q,h.id(i)));
assertTrue("res id "+resID+" should be < prev res id "+prevID, resID.compareTo(prevID)<0);
prevID = resID;
}
|
protected void | setUp()
// prepare a small index with just a few documents.
super.setUp();
|
protected void | tearDown()
super.tearDown();
|
public void | testCachingByte()Test that FieldScoreQuery of Type.BYTE caches/reuses loaded values and consumes the proper RAM resources.
// INT field values are small enough to be parsed as byte
doTestCaching(INT_FIELD,FieldScoreQuery.Type.BYTE);
|
public void | testCachingFloat()Test that FieldScoreQuery of Type.FLOAT caches/reuses loaded values and consumes the proper RAM resources.
// INT field values can be parsed as float
doTestCaching(INT_FIELD,FieldScoreQuery.Type.FLOAT);
// same values, but in flot format
doTestCaching(FLOAT_FIELD,FieldScoreQuery.Type.FLOAT);
|
public void | testCachingInt()Test that FieldScoreQuery of Type.INT caches/reuses loaded values and consumes the proper RAM resources.
doTestCaching(INT_FIELD,FieldScoreQuery.Type.INT);
|
public void | testCachingShort()Test that FieldScoreQuery of Type.SHORT caches/reuses loaded values and consumes the proper RAM resources.
// INT field values are small enough to be parsed as short
doTestCaching(INT_FIELD,FieldScoreQuery.Type.SHORT);
|
public void | testExactScoreByte()Test that FieldScoreQuery of Type.BYTE returns the expected scores.
// INT field values are small enough to be parsed as byte
doTestExactScore(INT_FIELD,FieldScoreQuery.Type.BYTE);
|
public void | testExactScoreFloat()Test that FieldScoreQuery of Type.FLOAT returns the expected scores.
// INT field can be parsed as float
doTestExactScore(INT_FIELD,FieldScoreQuery.Type.FLOAT);
// same values, but in flot format
doTestExactScore(FLOAT_FIELD,FieldScoreQuery.Type.FLOAT);
|
public void | testExactScoreInt()Test that FieldScoreQuery of Type.INT returns the expected scores.
doTestExactScore(INT_FIELD,FieldScoreQuery.Type.INT);
|
public void | testExactScoreShort()Test that FieldScoreQuery of Type.SHORT returns the expected scores.
// INT field values are small enough to be parsed as short
doTestExactScore(INT_FIELD,FieldScoreQuery.Type.SHORT);
|
public void | testRankByte()Test that FieldScoreQuery of Type.BYTE returns docs in expected order.
// INT field values are small enough to be parsed as byte
doTestRank(INT_FIELD,FieldScoreQuery.Type.BYTE);
|
public void | testRankFloat()Test that FieldScoreQuery of Type.FLOAT returns docs in expected order.
// INT field can be parsed as float
doTestRank(INT_FIELD,FieldScoreQuery.Type.FLOAT);
// same values, but in flot format
doTestRank(FLOAT_FIELD,FieldScoreQuery.Type.FLOAT);
|
public void | testRankInt()Test that FieldScoreQuery of Type.INT returns docs in expected order.
doTestRank(INT_FIELD,FieldScoreQuery.Type.INT);
|
public void | testRankShort()Test that FieldScoreQuery of Type.SHORT returns docs in expected order.
// INT field values are small enough to be parsed as short
doTestRank(INT_FIELD,FieldScoreQuery.Type.SHORT);
|