### Question:
SpanRewriter { public Query rewrite(Query in, IndexSearcher searcher) throws RewriteException, IOException { if (in instanceof SpanOffsetReportingQuery) return in; if (in instanceof SpanQuery) return forceOffsets((SpanQuery)in); if (in instanceof ForceNoBulkScoringQuery) { return new ForceNoBulkScoringQuery(rewrite(((ForceNoBulkScoringQuery) in).getWrappedQuery(), searcher)); } if (in instanceof TermQuery) return rewriteTermQuery((TermQuery)in); if (in instanceof BooleanQuery) return rewriteBoolean((BooleanQuery) in, searcher); if (in instanceof MultiTermQuery) return rewriteMultiTermQuery((MultiTermQuery)in); if (in instanceof DisjunctionMaxQuery) return rewriteDisjunctionMaxQuery((DisjunctionMaxQuery) in, searcher); if (in instanceof TermInSetQuery) return rewriteTermInSetQuery((TermInSetQuery) in); if (in instanceof BoostQuery) return rewrite(((BoostQuery) in).getQuery(), searcher); if (in instanceof PhraseQuery) return rewritePhraseQuery((PhraseQuery)in); if (in instanceof ConstantScoreQuery) return rewrite(((ConstantScoreQuery) in).getQuery(), searcher); if (searcher != null) { return rewrite(searcher.rewrite(in), null); } return rewriteUnknown(in); }  Query rewrite(Query in, IndexSearcher searcher); static final SpanRewriter INSTANCE; }### Answer:
@Test public void testBoostQuery() throws Exception { Query q = new SpanRewriter().rewrite(new BoostQuery(new TermQuery(new Term("f", "t")), 2.0f), null); assertThat(q).isInstanceOf(SpanOffsetReportingQuery.class); }
@Test public void testMultiTermQueryEquals() throws Exception { WildcardQuery wq = new WildcardQuery(new Term("field", "term")); Query q1 = new SpanRewriter().rewrite(wq, null); Query q2 = new SpanRewriter().rewrite(wq, null); assertThat(q1).isEqualTo(q2); }
@Test public void testPhraseQuery() throws Exception { PhraseQuery pq = new PhraseQuery(1, "field1", "term1", "term2"); Query q = new SpanRewriter().rewrite(pq, null); assertThat(q).isInstanceOf(SpanOffsetReportingQuery.class); SpanOffsetReportingQuery or = (SpanOffsetReportingQuery) q; assertThat(or.getWrappedQuery()).isInstanceOf(SpanNearQuery.class); SpanNearQuery sq = (SpanNearQuery) or.getWrappedQuery(); assertThat(sq.getClauses()).contains(new SpanTermQuery(new Term("field1", "term1")), new SpanTermQuery(new Term("field1", "term2"))); assertThat(sq.getSlop()).isEqualTo(1); }
@Test public void testConstantScoreQuery() throws Exception { Query q = new ConstantScoreQuery(new TermQuery(new Term("field", "term"))); Query rewritten = new SpanRewriter().rewrite(q, null); assertThat(rewritten).isInstanceOf(SpanOffsetReportingQuery.class); }