Search in sources :

Example 1 with LMJelinekMercerSimilarity

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

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

the class LMJelinekMercerSimilarityFactory method getSimilarity.

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

Example 3 with LMJelinekMercerSimilarity

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

the class SimilarityTests method testResolveSimilaritiesFromMapping_LMJelinekMercer.

public void testResolveSimilaritiesFromMapping_LMJelinekMercer() 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", "LMJelinekMercer").put("index.similarity.my_similarity.lambda", 0.7f).build();
    IndexService indexService = createIndex("foo", indexSettings);
    DocumentMapper documentMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    assertThat(documentMapper.mappers().getMapper("field1").fieldType().similarity(), instanceOf(LMJelinekMercerSimilarityProvider.class));
    LMJelinekMercerSimilarity similarity = (LMJelinekMercerSimilarity) documentMapper.mappers().getMapper("field1").fieldType().similarity().get();
    assertThat(similarity.getLambda(), equalTo(0.7f));
}
Also used : IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) LMJelinekMercerSimilarity(org.apache.lucene.search.similarities.LMJelinekMercerSimilarity) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

LMJelinekMercerSimilarity (org.apache.lucene.search.similarities.LMJelinekMercerSimilarity)3 Similarity (org.apache.lucene.search.similarities.Similarity)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