Search in sources :

Example 1 with DFRSimilarity

use of org.apache.lucene.search.similarities.DFRSimilarity 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 2 with DFRSimilarity

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

the class DFRSimilarityFactory method getSimilarity.

@Override
public Similarity getSimilarity() {
    DFRSimilarity sim = new DFRSimilarity(basicModel, afterEffect, normalization);
    sim.setDiscountOverlaps(discountOverlaps);
    return sim;
}
Also used : DFRSimilarity(org.apache.lucene.search.similarities.DFRSimilarity)

Example 3 with DFRSimilarity

use of org.apache.lucene.search.similarities.DFRSimilarity in project elasticsearch by elastic.

the class SimilarityTests method testResolveSimilaritiesFromMapping_DFR.

public void testResolveSimilaritiesFromMapping_DFR() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field1").field("type", "text").field("similarity", "my_similarity").endObject().endObject().endObject().endObject().string();
    Settings indexSettings = Settings.builder().put("index.similarity.my_similarity.type", "DFR").put("index.similarity.my_similarity.basic_model", "g").put("index.similarity.my_similarity.after_effect", "l").put("index.similarity.my_similarity.normalization", "h2").put("index.similarity.my_similarity.normalization.h2.c", 3f).build();
    IndexService indexService = createIndex("foo", indexSettings);
    DocumentMapper documentMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity(), instanceOf(DFRSimilarityProvider.class));
    DFRSimilarity similarity = (DFRSimilarity) documentMapper.mappers().getMapper("field1").fieldType().similarity().get();
    assertThat(similarity.getBasicModel(), instanceOf(BasicModelG.class));
    assertThat(similarity.getAfterEffect(), instanceOf(AfterEffectL.class));
    assertThat(similarity.getNormalization(), instanceOf(NormalizationH2.class));
    assertThat(((NormalizationH2) similarity.getNormalization()).getC(), equalTo(3f));
}
Also used : BasicModelG(org.apache.lucene.search.similarities.BasicModelG) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) NormalizationH2(org.apache.lucene.search.similarities.NormalizationH2) DFRSimilarity(org.apache.lucene.search.similarities.DFRSimilarity) Settings(org.elasticsearch.common.settings.Settings) AfterEffectL(org.apache.lucene.search.similarities.AfterEffectL)

Example 4 with DFRSimilarity

use of org.apache.lucene.search.similarities.DFRSimilarity 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());
}
Also used : DFRSimilarity(org.apache.lucene.search.similarities.DFRSimilarity) Similarity(org.apache.lucene.search.similarities.Similarity) DFRSimilarity(org.apache.lucene.search.similarities.DFRSimilarity)

Example 5 with DFRSimilarity

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

the class TestDFRSimilarityFactory method testParameterC.

/** LUCENE-3566 */
public void testParameterC() throws Exception {
    Similarity sim = getSimilarity("text_paramc");
    assertEquals(DFRSimilarity.class, sim.getClass());
    DFRSimilarity dfr = (DFRSimilarity) sim;
    assertEquals(BasicModelP.class, dfr.getBasicModel().getClass());
    assertEquals(AfterEffectL.class, dfr.getAfterEffect().getClass());
    assertEquals(NormalizationH2.class, dfr.getNormalization().getClass());
    NormalizationH2 norm = (NormalizationH2) dfr.getNormalization();
    assertEquals(7f, norm.getC(), 0.01f);
}
Also used : DFRSimilarity(org.apache.lucene.search.similarities.DFRSimilarity) Similarity(org.apache.lucene.search.similarities.Similarity) NormalizationH2(org.apache.lucene.search.similarities.NormalizationH2) DFRSimilarity(org.apache.lucene.search.similarities.DFRSimilarity)

Aggregations

DFRSimilarity (org.apache.lucene.search.similarities.DFRSimilarity)5 Similarity (org.apache.lucene.search.similarities.Similarity)3 NormalizationH2 (org.apache.lucene.search.similarities.NormalizationH2)2 AfterEffectL (org.apache.lucene.search.similarities.AfterEffectL)1 BasicModelG (org.apache.lucene.search.similarities.BasicModelG)1 NormalizationH3 (org.apache.lucene.search.similarities.NormalizationH3)1 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)1 Settings (org.elasticsearch.common.settings.Settings)1 IndexService (org.elasticsearch.index.IndexService)1 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)1