Ejemplo n.º 1
0
 @Override
 public Object visit(PropertyIsLike filter, Object extraData) {
   checkExpressionIsProperty(filter.getExpression());
   StringWriter output = asStringWriter(extraData);
   String pattern = escapeSpecialCharacters(filter.getLiteral(), filter.getEscape());
   pattern = pattern.replace(filter.getWildCard(), ".*");
   pattern = pattern.replace(filter.getSingleChar(), ".{1,1}");
   Expression expr = filter.getExpression();
   ExpressionToSolr visitor = new ExpressionToSolr();
   expr.accept(visitor, output);
   output.append(":/");
   output.append(pattern);
   output.append("/ ");
   return output;
 }
  @Test
  public void testLikeFilter() throws Exception {
    final String wildcard = "%";
    final String single = "?";
    final String escape = "\\";
    PropertyIsLike like =
        ff.like(
            ff.property("/measurement/determinand_description"),
            "%n_1_1",
            wildcard,
            single,
            escape,
            true,
            MatchAction.ONE);

    PropertyIsLike unmapped = (PropertyIsLike) like.accept(visitor, null);
    assertEquals(like.getLiteral(), unmapped.getLiteral());
    assertEquals(like.getWildCard(), unmapped.getWildCard());
    assertEquals(like.getSingleChar(), unmapped.getSingleChar());
    assertEquals(like.getEscape(), unmapped.getEscape());
    assertEquals(like.isMatchingCase(), unmapped.isMatchingCase());
    assertEquals(like.getMatchAction(), unmapped.getMatchAction());

    Expression unmappedExpr = unmapped.getExpression();
    assertTrue(unmappedExpr instanceof PropertyName);
    assertEquals("determinand_description", ((PropertyName) unmappedExpr).getPropertyName());
  }
 @Override
 public Object visit(PropertyIsLike filter, Object extraData) {
   Expression expr = (Expression) filter.getExpression().accept(this, extraData);
   String pattern = filter.getLiteral();
   String wildcard = filter.getWildCard();
   String singleChar = filter.getSingleChar();
   String escape = filter.getEscape();
   return getFactory(extraData).like(expr, pattern, wildcard, singleChar, escape, false);
 }
  public Object visit(PropertyIsLike filter, Object notUsed) {
    if (original == null) original = filter;

    if (!fcs.supports(PropertyIsLike.class)) {
      postStack.push(filter);

      return null;
    }

    int i = postStack.size();
    filter.getExpression().accept(this, null);

    if (i < postStack.size()) {
      postStack.pop();
      postStack.push(filter);

      return null;
    }

    preStack.pop(); // value
    preStack.push(filter);
    return null;
  }