ToFieldStringValue() public static method

public static ToFieldStringValue ( object value ) : string
value object
return string
Exemplo n.º 1
0
        public IndexQuery WhereBetween(string field, object fromValue, object toValue, bool fromInclusive, bool toInclusive)
        {
            if (fromValue == null && toValue == null)
            {
                return(this);
            }

            var isNumericField = false;

            var property = ModelType.GetProperty(field, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

            // property might be null because it might be custom fields
            if (property != null)
            {
                var fieldAttr = property.GetCustomAttribute <FieldAttribute>();
                isNumericField = fieldAttr != null && fieldAttr.Numeric;
            }

            Query query = null;

            if (isNumericField)
            {
                query = CreateNumericRangeQuery(field, property.PropertyType, fromValue, toValue, fromInclusive, toInclusive);
            }
            else
            {
                query = new TermRangeQuery(field, LuceneUtility.ToFieldStringValue(fromValue), LuceneUtility.ToFieldStringValue(toValue), fromInclusive, toInclusive);
            }

            return(And(query));
        }
Exemplo n.º 2
0
        public IFieldable CreateLuceneField(string fieldName, object fieldValue)
        {
            if (!Numeric)
            {
                return(new Field(fieldName, LuceneUtility.ToFieldStringValue(fieldValue), Store, Index)
                {
                    Boost = Boost
                });
            }

            var field = new NumericField(fieldName, Store, Index != Field.Index.NO)
            {
                Boost = Boost
            };

            if (fieldValue is Int32)
            {
                field.SetIntValue((int)fieldValue);
            }
            else if (fieldValue is Int64)
            {
                field.SetLongValue((long)fieldValue);
            }
            else if (fieldValue is Single)
            {
                field.SetFloatValue((float)fieldValue);
            }
            else if (fieldValue is Double)
            {
                field.SetDoubleValue((double)fieldValue);
            }
            else if (fieldValue is Decimal)
            {
                field.SetDoubleValue((double)(decimal)fieldValue);
            }
            else
            {
                throw new NotSupportedException();
            }

            return(field);
        }
Exemplo n.º 3
0
 private TermQuery CreateTermQuery(string field, object value)
 {
     return(new TermQuery(new Term(field, LuceneUtility.ToFieldStringValue(value))));
 }