Search in sources :

Example 1 with SchemaSimilarityFactory

use of org.apache.solr.search.similarities.SchemaSimilarityFactory in project lucene-solr by apache.

the class TestBulkSchemaAPI method assertFieldSimilarity.

/**
   * whitebox checks the Similarity for the specified field according to {@link SolrCore#getLatestSchema}
   * 
   * Executes each of the specified Similarity-accepting validators.
   */
@SafeVarargs
private static <T extends Similarity> void assertFieldSimilarity(String fieldname, Class<T> expected, Consumer<T>... validators) {
    CoreContainer cc = jetty.getCoreContainer();
    try (SolrCore core = cc.getCore("collection1")) {
        SimilarityFactory simfac = core.getLatestSchema().getSimilarityFactory();
        assertNotNull(simfac);
        assertTrue("test only works with SchemaSimilarityFactory", simfac instanceof SchemaSimilarityFactory);
        Similarity mainSim = core.getLatestSchema().getSimilarity();
        assertNotNull(mainSim);
        // sanity check simfac vs sim in use - also verify infom called on simfac, otherwise exception
        assertEquals(mainSim, simfac.getSimilarity());
        assertTrue("test only works with PerFieldSimilarityWrapper, SchemaSimilarityFactory redefined?", mainSim instanceof PerFieldSimilarityWrapper);
        Similarity fieldSim = ((PerFieldSimilarityWrapper) mainSim).get(fieldname);
        assertEquals("wrong sim for field=" + fieldname, expected, fieldSim.getClass());
        Arrays.asList(validators).forEach(v -> v.accept((T) fieldSim));
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SweetSpotSimilarity(org.apache.lucene.misc.SweetSpotSimilarity) Similarity(org.apache.lucene.search.similarities.Similarity) DFISimilarity(org.apache.lucene.search.similarities.DFISimilarity) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) SolrCore(org.apache.solr.core.SolrCore) PerFieldSimilarityWrapper(org.apache.lucene.search.similarities.PerFieldSimilarityWrapper) SchemaSimilarityFactory(org.apache.solr.search.similarities.SchemaSimilarityFactory) SimilarityFactory(org.apache.solr.schema.SimilarityFactory) SchemaSimilarityFactory(org.apache.solr.search.similarities.SchemaSimilarityFactory)

Example 2 with SchemaSimilarityFactory

use of org.apache.solr.search.similarities.SchemaSimilarityFactory 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"));
    }
}
Also used : Similarity(org.apache.lucene.search.similarities.Similarity) SchemaSimilarityFactory(org.apache.solr.search.similarities.SchemaSimilarityFactory) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

Similarity (org.apache.lucene.search.similarities.Similarity)2 SchemaSimilarityFactory (org.apache.solr.search.similarities.SchemaSimilarityFactory)2 SweetSpotSimilarity (org.apache.lucene.misc.SweetSpotSimilarity)1 BM25Similarity (org.apache.lucene.search.similarities.BM25Similarity)1 DFISimilarity (org.apache.lucene.search.similarities.DFISimilarity)1 PerFieldSimilarityWrapper (org.apache.lucene.search.similarities.PerFieldSimilarityWrapper)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1 CoreContainer (org.apache.solr.core.CoreContainer)1 SolrCore (org.apache.solr.core.SolrCore)1 SimilarityFactory (org.apache.solr.schema.SimilarityFactory)1