if (!query.getClauses().isEmpty()) { for (Input input : inputs) { BoostInstruction bi = new BoostInstruction(query, direction, boost); builder.addRule(input, new Instructions(Collections.singletonList((Instruction) bi)));
return new BoostInstruction( new RawQuery(null, rawQuery, Occur.SHOULD, false), direction, boost); return new BoostInstruction(parser.parse(boostLine), direction, boost);
@Test public void test04() throws Exception { RulesCollection rules = createRulesFromResource("rules-test.txt", false); Term t1 = new Term(null, "t1"); Term t2 = new Term(null, "t2"); PositionSequence<InputSequenceElement> seq = new PositionSequence<>(); seq.nextPosition(); seq.addElement(t1); seq.nextPosition(); seq.addElement(t2); List<Action> actions = rules.getRewriteActions(seq); assertThat(actions, contains( new Action( Arrays.asList( new Instructions( Arrays.asList( (Instruction) new BoostInstruction(makeQueryUsingFactory("tboost tb2"), BoostDirection.UP, 3.5f)) )), new TermMatches(Arrays.asList(new TermMatch(t1), new TermMatch(t2))), 0, 2) )); }
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 ))); }
@Test public void testThatDownQueriesAreOfTypeQuery() throws Exception { RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false); BoostInstruction boostInstruction = new BoostInstruction(makeQuery("a b$1").getUserQuery(), BoostDirection.DOWN, 0.2f); builder.addRule((Input) LineParser.parseInput("x k*"), new Instructions(Collections.singletonList((Instruction) boostInstruction))); RulesCollection rules = builder.build(); CommonRulesRewriter rewriter = new CommonRulesRewriter(rules); ExpandedQuery query = makeQuery("x klm y"); Collection<BoostQuery> downQueries = rewriter.rewrite(query, EMPTY_CONTEXT).getBoostDownQueries(); for (BoostQuery bq : downQueries) { Assert.assertTrue(bq.getQuery() instanceof Query); } }
@Test public void testThatPlaceHolderGetsReplacedAsASeperateToken() throws Exception { RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false); BoostInstruction boostInstruction = new BoostInstruction(makeQuery("a $1").getUserQuery(), BoostDirection.DOWN, 0.3f); builder.addRule((Input) LineParser.parseInput("x k*"), new Instructions(Collections.singletonList((Instruction) boostInstruction))); RulesCollection rules = builder.build(); CommonRulesRewriter rewriter = new CommonRulesRewriter(rules); ExpandedQuery query = makeQuery("x klm y"); Collection<BoostQuery> downQueries = rewriter.rewrite(query, EMPTY_CONTEXT).getBoostDownQueries(); assertThat(downQueries, contains( boostQ( bq( dmq(must(), term("a", true)), dmq(must(), term("lm", true)) ), 0.3f ))); }
@Test public void testThatPlaceHolderGetsReplaced() throws Exception { RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false); BoostInstruction boostInstruction = new BoostInstruction(makeQuery("a b$1").getUserQuery(), BoostDirection.DOWN, 0.2f); builder.addRule((Input) LineParser.parseInput("x k*"), new Instructions(Collections.singletonList((Instruction) boostInstruction))); RulesCollection rules = builder.build(); CommonRulesRewriter rewriter = new CommonRulesRewriter(rules); ExpandedQuery query = makeQuery("x klm y"); Collection<BoostQuery> downQueries = rewriter.rewrite(query, EMPTY_CONTEXT).getBoostDownQueries(); assertThat(downQueries, contains( boostQ( bq( dmq(must(), term("a", true)), dmq(must(), term("blm", true)) ), 0.2f ))); }
BoostInstruction boostInstruction = new BoostInstruction(makeQuery("a c$1d").getUserQuery(), BoostDirection.UP, 0.3f);
new Instructions( Arrays.asList( (Instruction) new BoostInstruction( new RawQuery(null, "color:x", Occur.SHOULD, false), BoostDirection.DOWN ,2f)))), new TermMatches(new TermMatch(t1)), 0, 1),