コード例 #1
0
ファイル: GrammarTreeTest.java プロジェクト: Kuew/usergrid
  @Test
  public void selectDistance() throws RecognitionException {
    String queryString = "select * where a contains 'foo'";

    ANTLRStringStream in = new ANTLRStringStream(queryString);
    QueryFilterLexer lexer = new QueryFilterLexer(in);
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    QueryFilterParser parser = new QueryFilterParser(tokens);

    Query query = parser.ql().query;

    ContainsOperand operand = (ContainsOperand) query.getRootOperand();

    assertEquals("a", operand.getProperty().getValue());
    assertEquals("foo", operand.getString().getValue());
  }
コード例 #2
0
ファイル: GrammarTreeTest.java プロジェクト: Kuew/usergrid
  @Test
  public void containsOr() throws Exception {
    String queryString = "select * where keywords contains 'hot' or title contains 'hot'";

    ANTLRStringStream in = new ANTLRStringStream(queryString);
    QueryFilterLexer lexer = new QueryFilterLexer(in);
    TokenRewriteStream tokens = new TokenRewriteStream(lexer);
    QueryFilterParser parser = new QueryFilterParser(tokens);

    Query query = parser.ql().query;

    OrOperand rootNode = (OrOperand) query.getRootOperand();

    assertNotNull(rootNode);

    ContainsOperand left = (ContainsOperand) rootNode.getLeft();

    assertEquals("keywords", left.getProperty().getValue());

    assertEquals("hot", left.getString().getValue());
    assertEquals("hot", left.getString().getEndValue());

    ContainsOperand right = (ContainsOperand) rootNode.getRight();

    assertEquals("title", right.getProperty().getValue());

    assertEquals("hot", right.getString().getValue());
    assertEquals("hot", right.getString().getEndValue());
  }