/** * Tests if the ConstantScore filter rewrite return an exception */ @Test(expected=UnsupportedOperationException.class) public void testFilterRewrite() throws IOException { this.addDocument("<nowildcard> <nowildcardx>"); final MultiNodeTermQuery wq = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "nowildcard")); this.assertMatches(searcher, wq, 1); wq.setRewriteMethod(MultiNodeTermQuery.CONSTANT_SCORE_FILTER_REWRITE); wq.setBoost(0.2F); searcher.rewrite(wq); }
wq.setBoost(0.1F); expected.setRewriteMethod(wq.getRewriteMethod()); expected.setBoost(wq.getBoost()); assertEquals(searcher.rewrite(expected), searcher.rewrite(wq)); wq.setBoost(0.3F); expected.setRewriteMethod(wq.getRewriteMethod()); expected.setBoost(wq.getBoost()); assertEquals(searcher.rewrite(expected), searcher.rewrite(wq)); wq.setBoost(0.4F); expected.setRewriteMethod(wq.getRewriteMethod()); expected.setBoost(wq.getBoost()); assertEquals(searcher.rewrite(expected), searcher.rewrite(wq));
/** * Tests if a SirenWildcardQuery that has no wildcard in the term is rewritten to a single * TermQuery. The boost should be preserved, and the rewrite should return * a SirenConstantScoreQuery if the SirenWildcardQuery had a ConstantScore rewriteMethod. */ public void testTermWithoutWildcard() throws IOException { this.addDocument("<nowildcard> <nowildcardx>"); final MultiNodeTermQuery wq = new NodeWildcardQuery(new Term(DEFAULT_TEST_FIELD, "nowildcard")); this.assertMatches(searcher, wq, 1); wq.setRewriteMethod(MultiNodeTermQuery.SCORING_BOOLEAN_QUERY_REWRITE); wq.setBoost(0.1F); Query q = searcher.rewrite(wq); assertTrue(q instanceof NodeTermQuery); assertEquals(q.getBoost(), wq.getBoost(), 0); wq.setRewriteMethod(MultiNodeTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT); wq.setBoost(0.3F); q = searcher.rewrite(wq); assertTrue(q instanceof NodeConstantScoreQuery); assertEquals(q.getBoost(), wq.getBoost(), 0.1); wq.setRewriteMethod(MultiNodeTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE); wq.setBoost(0.4F); q = searcher.rewrite(wq); assertTrue(q instanceof NodeConstantScoreQuery); assertEquals(q.getBoost(), wq.getBoost(), 0.1); }