Exemple #1
0
        private Query CreateValueQuery(QueryFieldValue value)
        {
            var    currentField = _currentField.Peek();
            string numval;

            switch (value.Datatype)
            {
            case IndexableDataType.String:
                return(CreateStringValueQuery(value, currentField));

            case IndexableDataType.Int: numval = NumericUtils.IntToPrefixCoded(value.IntValue); break;

            case IndexableDataType.Long: numval = NumericUtils.LongToPrefixCoded(value.LongValue); break;

            case IndexableDataType.Float: numval = NumericUtils.FloatToPrefixCoded(value.SingleValue); break;

            case IndexableDataType.Double: numval = NumericUtils.DoubleToPrefixCoded(value.DoubleValue); break;

            default:
                throw new NotImplementedException("Unknown IndexableDataType enum value: " + value.Datatype);
            }
            var numterm = new Term(currentField.Name, numval);

            return(new TermQuery(numterm));
        }
Exemple #2
0
        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);
        }
Exemple #3
0
            /// <summary>
            /// Makes a TermQuery for the given MappedField and expression.
            /// </summary>
            /// <param name="field">
            /// The MappedField to create the query for.
            /// </param>
            /// <param name="term">
            /// The constant to match in the query.
            /// </param>
            /// <returns>
            /// An instance of TermQuery.
            /// </returns>
            private static TermQuery MakeTermQuery(MappedField field, Expression term)
            {
                Debug.Assert(null != field, "The mapped field must not be null.");
                Debug.Assert(null != term, "The term must not be null.");

                string queryTerm;

                switch (field.Type)
                {
                case MappedField.FieldType.Float:
                    queryTerm = NumericUtils.FloatToPrefixCoded(field.GetValueFromExpression <float>(term));
                    break;

                case MappedField.FieldType.Double:
                    queryTerm = NumericUtils.DoubleToPrefixCoded(field.GetValueFromExpression <double>(term));
                    break;

                case MappedField.FieldType.Short:
                    queryTerm = NumericUtils.IntToPrefixCoded(field.GetValueFromExpression <short>(term));
                    break;

                case MappedField.FieldType.Int:
                    queryTerm = NumericUtils.IntToPrefixCoded(field.GetValueFromExpression <int>(term));
                    break;

                case MappedField.FieldType.Long:
                    queryTerm = NumericUtils.LongToPrefixCoded(field.GetValueFromExpression <long>(term));
                    break;

                case MappedField.FieldType.String:
                    queryTerm = field.GetValueFromExpression <string>(term);
                    break;

                default:
                    throw new InvalidOperationException(String.Format(
                                                            "Cannot make a TermQuery for field '{0}' of type {1}.",
                                                            field.Name, field.Type));
                }

                return(new TermQuery(new Term(field.Name, queryTerm)));
            }
        internal static string ToPrefixCoded(this ValueType value)
        {
            if (value is int)
            {
                return(NumericUtils.IntToPrefixCoded((int)value));
            }
            if (value is long)
            {
                return(NumericUtils.LongToPrefixCoded((long)value));
            }
            if (value is double)
            {
                return(NumericUtils.DoubleToPrefixCoded((double)value));
            }
            if (value is float)
            {
                return(NumericUtils.FloatToPrefixCoded((float)value));
            }

            throw new NotSupportedException("ValueType " + value.GetType() + " not supported.");
        }
        private static string NumericStringToSortableNumeric(string value)
        {
            var number = NumberUtil.StringToNumber(value);

            if (number is int)
            {
                return(NumericUtils.IntToPrefixCoded((int)number));
            }
            if (number is long)
            {
                return(NumericUtils.LongToPrefixCoded((long)number));
            }
            if (number is float)
            {
                return(NumericUtils.FloatToPrefixCoded((float)number));
            }
            if (number is double)
            {
                return(NumericUtils.DoubleToPrefixCoded((double)number));
            }

            throw new ArgumentException("Unknown type for " + number.GetType() + " which started as " + value);
        }
Exemple #6
0
        private string ConvertToTermValue(IndexValue value)
        {
            switch (value.Type)
            {
            case IndexValueType.String:      return(value.StringValue);

            case IndexValueType.StringArray: throw new NotSupportedException();

            case IndexValueType.Bool:        return(value.BooleanValue ? IndexValue.Yes : IndexValue.No);

            case IndexValueType.Int:         return(NumericUtils.IntToPrefixCoded(value.IntegerValue));

            case IndexValueType.Long:        return(NumericUtils.LongToPrefixCoded(value.LongValue));

            case IndexValueType.Float:       return(NumericUtils.FloatToPrefixCoded(value.SingleValue));

            case IndexValueType.Double:      return(NumericUtils.DoubleToPrefixCoded(value.DoubleValue));

            case IndexValueType.DateTime:    return(NumericUtils.LongToPrefixCoded(value.DateTimeValue.Ticks));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private string GetTermText(Term term)
        {
            var fieldName = term.Field();
            var fieldText = term.Text();

            if (fieldText == null)
            {
                return(null);
            }

            var fieldType = default(IndexValueType);

            if (!(LuceneSearchManager?.IndexFieldTypeInfo?.TryGetValue(fieldName, out fieldType) ?? false))
            {
                switch (fieldName)
                {
                case "NodeTimestamp":
                case "VersionTimestamp":
                    fieldType = IndexValueType.Long;
                    break;

                default:
                    var c = fieldText.ToCharArray();
                    for (var i = 0; i < c.Length; i++)
                    {
                        if (c[i] < ' ')
                        {
                            c[i] = '.';
                        }
                    }
                    return(new string(c));
                }
            }

            var pt = Providers.Instance.StorageSchema.PropertyTypes[fieldName];

            if (pt == null)
            {
                switch (fieldName)
                {
                case "CreatedBy":
                case "ModifiedBy":
                case "Owner":
                case "VersionCreatedBy":
                case "VersionModifiedBy":
                case "Workspace":
                    fieldType = IndexValueType.Int;
                    break;
                    //case "NodeTimestamp":
                    //case "VersionTimestamp":
                    //    fieldType = IndexValueType.Long;
                    //    break;
                }
            }
            else
            {
                if (pt.DataType == DataType.Reference)
                {
                    fieldType = IndexValueType.Int;
                }
            }

            string check;

            switch (fieldType)
            {
            case IndexValueType.Bool:
            case IndexValueType.String:
            case IndexValueType.StringArray:
                return(fieldText);

            case IndexValueType.Int:
                var intValue = NumericUtils.PrefixCodedToInt(fieldText);
                check = NumericUtils.IntToPrefixCoded(intValue);
                if (check != fieldText)
                {
                    return(null);
                }
                return(Convert.ToString(intValue, CultureInfo.InvariantCulture));

            case IndexValueType.Long:
                var longValue = NumericUtils.PrefixCodedToLong(fieldText);
                check = NumericUtils.LongToPrefixCoded(longValue);
                if (check != fieldText)
                {
                    return(null);
                }
                return(Convert.ToString(longValue, CultureInfo.InvariantCulture));

            case IndexValueType.Float:
                var floatValue = NumericUtils.PrefixCodedToFloat(fieldText);
                check = NumericUtils.FloatToPrefixCoded(floatValue);
                if (check != fieldText)
                {
                    return(null);
                }
                return(Convert.ToString(floatValue, CultureInfo.InvariantCulture));

            case IndexValueType.Double:
                var doubleValue = NumericUtils.PrefixCodedToDouble(fieldText);
                check = NumericUtils.DoubleToPrefixCoded(doubleValue);
                if (check != fieldText)
                {
                    return(null);
                }
                return(Convert.ToString(doubleValue, CultureInfo.InvariantCulture));

            case IndexValueType.DateTime:
                var ticksValue = NumericUtils.PrefixCodedToLong(fieldText);
                check = NumericUtils.LongToPrefixCoded(ticksValue);
                if (check != fieldText)
                {
                    return(null);
                }
                var d = new DateTime(ticksValue);
                if (d.Hour == 0 && d.Minute == 0 && d.Second == 0)
                {
                    return(d.ToString("yyyy-MM-dd"));
                }
                if (d.Second == 0)
                {
                    return(d.ToString("yyyy-MM-dd HH:mm"));
                }
                return(d.ToString("yyyy-MM-dd HH:mm:ss"));

            default:
                throw new NotSupportedException("Unknown IndexFieldType: " + fieldType);
            }
        }