This repository has been archived by the owner on Sep 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* obsolete disk_size and data_size * ibmcom/couchdb3 docker image * search comments removed
- Loading branch information
Showing
25 changed files
with
1,345 additions
and
1,320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
//using System.Threading.Tasks; | ||
//using EnsureThat; | ||
//using MyCouch.Extensions; | ||
//using MyCouch.HttpRequestFactories; | ||
//using MyCouch.Requests; | ||
//using MyCouch.Responses; | ||
//using MyCouch.Responses.Factories; | ||
//using MyCouch.Serialization; | ||
|
||
//namespace MyCouch.Contexts | ||
//{ | ||
// public class Searches : ApiContextBase<IDbConnection>, ISearches | ||
// { | ||
// protected SearchIndexHttpRequestFactory SearchIndexHttpRequestFactory { get; set; } | ||
// protected SearchIndexResponseFactory SearchIndexResponseFactory { get; set; } | ||
|
||
// public Searches(IDbConnection connection, ISerializer documentSerializer, ISerializer serializer) | ||
// : base(connection) | ||
// { | ||
// Ensure.That(documentSerializer, "documentSerializer").IsNotNull(); | ||
// Ensure.Any.IsNotNull(serializer, nameof(serializer)); | ||
|
||
// SearchIndexHttpRequestFactory = new SearchIndexHttpRequestFactory(serializer); | ||
// SearchIndexResponseFactory = new SearchIndexResponseFactory(documentSerializer); | ||
// } | ||
|
||
// public virtual async Task<SearchIndexResponse> SearchAsync(SearchIndexRequest request) | ||
// { | ||
// Ensure.Any.IsNotNull(request, nameof(request)); | ||
|
||
// var httpRequest = SearchIndexHttpRequestFactory.Create(request); | ||
|
||
// using (var res = await SendAsync(httpRequest).ForAwait()) | ||
// { | ||
// return await SearchIndexResponseFactory.CreateAsync(res).ForAwait(); | ||
// } | ||
// } | ||
|
||
// public virtual async Task<SearchIndexResponse<TIncludedDoc>> SearchAsync<TIncludedDoc>(SearchIndexRequest request) | ||
// { | ||
// Ensure.Any.IsNotNull(request, nameof(request)); | ||
|
||
// var httpRequest = SearchIndexHttpRequestFactory.Create(request); | ||
|
||
// using (var res = await SendAsync(httpRequest).ForAwait()) | ||
// { | ||
// return await SearchIndexResponseFactory.CreateAsync<TIncludedDoc>(res).ForAwait(); | ||
// } | ||
// } | ||
// } | ||
//} | ||
using System.Threading.Tasks; | ||
using EnsureThat; | ||
using MyCouch.Extensions; | ||
using MyCouch.HttpRequestFactories; | ||
using MyCouch.Requests; | ||
using MyCouch.Responses; | ||
using MyCouch.Responses.Factories; | ||
using MyCouch.Serialization; | ||
|
||
namespace MyCouch.Contexts | ||
{ | ||
public class Searches : ApiContextBase<IDbConnection>, ISearches | ||
{ | ||
protected SearchIndexHttpRequestFactory SearchIndexHttpRequestFactory { get; set; } | ||
protected SearchIndexResponseFactory SearchIndexResponseFactory { get; set; } | ||
|
||
public Searches(IDbConnection connection, ISerializer documentSerializer, ISerializer serializer) | ||
: base(connection) | ||
{ | ||
Ensure.That(documentSerializer, "documentSerializer").IsNotNull(); | ||
Ensure.Any.IsNotNull(serializer, nameof(serializer)); | ||
|
||
SearchIndexHttpRequestFactory = new SearchIndexHttpRequestFactory(serializer); | ||
SearchIndexResponseFactory = new SearchIndexResponseFactory(documentSerializer); | ||
} | ||
|
||
public virtual async Task<SearchIndexResponse> SearchAsync(SearchIndexRequest request) | ||
{ | ||
Ensure.Any.IsNotNull(request, nameof(request)); | ||
|
||
var httpRequest = SearchIndexHttpRequestFactory.Create(request); | ||
|
||
using (var res = await SendAsync(httpRequest).ForAwait()) | ||
{ | ||
return await SearchIndexResponseFactory.CreateAsync(res).ForAwait(); | ||
} | ||
} | ||
|
||
public virtual async Task<SearchIndexResponse<TIncludedDoc>> SearchAsync<TIncludedDoc>(SearchIndexRequest request) | ||
{ | ||
Ensure.Any.IsNotNull(request, nameof(request)); | ||
|
||
var httpRequest = SearchIndexHttpRequestFactory.Create(request); | ||
|
||
using (var res = await SendAsync(httpRequest).ForAwait()) | ||
{ | ||
return await SearchIndexResponseFactory.CreateAsync<TIncludedDoc>(res).ForAwait(); | ||
} | ||
} | ||
} | ||
} |
218 changes: 109 additions & 109 deletions
218
source/projects/MyCouch/HttpRequestFactories/SearchIndexHttpRequestFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,110 @@ | ||
//using System.Collections.Generic; | ||
//using System.Linq; | ||
//using System.Net.Http; | ||
//using EnsureThat; | ||
//using MyCouch.Net; | ||
//using MyCouch.Requests; | ||
//using MyCouch.Serialization; | ||
|
||
//namespace MyCouch.HttpRequestFactories | ||
//{ | ||
// public class SearchIndexHttpRequestFactory | ||
// { | ||
// protected ISerializer Serializer { get; private set; } | ||
|
||
// public SearchIndexHttpRequestFactory(ISerializer serializer) | ||
// { | ||
// Ensure.Any.IsNotNull(serializer, nameof(serializer)); | ||
|
||
// Serializer = serializer; | ||
// } | ||
|
||
// public virtual HttpRequest Create(SearchIndexRequest request) | ||
// { | ||
// Ensure.Any.IsNotNull(request, nameof(request)); | ||
|
||
// return new HttpRequest(HttpMethod.Get, GenerateRelativeUrl(request)) | ||
// .SetRequestTypeHeader(request.GetType()); | ||
// } | ||
|
||
// protected virtual string GenerateRelativeUrl(SearchIndexRequest request) | ||
// { | ||
// return string.Format("/_design/{0}/_search/{1}{2}", | ||
// new UrlSegment(request.IndexIdentity.DesignDocument), | ||
// new UrlSegment(request.IndexIdentity.Name), | ||
// GenerateRequestUrlQueryString(request)); | ||
// } | ||
|
||
// protected virtual string GenerateRequestUrlQueryString(SearchIndexRequest request) | ||
// { | ||
// var p = GenerateQueryStringParams(request); | ||
|
||
// return string.IsNullOrEmpty(p) ? string.Empty : string.Concat("?", p); | ||
// } | ||
|
||
// protected virtual string GenerateQueryStringParams(SearchIndexRequest request) | ||
// { | ||
// return string.Join("&", GenerateJsonCompatibleKeyValues(request) | ||
// .Select(kv => string.Format("{0}={1}", kv.Key, UrlParam.Encode(kv.Value)))); | ||
// } | ||
|
||
// protected virtual IDictionary<string, string> GenerateJsonCompatibleKeyValues(SearchIndexRequest request) | ||
// { | ||
// var kvs = new Dictionary<string, string>(); | ||
|
||
// if (!string.IsNullOrWhiteSpace(request.Expression)) | ||
// kvs.Add(KeyNames.Expression, request.Expression); | ||
|
||
// if (request.HasSortings()) | ||
// kvs.Add(KeyNames.Sort, Serializer.ToJsonArray(request.Sort.ToArray())); | ||
|
||
// if (!string.IsNullOrWhiteSpace(request.Bookmark)) | ||
// kvs.Add(KeyNames.Bookmark, request.Bookmark); | ||
|
||
// if (request.Stale.HasValue) | ||
// kvs.Add(KeyNames.Stale, request.Stale.Value.AsString()); | ||
|
||
// if (request.Limit.HasValue) | ||
// kvs.Add(KeyNames.Limit, Serializer.ToJson(request.Limit.Value)); | ||
|
||
// if (request.IncludeDocs.HasValue) | ||
// kvs.Add(KeyNames.IncludeDocs, Serializer.ToJson(request.IncludeDocs.Value)); | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using EnsureThat; | ||
using MyCouch.Net; | ||
using MyCouch.Requests; | ||
using MyCouch.Serialization; | ||
|
||
namespace MyCouch.HttpRequestFactories | ||
{ | ||
public class SearchIndexHttpRequestFactory | ||
{ | ||
protected ISerializer Serializer { get; private set; } | ||
|
||
public SearchIndexHttpRequestFactory(ISerializer serializer) | ||
{ | ||
Ensure.Any.IsNotNull(serializer, nameof(serializer)); | ||
|
||
Serializer = serializer; | ||
} | ||
|
||
public virtual HttpRequest Create(SearchIndexRequest request) | ||
{ | ||
Ensure.Any.IsNotNull(request, nameof(request)); | ||
|
||
return new HttpRequest(HttpMethod.Get, GenerateRelativeUrl(request)) | ||
.SetRequestTypeHeader(request.GetType()); | ||
} | ||
|
||
protected virtual string GenerateRelativeUrl(SearchIndexRequest request) | ||
{ | ||
return string.Format("/_design/{0}/_search/{1}{2}", | ||
new UrlSegment(request.IndexIdentity.DesignDocument), | ||
new UrlSegment(request.IndexIdentity.Name), | ||
GenerateRequestUrlQueryString(request)); | ||
} | ||
|
||
protected virtual string GenerateRequestUrlQueryString(SearchIndexRequest request) | ||
{ | ||
var p = GenerateQueryStringParams(request); | ||
|
||
return string.IsNullOrEmpty(p) ? string.Empty : string.Concat("?", p); | ||
} | ||
|
||
protected virtual string GenerateQueryStringParams(SearchIndexRequest request) | ||
{ | ||
return string.Join("&", GenerateJsonCompatibleKeyValues(request) | ||
.Select(kv => string.Format("{0}={1}", kv.Key, UrlParam.Encode(kv.Value)))); | ||
} | ||
|
||
protected virtual IDictionary<string, string> GenerateJsonCompatibleKeyValues(SearchIndexRequest request) | ||
{ | ||
var kvs = new Dictionary<string, string>(); | ||
|
||
if (!string.IsNullOrWhiteSpace(request.Expression)) | ||
kvs.Add(KeyNames.Expression, request.Expression); | ||
|
||
if (request.HasSortings()) | ||
kvs.Add(KeyNames.Sort, Serializer.ToJsonArray(request.Sort.ToArray())); | ||
|
||
if (!string.IsNullOrWhiteSpace(request.Bookmark)) | ||
kvs.Add(KeyNames.Bookmark, request.Bookmark); | ||
|
||
if (request.Stale.HasValue) | ||
kvs.Add(KeyNames.Stale, request.Stale.Value.AsString()); | ||
|
||
if (request.Limit.HasValue) | ||
kvs.Add(KeyNames.Limit, Serializer.ToJson(request.Limit.Value)); | ||
|
||
if (request.IncludeDocs.HasValue) | ||
kvs.Add(KeyNames.IncludeDocs, Serializer.ToJson(request.IncludeDocs.Value)); | ||
|
||
// if (request.Ranges != null) | ||
// kvs.Add(KeyNames.Ranges, Serializer.Serialize(request.Ranges)); | ||
|
||
// if (request.HasCounts()) | ||
// kvs.Add(KeyNames.Counts, Serializer.ToJsonArray(request.Counts.ToArray())); | ||
|
||
// if (!string.IsNullOrWhiteSpace(request.GroupField)) | ||
// kvs.Add(KeyNames.GroupField, request.GroupField); | ||
|
||
// if (request.GroupLimit.HasValue) | ||
// kvs.Add(KeyNames.GroupLimit, Serializer.ToJson(request.GroupLimit.Value)); | ||
|
||
// if (request.HasGroupSortings()) | ||
// kvs.Add(KeyNames.GroupSort, Serializer.ToJsonArray(request.GroupSort.ToArray())); | ||
|
||
// if (request.DrillDown.HasValue) | ||
// kvs.Add(KeyNames.DrillDown, Serializer.ToJsonArray(new[] { request.DrillDown.Value.Key, request.DrillDown.Value.Value })); | ||
|
||
// return kvs; | ||
// } | ||
|
||
// protected static class KeyNames | ||
// { | ||
// public const string Expression = "q"; | ||
// public const string Sort = "sort"; | ||
// public const string Bookmark = "bookmark"; | ||
// public const string Stale = "stale"; | ||
// public const string Limit = "limit"; | ||
// public const string IncludeDocs = "include_docs"; | ||
// public const string Ranges = "ranges"; | ||
// public const string Counts = "counts"; | ||
// public const string GroupField = "group_field"; | ||
// public const string GroupLimit = "group_limit"; | ||
// public const string GroupSort = "group_sort"; | ||
// public const string DrillDown = "drilldown"; | ||
// } | ||
// } | ||
//} | ||
if (request.Ranges != null) | ||
kvs.Add(KeyNames.Ranges, Serializer.Serialize(request.Ranges)); | ||
|
||
if (request.HasCounts()) | ||
kvs.Add(KeyNames.Counts, Serializer.ToJsonArray(request.Counts.ToArray())); | ||
|
||
if (!string.IsNullOrWhiteSpace(request.GroupField)) | ||
kvs.Add(KeyNames.GroupField, request.GroupField); | ||
|
||
if (request.GroupLimit.HasValue) | ||
kvs.Add(KeyNames.GroupLimit, Serializer.ToJson(request.GroupLimit.Value)); | ||
|
||
if (request.HasGroupSortings()) | ||
kvs.Add(KeyNames.GroupSort, Serializer.ToJsonArray(request.GroupSort.ToArray())); | ||
|
||
if (request.DrillDown.HasValue) | ||
kvs.Add(KeyNames.DrillDown, Serializer.ToJsonArray(new[] { request.DrillDown.Value.Key, request.DrillDown.Value.Value })); | ||
|
||
return kvs; | ||
} | ||
|
||
protected static class KeyNames | ||
{ | ||
public const string Expression = "q"; | ||
public const string Sort = "sort"; | ||
public const string Bookmark = "bookmark"; | ||
public const string Stale = "stale"; | ||
public const string Limit = "limit"; | ||
public const string IncludeDocs = "include_docs"; | ||
public const string Ranges = "ranges"; | ||
public const string Counts = "counts"; | ||
public const string GroupField = "group_field"; | ||
public const string GroupLimit = "group_limit"; | ||
public const string GroupSort = "group_sort"; | ||
public const string DrillDown = "drilldown"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.