### Question:
LuceneQueryBuilder extends AbstractNodeVisitor<LuceneQueryFactory<?>> { public Query createQuery(final querqy.model.Query query, final boolean useBooleanQueryForDMQ) { boolean tmp = this.useBooleanQueryForDMQ; try { this.useBooleanQueryForDMQ = useBooleanQueryForDMQ; return createQuery(query); } finally { this.useBooleanQueryForDMQ = tmp; } } LuceneQueryBuilder(final TermQueryBuilder termQueryBuilder, final Analyzer analyzer,
           final SearchFieldsAndBoosting searchFieldsAndBoosting,
           final float dmqTieBreakerMultiplier, final TermQueryCache termQueryCache);  LuceneQueryBuilder(final TermQueryBuilder termQueryBuilder, final Analyzer analyzer,
                              final SearchFieldsAndBoosting searchFieldsAndBoosting,
                              final float dmqTieBreakerMultiplier, final boolean normalizeBooleanQueryBoost,
                              final TermQueryCache termQueryCache); void reset(); Query createQuery(final querqy.model.Query query, final boolean useBooleanQueryForDMQ); Query createQuery(final QuerqyQuery<?> query); @Override LuceneQueryFactory<?> visit(final querqy.model.Query query); @Override LuceneQueryFactory<?> visit(final BooleanQuery booleanQuery); @Override LuceneQueryFactory<?> visit(final DisjunctionMaxQuery disjunctionMaxQuery); @Override LuceneQueryFactory<?> visit(final Term term);  }### Answer:
@Test public void testPurelyNegativeQueriesFromWhitespaceQuerqyParser() throws IOException { float tie = (float) Math.random(); Map<String, Float> fields = fields("f1", "f2"); SearchFieldsAndBoosting searchFieldsAndBoosting = new SearchFieldsAndBoosting(FieldBoostModel.FIXED, fields, fields, 0.8f); LuceneQueryBuilder builder = new LuceneQueryBuilder(new DependentTermQueryBuilder(new DocumentFrequencyCorrection()), keywordAnalyzer, searchFieldsAndBoosting, tie, null); Query q = builder.createQuery(new FieldAwareWhiteSpaceQuerqyParser().parse("-ab")); assertThat(q, bq( bq(Occur.MUST_NOT, dtq(Occur.SHOULD, 1f, "f1", "ab"), dtq(Occur.SHOULD, 2f, "f2", "ab") ) )); }
@Test public void testSynonymsWithRestrictedFieldsForGeneratedTerms() throws Exception { Map<String, Float> fieldsQuery = new HashMap<>(); fieldsQuery.put("f1", 2f); fieldsQuery.put("f2", 3f); Map<String, Float> fieldsGenerated = new HashMap<>(); fieldsGenerated.put("f1", 4f); SearchFieldsAndBoosting searchFieldsAndBoosting = new SearchFieldsAndBoosting(FieldBoostModel.FIXED, fieldsQuery, fieldsGenerated, 0.8f); LuceneQueryBuilder builder = new LuceneQueryBuilder(new DependentTermQueryBuilder(new DocumentFrequencyCorrection()), keywordAnalyzer, searchFieldsAndBoosting, 0.1f, null); WhiteSpaceQuerqyParser parser = new WhiteSpaceQuerqyParser(); querqy.model.Query q = parser.parse("a"); SimpleCommonRulesRewriterFactory factory = new SimpleCommonRulesRewriterFactory("CommonRulesRewriter", new BufferedReader(new InputStreamReader(Objects.requireNonNull( getClass().getClassLoader().getResourceAsStream("rules-synonyms.txt")), StandardCharsets.UTF_8)), new WhiteSpaceQuerqyParserFactory(), true, Collections.emptyMap(), (rewriterId, searchEngineRequestAdapter) -> SelectionStrategyFactory.DEFAULT_SELECTION_STRATEGY); ContextAwareQueryRewriter rewriter = (ContextAwareQueryRewriter) factory.createRewriter(null, searchEngineRequestAdapter); Query query = builder.createQuery(rewriter.rewrite(new ExpandedQuery(q), searchEngineRequestAdapter).getUserQuery()); assertThat(query, dmq(1f, 0.1f, dtq(2f, "f1", "a"), dtq(3f, "f2", "a"), dtq(4f, "f1", "x") )); }