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