Search in sources :

Example 1 with DFISimilarity

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

the class SimilarityTests method testResolveSimilaritiesFromMapping_DFI.

public void testResolveSimilaritiesFromMapping_DFI() 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", "DFI").put("index.similarity.my_similarity.independence_measure", "chisquared").build();
    IndexService indexService = createIndex("foo", indexSettings);
    DocumentMapper documentMapper = indexService.mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    MappedFieldType fieldType = documentMapper.mappers().getMapper("field1").fieldType();
    assertThat(fieldType.similarity(), instanceOf(DFISimilarityProvider.class));
    DFISimilarity similarity = (DFISimilarity) fieldType.similarity().get();
    assertThat(similarity.getIndependence(), instanceOf(IndependenceChiSquared.class));
}
Also used : IndexService(org.elasticsearch.index.IndexService) DFISimilarity(org.apache.lucene.search.similarities.DFISimilarity) IndependenceChiSquared(org.apache.lucene.search.similarities.IndependenceChiSquared) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Settings(org.elasticsearch.common.settings.Settings)

Example 2 with DFISimilarity

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

the class TestDFISimilarityFactory method testParameters.

/**
   * dfi with discountOverlaps parameter set to false
   */
public void testParameters() throws Exception {
    Similarity sim = getSimilarity("text_params");
    assertEquals(DFISimilarity.class, sim.getClass());
    DFISimilarity dfr = (DFISimilarity) sim;
    assertFalse(dfr.getDiscountOverlaps());
}
Also used : DFISimilarity(org.apache.lucene.search.similarities.DFISimilarity) Similarity(org.apache.lucene.search.similarities.Similarity) DFISimilarity(org.apache.lucene.search.similarities.DFISimilarity)

Example 3 with DFISimilarity

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

the class TestDFISimilarityFactory method test.

/**
   * dfi with no parameters
   */
public void test() throws Exception {
    Similarity sim = getSimilarity("text");
    assertEquals(DFISimilarity.class, sim.getClass());
    DFISimilarity dfi = (DFISimilarity) sim;
    assertTrue(dfi.getDiscountOverlaps());
    assertTrue(dfi.getIndependence() instanceof IndependenceChiSquared);
}
Also used : DFISimilarity(org.apache.lucene.search.similarities.DFISimilarity) Similarity(org.apache.lucene.search.similarities.Similarity) DFISimilarity(org.apache.lucene.search.similarities.DFISimilarity) IndependenceChiSquared(org.apache.lucene.search.similarities.IndependenceChiSquared)

Example 4 with DFISimilarity

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

the class DFISimilarityFactory method getSimilarity.

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

Aggregations

DFISimilarity (org.apache.lucene.search.similarities.DFISimilarity)4 IndependenceChiSquared (org.apache.lucene.search.similarities.IndependenceChiSquared)2 Similarity (org.apache.lucene.search.similarities.Similarity)2 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 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)1