use of org.apache.lucene.search.similarities.DFRSimilarity in project lucene-solr by apache.
the class TestDFRSimilarityFactory method testParameters.
/** dfr with parametrized normalization */
public void testParameters() throws Exception {
Similarity sim = getSimilarity("text_params");
assertEquals(DFRSimilarity.class, sim.getClass());
DFRSimilarity dfr = (DFRSimilarity) sim;
assertEquals(BasicModelIF.class, dfr.getBasicModel().getClass());
assertEquals(AfterEffectB.class, dfr.getAfterEffect().getClass());
assertEquals(NormalizationH3.class, dfr.getNormalization().getClass());
NormalizationH3 norm = (NormalizationH3) dfr.getNormalization();
assertEquals(900f, norm.getMu(), 0.01f);
}
use of org.apache.lucene.search.similarities.DFRSimilarity in project lucene-solr by apache.
the class DFRSimilarityFactory method getSimilarity.
@Override
public Similarity getSimilarity() {
DFRSimilarity sim = new DFRSimilarity(basicModel, afterEffect, normalization);
sim.setDiscountOverlaps(discountOverlaps);
return sim;
}
use of org.apache.lucene.search.similarities.DFRSimilarity 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));
}
use of org.apache.lucene.search.similarities.DFRSimilarity in project lucene-solr by apache.
the class TestDFRSimilarityFactory method test.
/** dfr with default parameters */
public void test() throws Exception {
Similarity sim = getSimilarity("text");
assertEquals(DFRSimilarity.class, sim.getClass());
DFRSimilarity dfr = (DFRSimilarity) sim;
assertEquals(BasicModelIF.class, dfr.getBasicModel().getClass());
assertEquals(AfterEffectB.class, dfr.getAfterEffect().getClass());
assertEquals(NormalizationH2.class, dfr.getNormalization().getClass());
}
use of org.apache.lucene.search.similarities.DFRSimilarity 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);
}
Aggregations