### Question:
DependentTermQueryBuilder implements TermQueryBuilder { @Override public DependentTermQuery createTermQuery(final Term term, final FieldBoost boost) { return new DependentTermQuery(term, dfc, boost); } DependentTermQueryBuilder(final DocumentFrequencyCorrection dfc); @Override Optional<DocumentFrequencyCorrection> getDocumentFrequencyCorrection(); @Override DependentTermQuery createTermQuery(final Term term, final FieldBoost boost);  }### Answer:
@Test public void testCreateWeight() throws Exception { Analyzer analyzer = new StandardAnalyzer(); Directory directory = new ByteBuffersDirectory(); IndexWriterConfig config = new IndexWriterConfig(analyzer); config.setSimilarity(new ClassicSimilarity()); IndexWriter indexWriter = new IndexWriter(directory, config); TestUtil.addNumDocsWithTextField("f1", "v1", indexWriter, 4); TestUtil.addNumDocsWithTextField("f2", "v1 v1", indexWriter, 1); indexWriter.close(); IndexReader indexReader = DirectoryReader.open(directory); IndexSearcher indexSearcher = new IndexSearcher(indexReader); indexSearcher.setSimilarity(new ClassicSimilarity()); DocumentFrequencyCorrection dfc = new DocumentFrequencyCorrection(); Term qTerm1 = new Term("f1", "v1"); Term qTerm2 = new Term("f2", "v1"); dfc.newClause(); dfc.prepareTerm(qTerm1); dfc.prepareTerm(qTerm2); dfc.finishedUserQuery(); DependentTermQueryBuilder.DependentTermQuery query1 = new DependentTermQueryBuilder(dfc) .createTermQuery(qTerm1, fieldBoost1); DependentTermQueryBuilder.DependentTermQuery query2 = new DependentTermQueryBuilder(dfc) .createTermQuery(qTerm2, fieldBoost2); TopDocs topDocs = indexSearcher.search(query2, 10); final Weight weight2 = query2.createWeight(indexSearcher, ScoreMode.COMPLETE, 4.5f); final Explanation explain = weight2.explain(indexReader.leaves().get(0), topDocs.scoreDocs[0].doc); String explainText = explain.toString(); assertTrue(explainText.contains("9.0 = boost")); assertTrue(explainText.contains("4 = docFreq")); assertTrue(explainText.contains("2.0 = freq")); indexReader.close(); directory.close(); analyzer.close(); }
@Test public void testPostingsVsMaxScore() throws Exception { Analyzer analyzer = new StandardAnalyzer(); Directory directory = new ByteBuffersDirectory(); IndexWriterConfig config = new IndexWriterConfig(analyzer); config.setSimilarity(new ClassicSimilarity()); IndexWriter indexWriter = new IndexWriter(directory, config); TestUtil.addNumDocsWithTextField("f1", "v1", indexWriter, 1); TestUtil.addNumDocsWithTextField("f2", "v1 v2", indexWriter, 1); indexWriter.close(); IndexReader indexReader = DirectoryReader.open(directory); IndexSearcher indexSearcher = new IndexSearcher(indexReader); indexSearcher.setSimilarity(new ClassicSimilarity()); DocumentFrequencyCorrection dfc = new DocumentFrequencyCorrection(); Term qTerm1 = new Term("f2", "v1"); Term qTerm2 = new Term("f2", "v2"); dfc.newClause(); dfc.prepareTerm(qTerm1); dfc.newClause(); dfc.prepareTerm(qTerm2); dfc.finishedUserQuery(); DependentTermQueryBuilder.DependentTermQuery query1 = new DependentTermQueryBuilder(dfc) .createTermQuery(qTerm1, fieldBoost1); DependentTermQueryBuilder.DependentTermQuery query2 = new DependentTermQueryBuilder(dfc) .createTermQuery(qTerm2, fieldBoost2); BooleanQuery.Builder builder = new BooleanQuery.Builder(); builder.add(query1, BooleanClause.Occur.SHOULD); builder.add(query2, BooleanClause.Occur.SHOULD); builder.setMinimumNumberShouldMatch(2); BooleanQuery bq = builder.build(); TopDocs topDocs = indexSearcher.search(bq, 10); assertEquals(1, topDocs.scoreDocs.length); }