Search in sources :

Example 1 with IBSimilarity

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

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

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

the class TestIBSimilarityFactory method test.

/** spl/df/h2 with default parameters */
public void test() throws Exception {
    Similarity sim = getSimilarity("text");
    assertEquals(IBSimilarity.class, sim.getClass());
    IBSimilarity ib = (IBSimilarity) sim;
    assertEquals(DistributionSPL.class, ib.getDistribution().getClass());
    assertEquals(LambdaDF.class, ib.getLambda().getClass());
    assertEquals(NormalizationH2.class, ib.getNormalization().getClass());
}
Also used : Similarity(org.apache.lucene.search.similarities.Similarity) IBSimilarity(org.apache.lucene.search.similarities.IBSimilarity) IBSimilarity(org.apache.lucene.search.similarities.IBSimilarity)

Example 4 with IBSimilarity

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

the class IBSimilarityFactory method getSimilarity.

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

Aggregations

IBSimilarity (org.apache.lucene.search.similarities.IBSimilarity)4 Similarity (org.apache.lucene.search.similarities.Similarity)2 DistributionSPL (org.apache.lucene.search.similarities.DistributionSPL)1 LambdaTTF (org.apache.lucene.search.similarities.LambdaTTF)1 NormalizationH2 (org.apache.lucene.search.similarities.NormalizationH2)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