@Override
public void setUp() throws Exception {
super.setUp();
index = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, index,
newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random))
.setSimilarity(sim).setMergePolicy(newLogMergePolicy()));
// hed is the most important field, dek is secondary
// d1 is an "ok" match for: albino elephant
{
Document d1 = new Document();
d1.add(newField("id", "d1", Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("id",
// "d1"));
d1
.add(newField("hed", "elephant", Field.Store.YES,
Field.Index.ANALYZED));// Field.Text("hed", "elephant"));
d1
.add(newField("dek", "elephant", Field.Store.YES,
Field.Index.ANALYZED));// Field.Text("dek", "elephant"));
writer.addDocument(d1);
}
// d2 is a "good" match for: albino elephant
{
Document d2 = new Document();
d2.add(newField("id", "d2", Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("id",
// "d2"));
d2
.add(newField("hed", "elephant", Field.Store.YES,
Field.Index.ANALYZED));// Field.Text("hed", "elephant"));
d2.add(newField("dek", "albino", Field.Store.YES, Field.Index.ANALYZED));// Field.Text("dek",
// "albino"));
d2
.add(newField("dek", "elephant", Field.Store.YES,
Field.Index.ANALYZED));// Field.Text("dek", "elephant"));
writer.addDocument(d2);
}
// d3 is a "better" match for: albino elephant
{
Document d3 = new Document();
d3.add(newField("id", "d3", Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("id",
// "d3"));
d3.add(newField("hed", "albino", Field.Store.YES, Field.Index.ANALYZED));// Field.Text("hed",
// "albino"));
d3
.add(newField("hed", "elephant", Field.Store.YES,
Field.Index.ANALYZED));// Field.Text("hed", "elephant"));
writer.addDocument(d3);
}
// d4 is the "best" match for: albino elephant
{
Document d4 = new Document();
d4.add(newField("id", "d4", Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("id",
// "d4"));
d4.add(newField("hed", "albino", Field.Store.YES, Field.Index.ANALYZED));// Field.Text("hed",
// "albino"));
d4
.add(newField("hed", "elephant", Field.Store.YES,
Field.Index.ANALYZED));// Field.Text("hed", "elephant"));
d4.add(newField("dek", "albino", Field.Store.YES, Field.Index.ANALYZED));// Field.Text("dek",
// "albino"));
writer.addDocument(d4);
}
writer.optimize();
r = writer.getReader();
writer.close();
s = newSearcher(r);
s.setSimilarity(sim);
}