void CanParseComplexedBooleanQuery() { var parser = new LuceneQueryParser(); parser.Parse("(foo:a foo:b) (foo:b +d) AND (foo:(e -c) OR g)"); var query = parser.LuceneAST.ToQuery(config); Assert.Equal("(foo:a foo:b) +(foo:b +foo:d) +((foo:e -foo:c) foo:g)", query.ToString()); }
void CanParseParenthesisInsideNextedBooleanQuery2() { var parser = new LuceneQueryParser(); parser.Parse("foo:a AND (foo:b -d) foo:-c"); var query = parser.LuceneAST.ToQuery(config); Assert.Equal("+foo:a +(foo:b -foo:d) foo:c", query.ToString()); }
void CanParseThreeTermsWithDiffrentOperators2() { var parser = new LuceneQueryParser(); parser.Parse("foo:a AND foo:b foo:-c"); var query = parser.LuceneAST.ToQuery(config); Assert.Equal("+foo:a +foo:b foo:c", query.ToString()); }
public void CanParseQueriesAndOutputWithNoChanges(string expectedQuery) { var sut = new LuceneQueryParser(); var rootNode = sut.Parse(expectedQuery); var actualResult = rootNode.ToString(); Assert.Equal(expectedQuery, actualResult); }
public void UnterminatedParensIsNotValid() { var sut = new LuceneQueryParser(); var ex = Assert.Throws <FormatException>(() => { var result = sut.Parse("(something"); }); Assert.Contains("Missing closing paren ')' for group expression", ex.Message); }
public void CanParseNotBeforeParens() { var sut = new LuceneQueryParser(); var result = sut.Parse("NOT (dog parrot)"); Assert.IsType <GroupNode>(result.Left); Assert.True((result.Left as GroupNode).HasParens); Assert.True((result.Left as GroupNode).IsNegated); }
public void CanHandleUnterminatedRegex() { var sut = new LuceneQueryParser(); var ex = Assert.Throws <FormatException>(() => { var result = sut.Parse(@"/\(\[A-Za-z\/\]+\).*?"); var ast = DebugQueryVisitor.Run(result); }); Assert.Contains("Unterminated regex", ex.Message); }
public void DoubleUnterminatedQuotedStringIsNotValid() { var sut = new LuceneQueryParser(); var ex = Assert.Throws <FormatException>(() => { var result = sut.Parse("\"something\"\""); var ast = DebugQueryVisitor.Run(result); }); Assert.Contains("Unexpected character", ex.Message); }
public void PrefixWithoutImmediateExpressionIsInvalid() { var sut = new LuceneQueryParser(); var ex = Assert.Throws <FormatException>(() => { var result = sut.Parse("something + other"); var ast = DebugQueryVisitor.Run(result); }); Assert.Contains("Unexpected character '+'.", ex.Message); }
public static FilterScope Run(string filter) { var node = _parser.Parse(filter); return(new GetFilterScopeVisitor().AcceptAsync(node, null).GetAwaiter().GetResult()); }