private SnQueryPredicate CreateRangeQuery(string fieldName, QueryFieldValue minValue, QueryFieldValue maxValue, bool includeLower, bool includeUpper) { var min = ParseValue(fieldName, minValue, _context); var max = ParseValue(fieldName, maxValue, _context); if (min?.StringValue == SnQuery.EmptyText && max == null) { _hasEmptyQuery = true; return(new SimplePredicate(fieldName, min)); } if (max?.StringValue == SnQuery.EmptyText && min == null) { _hasEmptyQuery = true; return(new SimplePredicate(fieldName, max)); } if (min?.StringValue == SnQuery.EmptyText) { min = null; } if (max?.StringValue == SnQuery.EmptyText) { max = null; } if (min == null && max == null) { throw ParserError("Invalid range: the minimum and the maximum value are cannot be null/empty together."); } return(new RangePredicate(fieldName, min, max, !includeLower, !includeUpper)); }
private SnQueryPredicate CreateValueQuery(QueryFieldValue value) { var currentField = _currentField.Peek(); var fieldName = currentField.Name; if (value.StringValue == SnQuery.EmptyText) { return(new SimplePredicate(currentField.Name, new IndexValue(value.StringValue))); } if (value.StringValue == SnQuery.EmptyInnerQueryText) { return(new SimplePredicate(IndexFieldName.NodeId, new IndexValue(0))); } var parsedValue = ParseValue(fieldName, value, _context); if (parsedValue.Type == IndexValueType.String) { if (parsedValue.StringValue == SnQuery.EmptyText) { return(new SimplePredicate(currentField.Name, parsedValue)); } if (parsedValue.StringValue == SnQuery.EmptyInnerQueryText) { return(new SimplePredicate(IndexFieldName.NodeId, new IndexValue(0))); } } return(new SimplePredicate(currentField.Name, parsedValue, value.FuzzyValue)); }
private IndexValue ParseValue(string fieldName, QueryFieldValue value, IQueryContext context) { if (value == null) { return(null); } if (fieldName == IndexFieldName.AllText) { return(new IndexValue(value.StringValue.ToLowerInvariant())); } var parser = context.GetPerFieldIndexingInfo(fieldName); if (parser == null) { throw ParserError($"Unknown field: {fieldName}."); } var parsed = parser.IndexFieldHandler.Parse(value.StringValue); if (parsed == null) { throw ParserError($"Cannot parse the value. FieldName {fieldName}, Parser: {parser.IndexFieldHandler.GetType().Name}"); } return(parsed); }
private static QueryFieldValue ConvertValue(string name, object value, out Type fieldDataType) { var contentTypeValue = value as ContentType; if (contentTypeValue != null && name == "ContentType") { name = "TypeIs"; value = contentTypeValue.Name; } var fieldInfo = SenseNet.ContentRepository.Schema.ContentTypeManager.GetPerFieldIndexingInfo(name); if (fieldInfo == null) { throw new InvalidOperationException("Unknown field: " + name); } var converter = fieldInfo.IndexFieldHandler; var queryFieldValue = new QueryFieldValue(value); converter.ConvertToTermValue(queryFieldValue); fieldDataType = fieldInfo.FieldDataType; return(queryFieldValue); }
private void BuildWildcardQuery(string field, WildcardPosition type, string arg) { var fieldInfo = SenseNet.ContentRepository.Schema.ContentTypeManager.GetPerFieldIndexingInfo(field); if (fieldInfo == null) { throw new InvalidOperationException("Unknown field: " + field); } var queryFieldValue = new QueryFieldValue(arg); fieldInfo.IndexFieldHandler.ConvertToTermValue(queryFieldValue); if (queryFieldValue.Datatype != IndexableDataType.String) { throw new NotSupportedException("Wildcard query only can be built on string based Field."); } string text; switch (type) { case WildcardPosition.AtStart: text = "*" + queryFieldValue.StringValue; break; case WildcardPosition.AtEnd: text = queryFieldValue.StringValue + "*"; break; case WildcardPosition.AtStartAndEnd: text = string.Concat("*", queryFieldValue.StringValue, "*"); break; default: throw new SnNotSupportedException("WildcardType is not supported: " + type); } var wq = new WildcardQuery(new Term(field, text)); _queries.Push(wq); }
private static Term CreateTerm(string name, QueryFieldValue queryFieldValue) { string numval; switch (queryFieldValue.Datatype) { case IndexableDataType.String: return(new Term(name, queryFieldValue.StringValue)); case IndexableDataType.Int: numval = NumericUtils.IntToPrefixCoded(queryFieldValue.IntValue); break; case IndexableDataType.Long: numval = NumericUtils.LongToPrefixCoded(queryFieldValue.LongValue); break; case IndexableDataType.Float: numval = NumericUtils.FloatToPrefixCoded(queryFieldValue.SingleValue); break; case IndexableDataType.Double: numval = NumericUtils.DoubleToPrefixCoded(queryFieldValue.DoubleValue); break; default: throw new SnNotSupportedException("Unknown IndexableDataType enum value: " + queryFieldValue.Datatype); } var numterm = new Term(name, numval); return(numterm); }
internal static Query GetPathQuery(string path, bool inTree) { if (path == null) { return(null); } FieldIndexHandler converter = null; string fieldName = null; if (inTree) { converter = new InTreeIndexHandler(); fieldName = LucObject.FieldName.InTree; } else { converter = new InFolderIndexHandler(); fieldName = LucObject.FieldName.InFolder; } var qvalue = new QueryFieldValue(path); converter.ConvertToTermValue(qvalue); return(new TermQuery(new Term(fieldName, qvalue.StringValue))); }
private QueryFieldValue ParseValue() { // Value ==> ExactValue | WILDCARDSTRING var val = ParseExactValue(false); if (val != null) { return(val); } if (_lexer.CurrentToken == CqlLexer.Token.WildcardString) { val = new QueryFieldValue(_lexer.StringValue, _lexer.IsPhrase); _lexer.NextToken(); return(val); } return(null); }
public override bool TryParseAndSet(QueryFieldValue value) { var v = value.StringValue.ToLower(); if (v.StartsWith("#")) { return(true); } switch (v) { case "red": value.Set("#ff0000"); return(true); case "green": value.Set("#00ff00"); return(true); case "blue": value.Set("#0000ff"); return(true); default: return(false); } }
private QueryFieldValue ParseExactValue(bool throwEx) { // ExactValue ==> STRING | NUMBER | EMPTY if (_lexer.StringValue == SnQuery.EmptyText) { _hasEmptyQuery = true; var fieldVal = new QueryFieldValue(_lexer.StringValue, _lexer.IsPhrase); _lexer.NextToken(); return(fieldVal); } if (_lexer.CurrentToken != CqlLexer.Token.String && _lexer.CurrentToken != CqlLexer.Token.Number) { if (throwEx) { throw ParserError(String.Concat("Unexpected ", _lexer.CurrentToken, ". Expected: STRING | NUMBER")); } return(null); } var val = new QueryFieldValue(_lexer.StringValue, _lexer.IsPhrase); _lexer.NextToken(); return(val); }
private Query CreateRangeQuery(string fieldName, QueryFieldValue minValue, QueryFieldValue maxValue, bool includeLower, bool includeUpper) { QueryFieldValue value = minValue == null ? maxValue : minValue; var dataType = value.Datatype; switch (dataType) { case IndexableDataType.String: var lowerTerm = minValue == null ? null : minValue.StringValue; var upperTerm = maxValue == null ? null : maxValue.StringValue; return(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper)); case IndexableDataType.Int: var lowerInt = minValue == null ? null : (Int32?)minValue.IntValue; var upperInt = maxValue == null ? null : (Int32?)maxValue.IntValue; return(NumericRangeQuery.NewIntRange(fieldName, lowerInt, upperInt, includeLower, includeUpper)); case IndexableDataType.Long: var lowerLong = minValue == null ? null : (Int64?)minValue.LongValue; var upperLong = maxValue == null ? null : (Int64?)maxValue.LongValue; return(NumericRangeQuery.NewLongRange(fieldName, 8, lowerLong, upperLong, includeLower, includeUpper)); case IndexableDataType.Float: var lowerFloat = minValue == null ? Single.MinValue : minValue.SingleValue; var upperFloat = maxValue == null ? Single.MaxValue : maxValue.SingleValue; return(NumericRangeQuery.NewFloatRange(fieldName, lowerFloat, upperFloat, includeLower, includeUpper)); case IndexableDataType.Double: var lowerDouble = minValue == null ? Double.MinValue : minValue.DoubleValue; var upperDouble = maxValue == null ? Double.MaxValue : maxValue.DoubleValue; return(NumericRangeQuery.NewDoubleRange(fieldName, 8, lowerDouble, upperDouble, includeLower, includeUpper)); default: throw new SnNotSupportedException("Unknown IndexableDataType: " + dataType); } }
public override void ConvertToTermValue(QueryFieldValue value) { throw new NotImplementedException(); }