本文整理汇总了C#中QueryBuilder.AddBooleanClause方法的典型用法代码示例。如果您正苦于以下问题:C# QueryBuilder.AddBooleanClause方法的具体用法?C# QueryBuilder.AddBooleanClause怎么用?C# QueryBuilder.AddBooleanClause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.AddBooleanClause方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBuilderFromExpression
private static QueryBuilder CreateBuilderFromExpression(string expression, out ClauseOccurrence occurrence)
{
// FirstName# = 'Tim
// +(LastName+ = 'James', Type+ = '0')
occurrence = ClauseOccurrence.Default;
if (string.IsNullOrEmpty(expression))
return new QueryBuilder();
QueryBuilder builder = new QueryBuilder();
if (expression.StartsWith("+")) {
occurrence = ClauseOccurrence.MustOccur;
expression = expression.Substring(1);
}
else if (expression.StartsWith("#")) {
occurrence = ClauseOccurrence.ShouldOccur;
expression = expression.Substring(1);
}
else if (expression.StartsWith("-")) {
occurrence = ClauseOccurrence.MustNotOccur;
expression = expression.Substring(1);
}
if (expression.StartsWith("("))
expression = expression.Substring(1);
if (expression.EndsWith(")"))
expression = expression.Substring(0, expression.Length - 1);
string[] parts = expression.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var part in parts) {
string searchTerm;
string boolOperator;
string searchValue;
ClauseOccurrence co = ClauseOccurrence.Default;
string[] words = part.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (words.Length < 3)
throw new ArgumentNullException("expression", "Malformed expression");
searchTerm = words[0];
boolOperator = words[1];
searchValue = string.Join(" ", words, 2, words.Length - 2).Replace("\'", "");
if (searchTerm.EndsWith("+")) {
co = ClauseOccurrence.MustOccur;
searchTerm = searchTerm.Substring(0, searchTerm.Length - 1);
}
else if (searchTerm.EndsWith("#")) {
co = ClauseOccurrence.ShouldOccur;
searchTerm = searchTerm.Substring(0, searchTerm.Length - 1);
}
else if (searchTerm.EndsWith("-")) {
co = ClauseOccurrence.MustNotOccur;
searchTerm = searchTerm.Substring(0, searchTerm.Length - 1);
}
if (boolOperator.Equals("=")) {
builder.AddBooleanClause(new SearchTerm(searchTerm, searchValue, StaticValues.DefaultBoost, true), co);
}
else if (boolOperator.Equals(">")) {
throw new NotSupportedException("Boolean operator not yet supported");
}
else if (boolOperator.Equals(">=")) {
throw new NotSupportedException("Boolean operator not yet supported");
}
else if (boolOperator.Equals("<")) {
throw new NotSupportedException("Boolean operator not yet supported");
}
else if (boolOperator.Equals("<=")) {
throw new NotSupportedException("Boolean operator not yet supported");
}
else if (boolOperator.Equals("!=") || boolOperator.Equals("<>")) {
if (co == ClauseOccurrence.MustNotOccur)
co = ClauseOccurrence.MustOccur;
else if (co == ClauseOccurrence.MustOccur)
co = ClauseOccurrence.MustNotOccur;
builder.AddBooleanClause(new SearchTerm(searchTerm, searchValue, StaticValues.DefaultBoost, true), co);
}
else {
throw new ArgumentException("Malformed boolean operator in expression");
}
}
return builder;
}