Methods Summary |
---|
public static void | checkNorms(org.apache.lucene.index.IndexReader reader)
// test omit norms
for (int i=0; i<DocHelper.fields.length; i++) {
Fieldable f = DocHelper.fields[i];
if (f.isIndexed()) {
assertEquals(reader.hasNorms(f.name()), !f.getOmitNorms());
assertEquals(reader.hasNorms(f.name()), !DocHelper.noNorms.containsKey(f.name()));
if (!reader.hasNorms(f.name())) {
// test for fake norms of 1.0
byte [] norms = reader.norms(f.name());
assertEquals(norms.length,reader.maxDoc());
for (int j=0; j<reader.maxDoc(); j++) {
assertEquals(norms[j], DefaultSimilarity.encodeNorm(1.0f));
}
norms = new byte[reader.maxDoc()];
reader.norms(f.name(),norms, 0);
for (int j=0; j<reader.maxDoc(); j++) {
assertEquals(norms[j], DefaultSimilarity.encodeNorm(1.0f));
}
}
}
}
|
protected void | setUp()
DocHelper.setupDoc(testDoc);
DocHelper.writeDoc(dir, testDoc);
reader = SegmentReader.get(new SegmentInfo("test", 1, dir));
|
protected void | tearDown()
|
public void | test()
assertTrue(dir != null);
assertTrue(reader != null);
assertTrue(DocHelper.nameValues.size() > 0);
assertTrue(DocHelper.numFields(testDoc) == DocHelper.all.size());
|
public void | testDelete()
Document docToDelete = new Document();
DocHelper.setupDoc(docToDelete);
DocHelper.writeDoc(dir, "seg-to-delete", docToDelete);
SegmentReader deleteReader = SegmentReader.get(new SegmentInfo("seg-to-delete", 1, dir));
assertTrue(deleteReader != null);
assertTrue(deleteReader.numDocs() == 1);
deleteReader.deleteDocument(0);
assertTrue(deleteReader.isDeleted(0) == true);
assertTrue(deleteReader.hasDeletions() == true);
assertTrue(deleteReader.numDocs() == 0);
try {
deleteReader.document(0);
fail();
} catch (IllegalArgumentException e) {
// expcected exception
}
|
public void | testDocument()
assertTrue(reader.numDocs() == 1);
assertTrue(reader.maxDoc() >= 1);
Document result = reader.document(0);
assertTrue(result != null);
//There are 2 unstored fields on the document that are not preserved across writing
assertTrue(DocHelper.numFields(result) == DocHelper.numFields(testDoc) - DocHelper.unstored.size());
List fields = result.getFields();
for (Iterator iter = fields.iterator(); iter.hasNext();) {
Fieldable field = (Fieldable) iter.next();
assertTrue(field != null);
assertTrue(DocHelper.nameValues.containsKey(field.name()));
}
|
public void | testGetFieldNameVariations()
Collection result = reader.getFieldNames(IndexReader.FieldOption.ALL);
assertTrue(result != null);
assertTrue(result.size() == DocHelper.all.size());
for (Iterator iter = result.iterator(); iter.hasNext();) {
String s = (String) iter.next();
//System.out.println("Name: " + s);
assertTrue(DocHelper.nameValues.containsKey(s) == true || s.equals(""));
}
result = reader.getFieldNames(IndexReader.FieldOption.INDEXED);
assertTrue(result != null);
assertTrue(result.size() == DocHelper.indexed.size());
for (Iterator iter = result.iterator(); iter.hasNext();) {
String s = (String) iter.next();
assertTrue(DocHelper.indexed.containsKey(s) == true || s.equals(""));
}
result = reader.getFieldNames(IndexReader.FieldOption.UNINDEXED);
assertTrue(result != null);
assertTrue(result.size() == DocHelper.unindexed.size());
//Get all indexed fields that are storing term vectors
result = reader.getFieldNames(IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR);
assertTrue(result != null);
assertTrue(result.size() == DocHelper.termvector.size());
result = reader.getFieldNames(IndexReader.FieldOption.INDEXED_NO_TERMVECTOR);
assertTrue(result != null);
assertTrue(result.size() == DocHelper.notermvector.size());
|
public void | testNorms()
//TODO: Not sure how these work/should be tested
/*
try {
byte [] norms = reader.norms(DocHelper.TEXT_FIELD_1_KEY);
System.out.println("Norms: " + norms);
assertTrue(norms != null);
} catch (IOException e) {
e.printStackTrace();
assertTrue(false);
}
*/
checkNorms(reader);
|
public void | testTermVectors()
TermFreqVector result = reader.getTermFreqVector(0, DocHelper.TEXT_FIELD_2_KEY);
assertTrue(result != null);
String [] terms = result.getTerms();
int [] freqs = result.getTermFrequencies();
assertTrue(terms != null && terms.length == 3 && freqs != null && freqs.length == 3);
for (int i = 0; i < terms.length; i++) {
String term = terms[i];
int freq = freqs[i];
assertTrue(DocHelper.FIELD_2_TEXT.indexOf(term) != -1);
assertTrue(freq > 0);
}
TermFreqVector [] results = reader.getTermFreqVectors(0);
assertTrue(results != null);
assertTrue("We do not have 4 term freq vectors, we have: " + results.length, results.length == 4);
|
public void | testTerms()
TermEnum terms = reader.terms();
assertTrue(terms != null);
while (terms.next() == true)
{
Term term = terms.term();
assertTrue(term != null);
//System.out.println("Term: " + term);
String fieldValue = (String)DocHelper.nameValues.get(term.field());
assertTrue(fieldValue.indexOf(term.text()) != -1);
}
TermDocs termDocs = reader.termDocs();
assertTrue(termDocs != null);
termDocs.seek(new Term(DocHelper.TEXT_FIELD_1_KEY, "field"));
assertTrue(termDocs.next() == true);
termDocs.seek(new Term(DocHelper.NO_NORMS_KEY, DocHelper.NO_NORMS_TEXT));
assertTrue(termDocs.next() == true);
TermPositions positions = reader.termPositions();
positions.seek(new Term(DocHelper.TEXT_FIELD_1_KEY, "field"));
assertTrue(positions != null);
assertTrue(positions.doc() == 0);
assertTrue(positions.nextPosition() >= 0);
|