Exemplo n.º 1
0
  @Test
  public void testThatTermIsRemovedIfThereASecondDMQWithoutTheTerm() throws Exception {
    RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false);
    DeleteInstruction delete = new DeleteInstruction(Arrays.asList(mkTerm("a")));
    builder.addRule(
        new Input(Arrays.asList(mkTerm("a")), false, false),
        new Instructions(Arrays.asList((Instruction) delete)));
    RulesCollection rules = builder.build();
    CommonRulesRewriter rewriter = new CommonRulesRewriter(rules);

    Query rewritten = rewriter.rewrite(makeQuery("a b"), EMPTY_CONTEXT).getUserQuery();

    assertThat(rewritten, bq(dmq(term("b"))));
  }
Exemplo n.º 2
0
  @Test
  public void testThatNothingIsDeletedIfWeWouldEndUpWithAnEmptyQuery() {

    RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false);
    DeleteInstruction delete = new DeleteInstruction(Arrays.asList(mkTerm("a")));
    builder.addRule(
        new Input(Arrays.asList(mkTerm("a")), false, false),
        new Instructions(Arrays.asList((Instruction) delete)));
    RulesCollection rules = builder.build();
    CommonRulesRewriter rewriter = new CommonRulesRewriter(rules);

    ExpandedQuery query = makeQuery("a");
    Query rewritten = rewriter.rewrite(query, EMPTY_CONTEXT).getUserQuery();

    assertThat(rewritten, bq(dmq(term("a"))));
  }
Exemplo n.º 3
0
  @Test
  public void testThatTermIsRemovedIfThereIsAnotherTermInTheSameDMQ() throws Exception {
    RulesCollectionBuilder builder = new TrieMapRulesCollectionBuilder(false);
    DeleteInstruction delete = new DeleteInstruction(Arrays.asList(mkTerm("a")));
    builder.addRule(
        new Input(Arrays.asList(mkTerm("a")), false, false),
        new Instructions(Arrays.asList((Instruction) delete)));
    RulesCollection rules = builder.build();
    CommonRulesRewriter rewriter = new CommonRulesRewriter(rules);

    ExpandedQuery expandedQuery = makeQuery("a");
    Query query = expandedQuery.getUserQuery();

    DisjunctionMaxQuery dmq = query.getClauses(DisjunctionMaxQuery.class).get(0);
    querqy.model.Term termB = new querqy.model.Term(dmq, null, "b");
    dmq.addClause(termB);

    Query rewritten = rewriter.rewrite(expandedQuery, EMPTY_CONTEXT).getUserQuery();

    assertThat(rewritten, bq(dmq(term("b"))));
  }