use of org.apache.lucene.search.similarities.Similarity in project lucene-solr by apache.
the class ChangedSchemaMergeTest method testSanityOfSchemaSimilarityFactoryInform.
public void testSanityOfSchemaSimilarityFactoryInform() {
// sanity check that SchemaSimilarityFactory will throw an Exception if you
// try to use it w/o inform(SolrCoreAware) otherwise assertSimilarity is useless
SchemaSimilarityFactory broken = new SchemaSimilarityFactory();
broken.init(new ModifiableSolrParams());
// NO INFORM
try {
Similarity bogus = broken.getSimilarity();
fail("SchemaSimilarityFactory should have thrown IllegalStateException b/c inform not used");
} catch (IllegalStateException expected) {
assertTrue("GOT: " + expected.getMessage(), expected.getMessage().contains("SolrCoreAware.inform"));
}
}
use of org.apache.lucene.search.similarities.Similarity in project lucene-solr by apache.
the class TestPerFieldSimilarity method testFactory.
/** test a field where a configurable sim factory is defined */
public void testFactory() throws Exception {
Similarity sim = getSimilarity("sim2text");
assertEquals(MockConfigurableSimilarity.class, sim.getClass());
assertEquals("is there an echo?", ((MockConfigurableSimilarity) sim).getPassthrough());
}
use of org.apache.lucene.search.similarities.Similarity in project lucene-solr by apache.
the class TestPerFieldSimilarity method testDefaultsDynamic.
/** ... and for a dynamic field */
public void testDefaultsDynamic() throws Exception {
Similarity sim = getSimilarity("text_sim3");
assertEquals(BM25Similarity.class, sim.getClass());
}
use of org.apache.lucene.search.similarities.Similarity in project lucene-solr by apache.
the class TestSweetSpotSimilarityFactory method computeNorm.
private static float computeNorm(Similarity sim, int length) throws IOException {
String value = IntStream.range(0, length).mapToObj(i -> "a").collect(Collectors.joining(" "));
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setSimilarity(sim));
w.addDocument(Collections.singleton(newTextField("foo", value, Store.NO)));
DirectoryReader reader = DirectoryReader.open(w);
w.close();
IndexSearcher searcher = new IndexSearcher(reader);
searcher.setSimilarity(sim);
Explanation expl = searcher.explain(new TermQuery(new Term("foo", "a")), 0);
reader.close();
dir.close();
Explanation norm = findExplanation(expl, "fieldNorm");
assertNotNull(norm);
return norm.getValue();
}
use of org.apache.lucene.search.similarities.Similarity in project lucene-solr by apache.
the class TestDFRSimilarityFactory method test.
/** dfr with default parameters */
public void test() throws Exception {
Similarity sim = getSimilarity("text");
assertEquals(DFRSimilarity.class, sim.getClass());
DFRSimilarity dfr = (DFRSimilarity) sim;
assertEquals(BasicModelIF.class, dfr.getBasicModel().getClass());
assertEquals(AfterEffectB.class, dfr.getAfterEffect().getClass());
assertEquals(NormalizationH2.class, dfr.getNormalization().getClass());
}
Aggregations