public static async Task <SearchResponse <T> > SearchAsync <T>(this IIndexManager indexManager, string indexName, SearchRequest request, CancellationToken cancellationToken) where T : class { // Validate parameters. if (indexManager == null) { throw new ArgumentNullException(nameof(indexManager)); } if (string.IsNullOrWhiteSpace(indexName)) { throw new ArgumentNullException(nameof(indexName)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } // Get the index. var index = (IIndex <T>) await indexManager.GetIndexAsync(indexName, cancellationToken).ConfigureAwait(false); // Get the read operations. IIndexReadOperations <T> ro = await index.GetReadOperationsAsync(cancellationToken).ConfigureAwait(false); // Search. return(await ro.SearchAsync(request, cancellationToken).ConfigureAwait(false)); }
public static async Task <IReadOnlyCollection <T> > GetAsync <T>( this IIndexReadOperations <T> readOperations, IEnumerable <object> ids, CancellationToken cancellationToken) where T : class { // Validate parameters. if (readOperations == null) { throw new ArgumentNullException(nameof(readOperations)); } if (ids == null) { throw new ArgumentNullException(nameof(ids)); } // Materialize. IReadOnlyCollection <object> materializedIds = ids.ToReadOnlyCollection(); // If no items, return. if (materializedIds.Count == 0) { return(ReadOnlyCollectionExtensions.Empty <T>()); } // Create the request. var request = new GetRequest { Ids = materializedIds, Take = materializedIds.Count }; // Return the response. return((await readOperations.GetAsync(request, cancellationToken) .ConfigureAwait(false)).Hits.Select(h => h.Item).ToReadOnlyCollection()); }
public async Task <GetResponse <object> > GetAsync(IEnumerable <object> ids, CancellationToken cancellationToken) { // Validate parameters. if (ids == null) { throw new ArgumentNullException(nameof(ids)); } // Get the read only operations. IIndexReadOperations <T> readOperations = await _index.GetReadOperationsAsync(cancellationToken) .ConfigureAwait(false); // Create the get request. var request = new GetRequest { Ids = ids.ToReadOnlyCollection() }; // Get. GetResponse <T> response = await readOperations.GetAsync(request, cancellationToken) .ConfigureAwait(false); // Yield the results. return(new GetResponse <object> { Request = response.Request, TotalHits = response.TotalHits, Hits = response .Hits .Select(h => new Hit <object> { Highlights = h.Highlights, Id = h.Id, Index = h.Index, Item = h.Item, Score = h.Score }) .ToReadOnlyCollection() }); }
public static async Task <T> GetAsync <T>( this IIndexReadOperations <T> readOperations, object id, CancellationToken cancellationToken) where T : class => (await readOperations.GetAsync(cancellationToken, id).ConfigureAwait(false)) .SingleOrDefault();
public static Task <IReadOnlyCollection <T> > GetAsync <T>( this IIndexReadOperations <T> readOperations, CancellationToken cancellationToken, params object[] ids) where T : class => readOperations.GetAsync(ids, cancellationToken);