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));
}
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());
}
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);
}
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;
}
Aggregations