public HttpResponseMessage MoreLikeThisGet() { var nameValueCollection = new NameValueCollection(); foreach (var queryNameValuePair in InnerRequest.GetQueryNameValuePairs()) { nameValueCollection.Add(queryNameValuePair.Key, queryNameValuePair.Value); } var parameters = GetParametersFromPath(GetRequestUrl(), nameValueCollection); parameters.TransformerParameters = ExtractTransformerParameters(); parameters.ResultsTransformer = GetQueryStringValue("resultsTransformer"); parameters.Includes = GetQueryStringValues("include"); var index = Database.IndexStorage.GetIndexInstance(parameters.IndexName); if (index == null) { return(GetMessageWithObject(new { Error = "The index " + parameters.IndexName + " cannot be found" }, HttpStatusCode.NotFound)); } var indexEtag = Database.Indexes.GetIndexEtag(parameters.IndexName, null); if (MatchEtag(indexEtag)) { return(GetEmptyMessage(HttpStatusCode.NotModified)); } var result = Database.ExecuteMoreLikeThisQuery(parameters, GetRequestTransaction(), GetPageSize(Database.Configuration.MaxPageSize), Database.IndexQueryTriggers); if (MatchEtag(result.Etag)) { return(GetEmptyMessage(HttpStatusCode.NotModified)); } var msg = GetMessageWithObject(result.Result); WriteETag(result.Etag, msg); return(msg); }
public Dictionary <string, RavenJToken> ExtractTransformerParameters() { var result = new Dictionary <string, RavenJToken>(); foreach (var key in InnerRequest.GetQueryNameValuePairs().Select(pair => pair.Key)) { if (string.IsNullOrEmpty(key)) { continue; } if (key.StartsWith("qp-") || key.StartsWith("tp-")) { var realkey = key.Substring(3); result[realkey] = GetQueryStringValue(key); } } return(result); }
private Dictionary <string, SortOptions> GetSortHints() { var result = new Dictionary <string, SortOptions>(); // backward compatibility foreach (var header in InnerRequest.Headers.Where(pair => pair.Key.StartsWith("SortHint-"))) { SortOptions sort; Enum.TryParse(GetHeader(header.Key), true, out sort); result[Uri.UnescapeDataString(header.Key)] = sort; } foreach (var pair in InnerRequest.GetQueryNameValuePairs().Where(pair => pair.Key.StartsWith("SortHint-", StringComparison.OrdinalIgnoreCase))) { var key = pair.Key; var value = pair.Value != null?Uri.UnescapeDataString(pair.Value) : null; SortOptions sort; Enum.TryParse(value, true, out sort); result[Uri.UnescapeDataString(key)] = sort; } return(result); }
public string[] GetQueryStringValues(string key) { var items = InnerRequest.GetQueryNameValuePairs().Where(pair => pair.Key == key); return(items.Select(pair => (pair.Value != null) ? Uri.UnescapeDataString(pair.Value) : null).ToArray()); }