private void VisitOrElse(BinaryExpression orElse) { VisitExpression(orElse.Left); luceneQuery.OrElse(); VisitExpression(orElse.Right); }
private void VisitOrElse(BinaryExpression orElse) { if (subClauseDepth > 0) { luceneQuery.OpenSubclause(); } subClauseDepth++; VisitExpression(orElse.Left); luceneQuery.OrElse(); VisitExpression(orElse.Right); subClauseDepth--; if (subClauseDepth > 0) { luceneQuery.CloseSubclause(); } }
public static IDocumentQuery <Resource> QueryByExample(IDocumentQuery <Resource> query, IEnumerable <Resource> examples) { foreach (var example in examples) { query.OrElse(); query.OpenSubclause(); var fields = new[] { new { Name = "Context", Values = Enumerable.Repeat(example.Context, 1).Where(v => v != null) }, new { Name = "Type", Values = example.Type }, new { Name = "SubType", Values = example.SubType }, new { Name = "Code", Values = example.Code }, new { Name = "Status", Values = example.Status }, new { Name = "Tags", Values = example.Tags }, new { Name = "Properties", Values = (example.Properties ?? new Property[] { }).Select(p => p.Name) } }; foreach (var field in fields) { foreach (var value in (field.Values ?? new string[] { }).Where(v => !String.IsNullOrWhiteSpace(v))) { if (value.StartsWith("!") && value.EndsWith("*")) { query.Not.WhereStartsWith(field.Name, value.TrimStart('!').TrimEnd('*')); } else if (value.StartsWith("!")) { query.WhereNotEquals(field.Name, value.TrimStart('!')); } else if (value.EndsWith("*")) { query.WhereStartsWith(field.Name, value.TrimEnd('*')); } else { query.WhereEquals(field.Name, value, exact: true); } } } foreach (var property in example.Properties ?? new Property[] { }) { foreach (var value in (property.Value ?? new string[] { }).Where(v => !String.IsNullOrWhiteSpace(v))) { query.WhereEquals(property.Name, value, false); } foreach (var resource in property.Resources ?? new Resource[] { }) { var resourcevalues = (new [] { resource.ResourceId ?? "" }) .Union(resource.Code ?? new string[] { }) .Union(resource.Title ?? new string[] { }); foreach (var value in resourcevalues.Where(v => !String.IsNullOrWhiteSpace(v))) { query.WhereEquals(property.Name, value); } } } foreach (var title in (example.Title ?? new string[] { }).Where(v => !String.IsNullOrWhiteSpace(v))) { query.Search("Title", title, SearchOperator.And); } foreach (var subTitle in (example.SubTitle ?? new string[] { }).Where(v => !String.IsNullOrWhiteSpace(v))) { query.Search("SubTitle", subTitle, SearchOperator.And); } foreach (var body in (example.Body ?? new string[] { }).Where(v => !String.IsNullOrWhiteSpace(v))) { query.Search("Body", body, SearchOperator.And); } query.CloseSubclause(); } return(query); }