Пример #1
0
        public override Query Process(RangeQueryOptions opt, AzureQueryMapper mapper)
        {
            object obj = opt.FieldFromValue ?? opt.FieldToValue;

            if (obj == null || !obj.GetType().IsPrimitive)
            {
                return((Query)null);
            }
            switch (Type.GetTypeCode(obj.GetType()))
            {
            case TypeCode.SByte:
            case TypeCode.Byte:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
            case TypeCode.UInt32:
            case TypeCode.Int64:
            case TypeCode.UInt64:
            case TypeCode.Decimal:
                return(this.BuildLongRangeQuery(opt));

            case TypeCode.Single:
            case TypeCode.Double:
                return(this.BuildDoubleRangeQuery(opt));

            default:
                return((Query)null);
            }
        }
 public override Query Process(RangeQueryOptions options, AzureQueryMapper mapper)
 {
     if (!(options.FieldFromValue is DateTime) && !(options.FieldToValue is DateTime))
         return (Query)null;
     options.FieldFromValue = this.ConvertToUtc(options.FieldFromValue, options.FieldName, mapper);
     options.FieldToValue = this.ConvertToUtc(options.FieldToValue, options.FieldName, mapper);
     return new DefaultRangeQueryProcessor().Process(options, mapper);
 }
Пример #3
0
 protected string NormalizeValue(string valueToNormalize, AzureQueryMapper mapper)
 {
     if (mapper.QueryParser != null && mapper.QueryParser.LowercaseExpandedTerms)
     {
         valueToNormalize = valueToNormalize.ToLower(mapper.QueryParser.Locale);
     }
     return(valueToNormalize);
 }
Пример #4
0
 public override Query Process(RangeQueryOptions options, AzureQueryMapper mapper)
 {
     if (!(options.FieldFromValue is DateTime) && !(options.FieldToValue is DateTime))
     {
         return((Query)null);
     }
     options.FieldFromValue = this.ConvertToUtc(options.FieldFromValue, options.FieldName, mapper);
     options.FieldToValue   = this.ConvertToUtc(options.FieldToValue, options.FieldName, mapper);
     return(new DefaultRangeQueryProcessor().Process(options, mapper));
 }
 public AzureIndex(AzureIndexParameters parameters)
 {
     if (parameters == null)
     {
         throw new ArgumentNullException("parameters");
     }
     QueryMapper         = new AzureQueryMapper(parameters);
     QueryOptimizer      = new AzureQueryOptimizer();
     FieldNameTranslator = parameters.FieldNameTranslator;
     Parameters          = parameters;
 }
 public override Query Process(RangeQueryOptions options, AzureQueryMapper mapper)
 {
     string lowerTerm = (string)null;
     string upperTerm = (string)null;
     if (options.FieldFromValue != null)
         lowerTerm = this.NormalizeValue(mapper.ValueFormatter.FormatValueForIndexStorage(options.FieldFromValue, options.FieldName).ToString(), mapper);
     if (options.FieldToValue != null)
         upperTerm = this.NormalizeValue(mapper.ValueFormatter.FormatValueForIndexStorage(options.FieldToValue, options.FieldName).ToString(), mapper);
     TermRangeQuery termRangeQuery = new TermRangeQuery(options.FieldName, lowerTerm, upperTerm, options.IncludeLower, options.IncludeUpper);
     termRangeQuery.Boost = options.Boost;
     return (Query)termRangeQuery;
 }
 private object ConvertToUtc(object objectToConvert, string fieldName, AzureQueryMapper mapper)
 {
     if (objectToConvert == null)
         return (object)null;
     DateTime dateTime = (DateTime)objectToConvert;
     if (dateTime.Kind != System.DateTimeKind.Utc)
     {
         SearchLog.Log.Warn(string.Format("Your query is using non UTC dates. field:{0} value: {1}. You will probably have incorrect search result.", (object)fieldName, (object)dateTime), (Exception)null);
         if (mapper.Parameters.ConvertQueryDatesToUtc)
             objectToConvert = (object)ContentSearchManager.Locator.GetInstance<IDateTimeConverter>().ToUniversalTime(dateTime);
     }
     return objectToConvert;
 }
 public Query BuildRangeQuery(RangeQueryOptions options, AzureQueryMapper mapper, bool useDefaultProcessor)
 {
     if (string.IsNullOrEmpty(options.FieldName))
         throw new ArgumentException("RangeQueryOptions.FieldName cannot be null or empty string.");
     foreach (RangeQueryProcessor rangeQueryProcessor in this.GetProcessors())
     {
         Query query = rangeQueryProcessor.Process(options, mapper);
         if (query != null)
             return query;
     }
     if (useDefaultProcessor)
         return new DefaultRangeQueryProcessor().Process(options, mapper);
     return (Query)null;
 }
Пример #9
0
        private object ConvertToUtc(object objectToConvert, string fieldName, AzureQueryMapper mapper)
        {
            if (objectToConvert == null)
            {
                return((object)null);
            }
            DateTime dateTime = (DateTime)objectToConvert;

            if (dateTime.Kind != System.DateTimeKind.Utc)
            {
                SearchLog.Log.Warn(string.Format("Your query is using non UTC dates. field:{0} value: {1}. You will probably have incorrect search result.", (object)fieldName, (object)dateTime), (Exception)null);
                if (mapper.Parameters.ConvertQueryDatesToUtc)
                {
                    objectToConvert = (object)ContentSearchManager.Locator.GetInstance <IDateTimeConverter>().ToUniversalTime(dateTime);
                }
            }
            return(objectToConvert);
        }
Пример #10
0
        public override Query Process(RangeQueryOptions options, AzureQueryMapper mapper)
        {
            string lowerTerm = (string)null;
            string upperTerm = (string)null;

            if (options.FieldFromValue != null)
            {
                lowerTerm = this.NormalizeValue(mapper.ValueFormatter.FormatValueForIndexStorage(options.FieldFromValue, options.FieldName).ToString(), mapper);
            }
            if (options.FieldToValue != null)
            {
                upperTerm = this.NormalizeValue(mapper.ValueFormatter.FormatValueForIndexStorage(options.FieldToValue, options.FieldName).ToString(), mapper);
            }
            TermRangeQuery termRangeQuery = new TermRangeQuery(options.FieldName, lowerTerm, upperTerm, options.IncludeLower, options.IncludeUpper);

            termRangeQuery.Boost = options.Boost;
            return((Query)termRangeQuery);
        }
Пример #11
0
 public Query BuildRangeQuery(RangeQueryOptions options, AzureQueryMapper mapper, bool useDefaultProcessor)
 {
     if (string.IsNullOrEmpty(options.FieldName))
     {
         throw new ArgumentException("RangeQueryOptions.FieldName cannot be null or empty string.");
     }
     foreach (RangeQueryProcessor rangeQueryProcessor in this.GetProcessors())
     {
         Query query = rangeQueryProcessor.Process(options, mapper);
         if (query != null)
         {
             return(query);
         }
     }
     if (useDefaultProcessor)
     {
         return(new DefaultRangeQueryProcessor().Process(options, mapper));
     }
     return((Query)null);
 }
 public override Query Process(RangeQueryOptions opt, AzureQueryMapper mapper)
 {
     object obj = opt.FieldFromValue ?? opt.FieldToValue;
     if (obj == null || !obj.GetType().IsPrimitive)
         return (Query)null;
     switch (Type.GetTypeCode(obj.GetType()))
     {
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64:
         case TypeCode.UInt64:
         case TypeCode.Decimal:
             return this.BuildLongRangeQuery(opt);
         case TypeCode.Single:
         case TypeCode.Double:
             return this.BuildDoubleRangeQuery(opt);
         default:
             return (Query)null;
     }
 }
 protected string NormalizeValue(string valueToNormalize, AzureQueryMapper mapper)
 {
     if (mapper.QueryParser != null && mapper.QueryParser.LowercaseExpandedTerms)
         valueToNormalize = valueToNormalize.ToLower(mapper.QueryParser.Locale);
     return valueToNormalize;
 }
 public abstract Query Process(RangeQueryOptions options, AzureQueryMapper mapper);
Пример #15
0
 public abstract Query Process(RangeQueryOptions options, AzureQueryMapper mapper);