Search in sources :

Example 6 with Similarity

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

the class TestDFRSimilarityFactory method testParameters.

/** dfr with parametrized normalization */
public void testParameters() throws Exception {
    Similarity sim = getSimilarity("text_params");
    assertEquals(DFRSimilarity.class, sim.getClass());
    DFRSimilarity dfr = (DFRSimilarity) sim;
    assertEquals(BasicModelIF.class, dfr.getBasicModel().getClass());
    assertEquals(AfterEffectB.class, dfr.getAfterEffect().getClass());
    assertEquals(NormalizationH3.class, dfr.getNormalization().getClass());
    NormalizationH3 norm = (NormalizationH3) dfr.getNormalization();
    assertEquals(900f, norm.getMu(), 0.01f);
}
Also used : DFRSimilarity(org.apache.lucene.search.similarities.DFRSimilarity) Similarity(org.apache.lucene.search.similarities.Similarity) NormalizationH3(org.apache.lucene.search.similarities.NormalizationH3) DFRSimilarity(org.apache.lucene.search.similarities.DFRSimilarity)

Example 7 with Similarity

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

the class TestIBSimilarityFactory method testParameters.

/** ll/ttf/h3 with parametrized normalization */
public void testParameters() throws Exception {
    Similarity sim = getSimilarity("text_params");
    assertEquals(IBSimilarity.class, sim.getClass());
    IBSimilarity ib = (IBSimilarity) sim;
    assertEquals(DistributionLL.class, ib.getDistribution().getClass());
    assertEquals(LambdaTTF.class, ib.getLambda().getClass());
    assertEquals(NormalizationH3.class, ib.getNormalization().getClass());
    NormalizationH3 norm = (NormalizationH3) ib.getNormalization();
    assertEquals(900f, norm.getMu(), 0.01f);
}
Also used : Similarity(org.apache.lucene.search.similarities.Similarity) IBSimilarity(org.apache.lucene.search.similarities.IBSimilarity) NormalizationH3(org.apache.lucene.search.similarities.NormalizationH3) IBSimilarity(org.apache.lucene.search.similarities.IBSimilarity)

Example 8 with Similarity

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

the class TestLMJelinekMercerSimilarityFactory method testParameters.

/** jelinek-mercer with parameters */
public void testParameters() throws Exception {
    Similarity sim = getSimilarity("text_params");
    assertEquals(LMJelinekMercerSimilarity.class, sim.getClass());
    LMJelinekMercerSimilarity lm = (LMJelinekMercerSimilarity) sim;
    assertEquals(0.4f, lm.getLambda(), 0.01f);
}
Also used : Similarity(org.apache.lucene.search.similarities.Similarity) LMJelinekMercerSimilarity(org.apache.lucene.search.similarities.LMJelinekMercerSimilarity) LMJelinekMercerSimilarity(org.apache.lucene.search.similarities.LMJelinekMercerSimilarity)

Example 9 with Similarity

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

the class TestPerFieldSimilarity method testFactoryDynamic.

/** ... and for a dynamic field */
public void testFactoryDynamic() throws Exception {
    Similarity sim = getSimilarity("text_sim2");
    assertEquals(MockConfigurableSimilarity.class, sim.getClass());
    assertEquals("is there an echo?", ((MockConfigurableSimilarity) sim).getPassthrough());
}
Also used : Similarity(org.apache.lucene.search.similarities.Similarity) SweetSpotSimilarity(org.apache.lucene.misc.SweetSpotSimilarity) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity)

Example 10 with Similarity

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

the class TestBM25SimilarityFactory method testParameters.

/** bm25 with parameters */
public void testParameters() throws Exception {
    Similarity sim = getSimilarity("text_params");
    assertEquals(BM25Similarity.class, sim.getClass());
    BM25Similarity bm25 = (BM25Similarity) sim;
    assertEquals(1.2f, bm25.getK1(), 0.01f);
    assertEquals(0.76f, bm25.getB(), 0.01f);
}
Also used : Similarity(org.apache.lucene.search.similarities.Similarity) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity)

Aggregations

Similarity (org.apache.lucene.search.similarities.Similarity)48 BM25Similarity (org.apache.lucene.search.similarities.BM25Similarity)15 ClassicSimilarity (org.apache.lucene.search.similarities.ClassicSimilarity)15 Directory (org.apache.lucene.store.Directory)9 PerFieldSimilarityWrapper (org.apache.lucene.search.similarities.PerFieldSimilarityWrapper)8 SweetSpotSimilarity (org.apache.lucene.misc.SweetSpotSimilarity)7 IOException (java.io.IOException)6 Document (org.apache.lucene.document.Document)5 Term (org.apache.lucene.index.Term)5 IndexSearcher (org.apache.lucene.search.IndexSearcher)5 Collectors (java.util.stream.Collectors)4 IntStream (java.util.stream.IntStream)4 Field (org.apache.lucene.document.Field)4 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)4 NormValueSource (org.apache.lucene.queries.function.valuesource.NormValueSource)4 BytesRef (org.apache.lucene.util.BytesRef)4 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)3 Store (org.apache.lucene.document.Field.Store)3 IndexWriter (org.apache.lucene.index.IndexWriter)3 ConstValueSource (org.apache.lucene.queries.function.valuesource.ConstValueSource)3