public async Task <int> GetDocumentsCount(FolderIdentity folderId, CancellationToken cancellationToken) { if (folderId == null) { throw new ArgumentNullException(nameof(folderId)); } var response = await elasticClient.CountAsync <DocumentInfoModel>( cd => cd .Index(options.IndexName) .Query(qcd => qcd .Term("folderId", folderId.ToString())), cancellationToken); CheckResponse(response, "Error during getting count documents in folder"); return((int)response.Count); }
public async Task <IReadOnlyCollection <DocumentInfo> > GetDocuments(User user, FolderIdentity parentFolderId, int limit, int skip, CancellationToken cancellationToken) { var response = await elasticClient.SearchAsync <DocumentInfoModel>( sd => sd .Index(options.IndexName) .Query(qd => qd .Bool(bqd => bqd .Must( qcd => qcd.Term("id.userIdentity.keyword", user.Id), qcd => qcd.Term("folderId", parentFolderId.ToString())))) .Source(sfd => sfd.Excludes(fd => fd.Field("text"))) .Take(limit) .Skip(skip), cancellationToken); return(response.Hits.Select(x => ToDocumentInfo(x.Source, cancellationToken)).ToArray()); }
public async Task RemoveDocumentsFromFolder(FolderIdentity folderId, CancellationToken cancellationToken) { if (folderId == null) { throw new ArgumentNullException(nameof(folderId)); } var response = await elasticClient.DeleteByQueryAsync <DocumentInfoModel>(dbqd => dbqd .Index(options.IndexName) .Query(qcd => qcd .Term("parentFoldersPath", folderId.ToString())), CancellationToken.None); CheckResponse(response, $"Error occured during removing items from folder {folderId}"); }