Search in sources :

Example 1 with NormalizationH2

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

the class SimilarityTests method testResolveSimilaritiesFromMapping_IB.

public void testResolveSimilaritiesFromMapping_IB() 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", "IB").put("index.similarity.my_similarity.distribution", "spl").put("index.similarity.my_similarity.lambda", "ttf").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(IBSimilarityProvider.class));
    IBSimilarity similarity = (IBSimilarity) documentMapper.mappers().getMapper("field1").fieldType().similarity().get();
    assertThat(similarity.getDistribution(), instanceOf(DistributionSPL.class));
    assertThat(similarity.getLambda(), instanceOf(LambdaTTF.class));
    assertThat(similarity.getNormalization(), instanceOf(NormalizationH2.class));
    assertThat(((NormalizationH2) similarity.getNormalization()).getC(), equalTo(3f));
}
Also used : IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) DistributionSPL(org.apache.lucene.search.similarities.DistributionSPL) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) NormalizationH2(org.apache.lucene.search.similarities.NormalizationH2) IBSimilarity(org.apache.lucene.search.similarities.IBSimilarity) LambdaTTF(org.apache.lucene.search.similarities.LambdaTTF) Settings(org.elasticsearch.common.settings.Settings)

Example 2 with NormalizationH2

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

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

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