public void CorrectParamsAreIncludedForIntValue() { var condition = new TermCondition(27, "blahblah", 2); var definition = condition.Definition; Assert.That(definition, Is.EqualTo("(term field=blahblah boost=2 27)")); }
public void CorrectParamsAreIncluded() { var condition = new TermCondition("some test text", "testfield", 2); var definition = condition.Definition; Assert.That(definition, Is.EqualTo("(term field=testfield boost=2 'some test text')")); }
public void Term(Expression <Func <TEntity, object> > expression, object value) { if (expression == null) { throw new ArgumentNullException(nameof(expression)); } var condition = new TermCondition <TEntity>(_queryContainerDescriptor, expression, value); Must(condition); }
private void AnsyExpression(Expression expression, SearchConditionBase query) { if (query == null) { query = new SearchConditionBase("query"); } if (expression is MemberExpression) { var memberexp = expression as MemberExpression; var nodetype = memberexp.NodeType; return; } if (expression is BinaryExpression) { SearchConditionBase condtion = null; var binexp = expression as BinaryExpression; if (!(binexp.Left is BinaryExpression)) { string jsonname = string.Empty; switch (binexp.NodeType) { case ExpressionType.GreaterThan: { condtion = new GreaterThen(); } break; case ExpressionType.GreaterThanOrEqual: { condtion = new GreaterEquelThen(); } break; case ExpressionType.LessThan: { condtion = new SmallThen(); } break; case ExpressionType.LessThanOrEqual: { condtion = new SmallEquelThen(); } break; case ExpressionType.Equal: { condtion = new TermCondition(); } break; case ExpressionType.NotEqual: { condtion = new MustNotCodition(); break; } default: throw new NotSupportedException("不支持的操作:" + binexp.NodeType); } if (binexp.Left is MemberExpression) { var memberexp = binexp.Left as MemberExpression; var jsonprop = (JsonPropertyAttribute)memberexp.Member.GetCustomAttributes(typeof(JsonPropertyAttribute), true).FirstOrDefault(); if (jsonprop != null) { jsonname = jsonprop.PropertyName; } else { jsonname = memberexp.Member.Name; } } else { throw new NotSupportedException("表达式左侧不是属性"); } if (binexp.Right is ConstantExpression) { var cst = binexp.Right as ConstantExpression; var conditionvalue = new SearchConditionBase(jsonname, cst.Value); if (condtion is MustNotCodition) { var sc = new TermCondition(); sc.FilterCollection.Add(conditionvalue); condtion.FilterCollection.Add(sc); } else { condtion.FilterCollection.Add(conditionvalue); } } else { throw new NotSupportedException("表达式的右侧一定是常数"); } query.FilterCollection.Add(condtion); return; } SearchConditionBase group = new SearchConditionBase("bool"); query.FilterCollection.Add(group); SearchConditionBase searchType = null; //包裹操作符 switch (binexp.NodeType) { case ExpressionType.AndAlso: { searchType = new MustCondition(); break; } case ExpressionType.OrElse: { searchType = new ShouldCondition(); break; } case ExpressionType.And: { break; } default: throw new NotSupportedException("不支持的操作:" + binexp.NodeType); } group.FilterCollection.Add(searchType); AnsyExpression(binexp.Left, searchType); AnsyExpression(binexp.Right, searchType); } }