Search in sources :

Example 1 with SimilarityFactory

use of org.apache.solr.schema.SimilarityFactory in project lucene-solr by apache.

the class ChangedSchemaMergeTest method assertSimilarity.

private static void assertSimilarity(SolrCore core, Class<? extends SimilarityFactory> expected) {
    SimilarityFactory actual = core.getLatestSchema().getSimilarityFactory();
    assertNotNull(actual);
    assertEquals(expected, actual.getClass());
    // if SolrCoreAware sim isn't properly initialized, this will throw an exception
    assertNotNull(actual.getSimilarity());
}
Also used : SimilarityFactory(org.apache.solr.schema.SimilarityFactory) LMJelinekMercerSimilarityFactory(org.apache.solr.search.similarities.LMJelinekMercerSimilarityFactory) SchemaSimilarityFactory(org.apache.solr.search.similarities.SchemaSimilarityFactory)

Example 2 with SimilarityFactory

use of org.apache.solr.schema.SimilarityFactory 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 3 with SimilarityFactory

use of org.apache.solr.schema.SimilarityFactory in project lucene-solr by apache.

the class SolrCore method setLatestSchema.

/** 
   * Sets the latest schema snapshot to be used by this core instance. 
   * If the specified <code>replacementSchema</code> uses a {@link SimilarityFactory} which is 
   * {@link SolrCoreAware} then this method will {@link SolrCoreAware#inform} that factory about 
   * this SolrCore prior to using the <code>replacementSchema</code>
   * @see #getLatestSchema
   */
public void setLatestSchema(IndexSchema replacementSchema) {
    // 1) For a newly instantiated core, the Similarity needs SolrCore before inform() is called on
    // any registered SolrCoreAware listeners (which will likeley need to use the SolrIndexSearcher.
    //
    // 2) If a new IndexSchema is assigned to an existing live SolrCore (ie: managed schema
    // replacement via SolrCloud) then we need to explicitly inform() the similarity because
    // we can't rely on the normal SolrResourceLoader lifecycle because the sim was instantiated
    // after the SolrCore was already live (see: SOLR-8311 + SOLR-8280)
    final SimilarityFactory similarityFactory = replacementSchema.getSimilarityFactory();
    if (similarityFactory instanceof SolrCoreAware) {
        ((SolrCoreAware) similarityFactory).inform(this);
    }
    this.schema = replacementSchema;
}
Also used : SolrCoreAware(org.apache.solr.util.plugin.SolrCoreAware) SimilarityFactory(org.apache.solr.schema.SimilarityFactory)

Aggregations

SimilarityFactory (org.apache.solr.schema.SimilarityFactory)3 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 Similarity (org.apache.lucene.search.similarities.Similarity)1 CoreContainer (org.apache.solr.core.CoreContainer)1 SolrCore (org.apache.solr.core.SolrCore)1 LMJelinekMercerSimilarityFactory (org.apache.solr.search.similarities.LMJelinekMercerSimilarityFactory)1 SolrCoreAware (org.apache.solr.util.plugin.SolrCoreAware)1