org.apache.lucene.search.similarities.DFISimilarity Java Examples

The following examples show how to use org.apache.lucene.search.similarities.DFISimilarity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DFISimilarityProvider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public DFISimilarityProvider(@Assisted String name, @Assisted Settings settings) {
    super(name);
    boolean discountOverlaps = settings.getAsBoolean("discount_overlaps", true);
    Independence measure = parseIndependence(settings);
    this.similarity = new DFISimilarity(measure);
    this.similarity.setDiscountOverlaps(discountOverlaps);
}
 
Example #2
Source File: TestDFISimilarityFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: TestDFISimilarityFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #4
Source File: LtrQueryTests.java    From elasticsearch-learning-to-rank with Apache License 2.0 5 votes vote down vote up
@Before
public void setupIndex() throws IOException {
    dirUnderTest = newDirectory();
    List<Similarity> sims = Arrays.asList(
            new ClassicSimilarity(),
            new SweetSpotSimilarity(), // extends Classic
            new BM25Similarity(),
            new LMDirichletSimilarity(),
            new BooleanSimilarity(),
            new LMJelinekMercerSimilarity(0.2F),
            new AxiomaticF3LOG(0.5F, 10),
            new DFISimilarity(new IndependenceChiSquared()),
            new DFRSimilarity(new BasicModelG(), new AfterEffectB(), new NormalizationH1()),
            new IBSimilarity(new DistributionLL(), new LambdaDF(), new NormalizationH3())
        );
    similarity = sims.get(random().nextInt(sims.size()));

    indexWriterUnderTest = new RandomIndexWriter(random(), dirUnderTest, newIndexWriterConfig().setSimilarity(similarity));
    for (int i = 0; i < docs.length; i++) {
        Document doc = new Document();
        doc.add(newStringField("id", "" + i, Field.Store.YES));
        doc.add(newField("field", docs[i], Store.YES));
        indexWriterUnderTest.addDocument(doc);
    }
    indexWriterUnderTest.commit();
    indexWriterUnderTest.forceMerge(1);
    indexWriterUnderTest.flush();


    indexReaderUnderTest = indexWriterUnderTest.getReader();
    searcherUnderTest = newSearcher(indexReaderUnderTest);
    searcherUnderTest.setSimilarity(similarity);
}
 
Example #5
Source File: DFISimilarityFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public Similarity getSimilarity() {
  DFISimilarity sim = new DFISimilarity(independenceMeasure);
  sim.setDiscountOverlaps(discountOverlaps);
  return sim;
}