use of org.apache.lucene.search.similarities.PerFieldSimilarityWrapper in project lucene-solr by apache.
the class TestSimilarityProvider method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
directory = newDirectory();
PerFieldSimilarityWrapper sim = new ExampleSimilarityProvider();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())).setSimilarity(sim);
RandomIndexWriter iw = new RandomIndexWriter(random(), directory, iwc);
Document doc = new Document();
Field field = newTextField("foo", "", Field.Store.NO);
doc.add(field);
Field field2 = newTextField("bar", "", Field.Store.NO);
doc.add(field2);
field.setStringValue("quick brown fox");
field2.setStringValue("quick brown fox");
iw.addDocument(doc);
field.setStringValue("jumps over lazy brown dog");
field2.setStringValue("jumps over lazy brown dog");
iw.addDocument(doc);
reader = iw.getReader();
iw.close();
searcher = newSearcher(reader);
searcher.setSimilarity(sim);
}
Aggregations