Пример #1
0
        public static IndexQuery GetIndexQueryFromHttpContext(this IHttpContext context, int maxPageSize)
        {
            var query = new IndexQuery
            {
                Query                = context.Request.QueryString["query"] ?? "",
                Start                = context.GetStart(),
                Cutoff               = context.GetCutOff(),
                PageSize             = context.GetPageSize(maxPageSize),
                SkipTransformResults = context.GetSkipTransformResults(),
                FieldsToFetch        = context.Request.QueryString.GetValues("fetch"),
                GroupBy              = context.Request.QueryString.GetValues("groupBy"),
                AggregationOperation = context.GetAggregationOperation(),
                SortedFields         = context.Request.QueryString.GetValues("sort")
                                       .EmptyIfNull()
                                       .Select(x => new SortedField(x))
                                       .ToArray()
            };

            double lat = context.GetLat(), lng = context.GetLng(), radius = context.GetRadius();

            if (lat != 0 || lng != 0 || radius != 0)
            {
                return(new SpatialIndexQuery(query)
                {
                    Latitude = lat,
                    Longitude = lng,
                    Radius = radius,
                    SortByDistance = context.SortByDistance()
                });
            }
            return(query);
        }
Пример #2
0
        public static IndexQuery GetIndexQueryFromHttpContext(this IHttpContext context, int maxPageSize)
        {
            var query = new IndexQuery
            {
                Query                = context.Request.QueryString["query"] ?? "",
                Start                = context.GetStart(),
                Cutoff               = context.GetCutOff(),
                CutoffEtag           = context.GetCutOffEtag(),
                PageSize             = context.GetPageSize(maxPageSize),
                SkipTransformResults = context.GetSkipTransformResults(),
                FieldsToFetch        = context.Request.QueryString.GetValues("fetch"),
                GroupBy              = context.Request.QueryString.GetValues("groupBy"),
                DefaultField         = context.Request.QueryString["defaultField"],

                DefaultOperator =
                    string.Equals(context.Request.QueryString["operator"], "AND", StringComparison.OrdinalIgnoreCase) ?
                    QueryOperator.And :
                    QueryOperator.Or,

                AggregationOperation = context.GetAggregationOperation(),
                SortedFields         = context.Request.QueryString.GetValues("sort")
                                       .EmptyIfNull()
                                       .Select(x => new SortedField(x))
                                       .ToArray(),
                HighlightedFields   = context.GetHighlightedFields().ToArray(),
                HighlighterPreTags  = context.Request.QueryString.GetValues("preTags"),
                HighlighterPostTags = context.Request.QueryString.GetValues("postTags"),
                ResultsTransformer  = context.Request.QueryString["resultsTransformer"],
                QueryInputs         = context.ExtractQueryInputs()
            };


            var          spatialFieldName = context.Request.QueryString["spatialField"] ?? Constants.DefaultSpatialFieldName;
            var          queryShape       = context.Request.QueryString["queryShape"];
            SpatialUnits units;
            bool         unitsSpecified = Enum.TryParse(context.Request.QueryString["spatialUnits"], out units);
            double       distanceErrorPct;

            if (!double.TryParse(context.Request.QueryString["distErrPrc"], NumberStyles.Any, CultureInfo.InvariantCulture, out distanceErrorPct))
            {
                distanceErrorPct = Constants.DefaultSpatialDistanceErrorPct;
            }
            SpatialRelation spatialRelation;

            if (Enum.TryParse(context.Request.QueryString["spatialRelation"], false, out spatialRelation) &&
                !string.IsNullOrWhiteSpace(queryShape))
            {
                return(new SpatialIndexQuery(query)
                {
                    SpatialFieldName = spatialFieldName,
                    QueryShape = queryShape,
                    RadiusUnitOverride = unitsSpecified ? units : (SpatialUnits?)null,
                    SpatialRelation = spatialRelation,
                    DistanceErrorPercentage = distanceErrorPct,
                });
            }
            return(query);
        }
Пример #3
0
        public static IndexQuery GetIndexQueryFromHttpContext(this IHttpContext context, int maxPageSize)
        {
            var query = new IndexQuery
            {
                Query                = context.Request.QueryString["query"] ?? "",
                Start                = context.GetStart(),
                Cutoff               = context.GetCutOff(),
                CutoffEtag           = context.GetCutOffEtag(),
                PageSize             = context.GetPageSize(maxPageSize),
                SkipTransformResults = context.GetSkipTransformResults(),
                FieldsToFetch        = context.Request.QueryString.GetValues("fetch"),
                GroupBy              = context.Request.QueryString.GetValues("groupBy"),
                DefaultField         = context.Request.QueryString["defaultField"],

                DefaultOperator =
                    string.Equals(context.Request.QueryString["operator"], "AND", StringComparison.InvariantCultureIgnoreCase) ?
                    QueryOperator.And :
                    QueryOperator.Or,

                AggregationOperation = context.GetAggregationOperation(),
                SortedFields         = context.Request.QueryString.GetValues("sort")
                                       .EmptyIfNull()
                                       .Select(x => new SortedField(x))
                                       .ToArray()
            };

            var    spatialFieldName = context.Request.QueryString["spatialField"] ?? Constants.DefaultSpatialFieldName;
            var    queryShape       = context.Request.QueryString["queryShape"];
            double distanceErrorPct;

            if (!double.TryParse(context.Request.QueryString["distErrPrc"], out distanceErrorPct))
            {
                distanceErrorPct = Constants.DefaultSpatialDistanceErrorPct;
            }
            SpatialRelation spatialRelation;

            if (Enum.TryParse(context.Request.QueryString["spatialRelation"], false, out spatialRelation) &&
                !string.IsNullOrWhiteSpace(queryShape))
            {
                return(new SpatialIndexQuery(query)
                {
                    SpatialFieldName = spatialFieldName,
                    QueryShape = queryShape,
                    SpatialRelation = spatialRelation,
                    DistanceErrorPercentage = distanceErrorPct,
                });
            }
            return(query);
        }
Пример #4
0
 public static IndexQuery GetIndexQueryFromHttpContext(this IHttpContext context, int maxPageSize)
 {
     return(new IndexQuery
     {
         Query = Uri.UnescapeDataString(context.Request.QueryString["query"] ?? ""),
         Start = context.GetStart(),
         Cutoff = context.GetCutOff(),
         PageSize = context.GetPageSize(maxPageSize),
         FieldsToFetch = context.Request.QueryString.GetValues("fetch"),
         SortedFields = context.Request.QueryString.GetValues("sort")
                        .EmptyIfNull()
                        .Select(x => new SortedField(x))
                        .ToArray()
     });
 }
Пример #5
0
        private void OnBulkOperation(IHttpContext context, Func <string, TransactionInformation, object> batchOperation)
        {
            var match = urlMatcher.Match(context.GetRequestUrl());
            var index = match.Groups[2].Value;

            if (string.IsNullOrEmpty(index))
            {
                context.SetStatusToBadRequest();
                return;
            }
            var allowStale = context.GetAllowStale();

            Database.TransactionalStorage.Batch(actions =>
            {
                bool stale;
                var queryResults = Database.QueryDocumentIds(index, new IndexQuery
                {
                    Query         = context.Request.QueryString["query"],
                    Start         = context.GetStart(),
                    PageSize      = int.MaxValue,        // get all
                    Cutoff        = context.GetCutOff(),
                    FieldsToFetch = new[] { "__document_id" }
                }, out stale);

                if (stale)
                {
                    context.SetStatusToNonAuthoritativeInformation();
                    if (allowStale == false)
                    {
                        throw new InvalidOperationException(
                            "Bulk operation cancelled because the index is stale and allowStale is false");
                    }
                }

                var transactionInformation = GetRequestTransaction(context);
                var array = new JArray();
                foreach (var documentId in queryResults)
                {
                    var result = batchOperation(documentId, transactionInformation);
                    array.Add(JObject.FromObject(result, new JsonSerializer {
                        Converters = { new JsonEnumConverter() }
                    }));
                }
                context.WriteJson(array);
            });
        }
Пример #6
0
    	private void OnBulkOperation(IHttpContext context, Func<string, TransactionInformation, object> batchOperation)
    	{
    		var match = urlMatcher.Match(context.GetRequestUrl());
    		var index = match.Groups[2].Value;
    		if (string.IsNullOrEmpty(index))
    		{
    			context.SetStatusToBadRequest();
    			return;
    		}
    		var allowStale = context.GetAllowStale();
    		Database.TransactionalStorage.Batch(actions =>
    		{
    			bool stale;
    			var queryResults = Database.QueryDocumentIds(index, new IndexQuery
    			{
    				Query = context.Request.QueryString["query"],
    				Start = context.GetStart(),
    				PageSize = int.MaxValue, // get all
    				Cutoff = context.GetCutOff(),
    				FieldsToFetch = new[] { "__document_id" }
    			}, out stale);

    			if (stale)
    			{
    				context.SetStatusToNonAuthoritativeInformation();
    				if (allowStale == false)
    				{
    					throw new InvalidOperationException(
    						"Bulk operation cancelled because the index is stale and allowStale is false");
    				}
    			}

				var transactionInformation = GetRequestTransaction(context);
    			var array = new JArray();
				foreach (var documentId in queryResults)
    			{
    				var result = batchOperation(documentId, transactionInformation);
					array.Add(JObject.FromObject(result, new JsonSerializer { Converters = { new JsonEnumConverter() } }));
    			}
    			context.WriteJson(array);
    		});
    	}
Пример #7
0
 private void OnGet(IHttpContext context, string index)
 {
     var definition = context.Request.QueryString["definition"];
     if ("yes".Equals(definition, StringComparison.InvariantCultureIgnoreCase))
     {
         context.WriteJson(new {Index = Database.IndexDefinitionStorage.GetIndexDefinition(index)});
     }
     else
     {
         context.WriteJson(Database.Query(index, new IndexQuery
         {
             Query = context.Request.QueryString["query"],
             Start = context.GetStart(),
             PageSize = context.GetPageSize(),
             Cutoff = context.GetCutOff(),
             FieldsToFetch = context.Request.QueryString.GetValues("fetch"),
             SortedFields = context.Request.QueryString.GetValues("sort")
                 .EmptyIfNull()
                 .Select(x => new SortedField(x))
                 .ToArray()
         }));
     }
 }
Пример #8
0
        private void OnGet(IHttpContext context, string index)
        {
            var definition = context.Request.QueryString["definition"];

            if ("yes".Equals(definition, StringComparison.InvariantCultureIgnoreCase))
            {
                context.WriteJson(new { Index = Database.IndexDefinitionStorage.GetIndexDefinition(index) });
            }
            else
            {
                context.WriteJson(Database.Query(index, new IndexQuery
                {
                    Query         = context.Request.QueryString["query"],
                    Start         = context.GetStart(),
                    PageSize      = context.GetPageSize(Database.Configuration.MaxPageSize),
                    Cutoff        = context.GetCutOff(),
                    FieldsToFetch = context.Request.QueryString.GetValues("fetch"),
                    SortedFields  = context.Request.QueryString.GetValues("sort")
                                    .EmptyIfNull()
                                    .Select(x => new SortedField(x))
                                    .ToArray()
                }));
            }
        }