Exemple #1
0
        /// <summary>
        /// Gets the index query URL.
        /// </summary>
        /// <param name="operationUrl">The operation URL.</param>
        /// <param name="index">The index.</param>
        /// <param name="operationName">Name of the operation.</param>
        /// <returns></returns>
        public string GetIndexQueryUrl(string operationUrl, string index, string operationName)
        {
            if (operationUrl.EndsWith("/"))
            {
                operationUrl = operationUrl.Substring(0, operationUrl.Length - 1);
            }
            var path = new StringBuilder()
                       .Append(operationUrl)
                       .Append("/")
                       .Append(operationName)
                       .Append("/")
                       .Append(index)
                       .Append("?query=").Append(Uri.EscapeUriString(Uri.EscapeDataString(Query ?? "")))
                       .Append("&start=").Append(Start)
                       .Append("&pageSize=").Append(PageSize)
                       .Append("&aggregation=").Append(AggregationOperation);

            FieldsToFetch.Apply(field => path.Append("&fetch=").Append(Uri.EscapeDataString(field)));
            GroupBy.Apply(field => path.Append("&groupBy=").Append(Uri.EscapeDataString(field)));
            SortedFields.Apply(field => path.Append("&sort=").Append(field.Descending ? "-" : "").Append(Uri.EscapeDataString(field.Field)));

            if (Cutoff != null)
            {
                var cutOffAsString =
                    Uri.EscapeUriString(Uri.EscapeDataString(Cutoff.Value.ToString("o", CultureInfo.InvariantCulture)));
                path.Append("&cutOff=").Append(cutOffAsString);
            }
            var vars = GetCustomQueryStringVariables();

            if (!string.IsNullOrEmpty(vars))
            {
                path.Append(vars.StartsWith("&") ? vars : ("&" + vars));
            }

            return(path.ToString());
        }