public void testThatMainQueryIsNotMarkedAsGenerated() { RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false); BoostInstruction boostInstruction = new BoostInstruction(makeQuery("-a b").getUserQuery(), BoostDirection.UP, 0.5f); builder.addRule(new Input(Arrays.asList(mkTerm("x")), false, false), new Instructions(Arrays.asList((Instruction) boostInstruction))); RulesCollection rules = builder.build(); CommonRulesRewriter rewriter = new CommonRulesRewriter(rules); ExpandedQuery query = makeQuery("x"); QuerqyQuery<?> mainQuery = rewriter.rewrite(query, EMPTY_CONTEXT).getUserQuery(); assertFalse(mainQuery.isGenerated()); }
@Test public void testThatBoostQueriesAreMarkedAsGenerated() { RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false); BoostInstruction boostInstruction = new BoostInstruction(makeQuery("a").getUserQuery(), BoostDirection.UP, 0.5f); builder.addRule(new Input(Arrays.asList(mkTerm("x")), false, false), new Instructions(Arrays.asList((Instruction) boostInstruction))); RulesCollection rules = builder.build(); CommonRulesRewriter rewriter = new CommonRulesRewriter(rules); ExpandedQuery query = makeQuery("x"); Collection<BoostQuery> upQueries = rewriter.rewrite(query, EMPTY_CONTEXT).getBoostUpQueries(); assertThat(upQueries, contains( boostQ( bq( dmq(must(), term("a", true)) ), 0.5f ))); }
@Test public void testThatUpQueriesAreOfTypeQuery() throws Exception { RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false); BoostInstruction boostInstruction = new BoostInstruction(makeQuery("a b").getUserQuery(), BoostDirection.UP, 0.5f); builder.addRule(new Input(Arrays.asList(mkTerm("x")), false, false), new Instructions(Arrays.asList((Instruction) boostInstruction))); RulesCollection rules = builder.build(); CommonRulesRewriter rewriter = new CommonRulesRewriter(rules); ExpandedQuery query = makeQuery("x"); Collection<BoostQuery> upQueries = rewriter.rewrite(query, EMPTY_CONTEXT).getBoostUpQueries(); for (BoostQuery bq : upQueries) { Assert.assertTrue(bq.getQuery() instanceof Query); } }
@Test public void testThatBoostQueriesUseMM100ByDefault() { RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false); BoostInstruction boostInstruction = new BoostInstruction(makeQuery("a b").getUserQuery(), BoostDirection.UP, 0.5f); builder.addRule(new Input(Arrays.asList(mkTerm("x")), false, false), new Instructions(Arrays.asList((Instruction) boostInstruction))); RulesCollection rules = builder.build(); CommonRulesRewriter rewriter = new CommonRulesRewriter(rules); ExpandedQuery query = makeQuery("x"); Collection<BoostQuery> upQueries = rewriter.rewrite(query, EMPTY_CONTEXT).getBoostUpQueries(); assertThat(upQueries, contains( boostQ( bq( dmq(must(), term("a", true)), dmq(must(), term("b", true)) ), 0.5f ))); }
@Test public void testThatBoostQueriesWithMustNotClauseUseMM100ByDefault() { RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false); BoostInstruction boostInstruction = new BoostInstruction(makeQuery("-a b").getUserQuery(), BoostDirection.UP, 0.5f); builder.addRule(new Input(Arrays.asList(mkTerm("x")), false, false), new Instructions(Arrays.asList((Instruction) boostInstruction))); RulesCollection rules = builder.build(); CommonRulesRewriter rewriter = new CommonRulesRewriter(rules); ExpandedQuery query = makeQuery("x"); Collection<BoostQuery> upQueries = rewriter.rewrite(query, EMPTY_CONTEXT).getBoostUpQueries(); assertThat(upQueries, contains( boostQ( bq( dmq(mustNot(), term("a", true)), dmq(must(), term("b", true)) ), 0.5f ))); }
@Test public void testThatBoostQueriesWithMustClauseUseMM100ByDefault() { RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false); BoostInstruction boostInstruction = new BoostInstruction(makeQuery("a +b").getUserQuery(), BoostDirection.UP, 0.5f); builder.addRule(new Input(Arrays.asList(mkTerm("x")), false, false), new Instructions(Arrays.asList((Instruction) boostInstruction))); RulesCollection rules = builder.build(); CommonRulesRewriter rewriter = new CommonRulesRewriter(rules); ExpandedQuery query = makeQuery("x"); Collection<BoostQuery> upQueries = rewriter.rewrite(query, EMPTY_CONTEXT).getBoostUpQueries(); assertThat(upQueries, contains( boostQ( bq( dmq(must(), term("a", true)), dmq(must(), term("b", true)) ), 0.5f ))); }