|
|
|
@ -50,31 +50,52 @@ namespace Squidex.Domain.Apps.Entities.Contents.Text.Elastic |
|
|
|
|
|
|
|
public async Task ExecuteAsync(params IndexCommand[] commands) |
|
|
|
{ |
|
|
|
var args = new List<object>(); |
|
|
|
|
|
|
|
foreach (var command in commands) |
|
|
|
{ |
|
|
|
switch (command) |
|
|
|
{ |
|
|
|
case UpsertIndexEntry upsert: |
|
|
|
await UpsertAsync(upsert); |
|
|
|
Upsert(upsert, args); |
|
|
|
break; |
|
|
|
case UpdateIndexEntry update: |
|
|
|
await UpdateAsync(update); |
|
|
|
Update(update, args); |
|
|
|
break; |
|
|
|
case DeleteIndexEntry delete: |
|
|
|
await DeleteAsync(delete); |
|
|
|
Delete(delete, args); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (args.Count > 0) |
|
|
|
{ |
|
|
|
var result = await client.BulkAsync<StringResponse>(PostData.MultiJson(args)); |
|
|
|
|
|
|
|
if (!result.Success) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException($"Failed with ${result.Body}", result.OriginalException); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (waitForTesting) |
|
|
|
{ |
|
|
|
await Task.Delay(1000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task UpsertAsync(UpsertIndexEntry upsert) |
|
|
|
private void Upsert(UpsertIndexEntry upsert, List<object> args) |
|
|
|
{ |
|
|
|
args.Add(new |
|
|
|
{ |
|
|
|
var data = new |
|
|
|
index = new |
|
|
|
{ |
|
|
|
_id = upsert.DocId, |
|
|
|
_index = indexName, |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
args.Add(new |
|
|
|
{ |
|
|
|
appId = upsert.AppId.Id.ToString(), |
|
|
|
appName = upsert.AppId.Name, |
|
|
|
@ -84,38 +105,40 @@ namespace Squidex.Domain.Apps.Entities.Contents.Text.Elastic |
|
|
|
serveAll = upsert.ServeAll, |
|
|
|
servePublished = upsert.ServePublished, |
|
|
|
texts = upsert.Texts |
|
|
|
}; |
|
|
|
|
|
|
|
var result = await client.IndexAsync<StringResponse>(indexName, upsert.DocId, CreatePost(data)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (!result.Success) |
|
|
|
private void Update(UpdateIndexEntry update, List<object> args) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException($"Failed with ${result.Body}", result.OriginalException); |
|
|
|
} |
|
|
|
args.Add(new |
|
|
|
{ |
|
|
|
update = new |
|
|
|
{ |
|
|
|
_id = update.DocId, |
|
|
|
_index = indexName, |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
private async Task UpdateAsync(UpdateIndexEntry update) |
|
|
|
{ |
|
|
|
var data = new |
|
|
|
args.Add(new |
|
|
|
{ |
|
|
|
doc = new |
|
|
|
{ |
|
|
|
serveAll = update.ServeAll, |
|
|
|
servePublished = update.ServePublished |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
var result = await client.UpdateAsync<StringResponse>(indexName, update.DocId, CreatePost(data)); |
|
|
|
|
|
|
|
if (!result.Success) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException($"Failed with ${result.Body}", result.OriginalException); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private Task DeleteAsync(DeleteIndexEntry delete) |
|
|
|
private void Delete(DeleteIndexEntry delete, List<object> args) |
|
|
|
{ |
|
|
|
args.Add(new |
|
|
|
{ |
|
|
|
return client.DeleteAsync<StringResponse>(indexName, delete.DocId); |
|
|
|
delete = new |
|
|
|
{ |
|
|
|
_id = delete.DocId, |
|
|
|
_index = indexName, |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<List<DomainId>?> SearchAsync(string? queryText, IAppEntity app, SearchFilter? filter, SearchScope scope) |
|
|
|
|