parent
e232b7b11a
commit
1e86517d37
@ -3676,15 +3676,16 @@ namespace RMuseum.Controllers
|
||||
/// <param name="relatedPoetId"></param>
|
||||
/// <param name="breakOnFirstSimilar"></param>
|
||||
/// <param name="relatedSubCatId"></param>
|
||||
/// <param name="insertReverse"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("quoted/discover/{poetId}/{relatedPoetId}/{breakOnFirstSimilar}/{relatedSubCatId}")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public IActionResult StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar = false, int relatedSubCatId = 0)
|
||||
public IActionResult StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar = false, int relatedSubCatId = 0, bool insertReverse = false)
|
||||
{
|
||||
|
||||
var res = _ganjoorService.StartDiscoverRelatedPoems(poetId, relatedPoetId, breakOnFirstSimilar, relatedSubCatId == 0 ? null : relatedSubCatId);
|
||||
var res = _ganjoorService.StartDiscoverRelatedPoems(poetId, relatedPoetId, breakOnFirstSimilar, relatedSubCatId == 0 ? null : relatedSubCatId, insertReverse);
|
||||
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
|
||||
@ -2019,7 +2019,7 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.StartDiscoverRelatedPoems(System.Int32,System.Int32,System.Boolean,System.Int32)">
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.StartDiscoverRelatedPoems(System.Int32,System.Int32,System.Boolean,System.Int32,System.Boolean)">
|
||||
<summary>
|
||||
discover related poems
|
||||
</summary>
|
||||
@ -2027,6 +2027,7 @@
|
||||
<param name="relatedPoetId"></param>
|
||||
<param name="breakOnFirstSimilar"></param>
|
||||
<param name="relatedSubCatId"></param>
|
||||
<param name="insertReverse"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.GetGanjoorQuotedPoemsForPoemAsync(System.Int32,System.Int32,System.Int32,System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean})">
|
||||
@ -15593,7 +15594,7 @@
|
||||
<param name="editingUserId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.StartDiscoverRelatedPoems(System.Int32,System.Int32,System.Boolean,System.Nullable{System.Int32})">
|
||||
<member name="M:RMuseum.Services.IGanjoorService.StartDiscoverRelatedPoems(System.Int32,System.Int32,System.Boolean,System.Nullable{System.Int32},System.Boolean)">
|
||||
<summary>
|
||||
discover related poems
|
||||
</summary>
|
||||
@ -15601,6 +15602,7 @@
|
||||
<param name="relatedPoetId"></param>
|
||||
<param name="breakOnFirstSimilar"></param>
|
||||
<param name="relatedSubCatId"></param>
|
||||
<param name="insertReverse"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.GetGanjoorQuotedPoemsForPoemAsync(System.Int32,System.Int32,System.Int32,System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean})">
|
||||
@ -17643,7 +17645,7 @@
|
||||
<param name="metre"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartDiscoverRelatedPoems(System.Int32,System.Int32,System.Boolean,System.Nullable{System.Int32})">
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartDiscoverRelatedPoems(System.Int32,System.Int32,System.Boolean,System.Nullable{System.Int32},System.Boolean)">
|
||||
<summary>
|
||||
discover related poems
|
||||
</summary>
|
||||
@ -17651,6 +17653,7 @@
|
||||
<param name="relatedPoetId"></param>
|
||||
<param name="breakOnFirstSimilar"></param>
|
||||
<param name="relatedSubCatId"></param>
|
||||
<param name="insertReverse"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartRegeneratingRelatedPoemsPages(System.Guid)">
|
||||
|
||||
@ -1231,8 +1231,9 @@ namespace RMuseum.Services
|
||||
/// <param name="relatedPoetId"></param>
|
||||
/// <param name="breakOnFirstSimilar"></param>
|
||||
/// <param name="relatedSubCatId"></param>
|
||||
/// <param name="insertReverse"></param>
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar, int? relatedSubCatId);
|
||||
RServiceResult<bool> StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar, int? relatedSubCatId, bool insertReverse);
|
||||
|
||||
/// <summary>
|
||||
/// get quoted poems for a poem
|
||||
|
||||
@ -25,8 +25,9 @@ namespace RMuseum.Services.Implementation
|
||||
/// <param name="relatedPoetId"></param>
|
||||
/// <param name="breakOnFirstSimilar"></param>
|
||||
/// <param name="relatedSubCatId"></param>
|
||||
/// <param name="insertReverse"></param>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar, int? relatedSubCatId)
|
||||
public RServiceResult<bool> StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar, int? relatedSubCatId, bool insertReverse)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -42,7 +43,7 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
try
|
||||
{
|
||||
await _DiscoverRelatedPoemsAsync(context, poetId, relatedPoetId, jobProgressServiceEF, job, breakOnFirstSimilar, relatedSubCatId);
|
||||
await _DiscoverRelatedPoemsAsync(context, poetId, relatedPoetId, insertReverse, jobProgressServiceEF, job, breakOnFirstSimilar, relatedSubCatId);
|
||||
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
}
|
||||
@ -81,7 +82,7 @@ namespace RMuseum.Services.Implementation
|
||||
return (float)found / total > 0.7f && AreSimilar(str2, str1, false);
|
||||
}
|
||||
|
||||
private async Task<RServiceResult<bool>> _DiscoverRelatedPoemsAsync(RMuseumDbContext context, int poetId, int relatedPoetId, LongRunningJobProgressServiceEF jobProgressServiceEF, RLongRunningJobStatus job, bool breakOnFirstSimilar, int? relatedSubCatId)
|
||||
private async Task<RServiceResult<bool>> _DiscoverRelatedPoemsAsync(RMuseumDbContext context, int poetId, int relatedPoetId, bool insertReverse, LongRunningJobProgressServiceEF jobProgressServiceEF, RLongRunningJobStatus job, bool breakOnFirstSimilar, int? relatedSubCatId)
|
||||
{
|
||||
DiscoverQuotedQueueItem discoverQuotedQueueItem = await context.DiscoverQuotedQueueItems.Where(i => i.PoetId == poetId && i.RelatedPoetId == relatedPoetId).SingleOrDefaultAsync();
|
||||
if (discoverQuotedQueueItem == null)
|
||||
@ -194,10 +195,9 @@ namespace RMuseum.Services.Implementation
|
||||
context.Add(relatedPoem);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
if (breakOnFirstSimilar)
|
||||
break;
|
||||
|
||||
var alreadyAdded2 = await context.GanjoorQuotedPoems.AsNoTracking()
|
||||
if(insertReverse)
|
||||
{
|
||||
var alreadyAdded2 = await context.GanjoorQuotedPoems.AsNoTracking()
|
||||
.AnyAsync(q => q.PoemId == otherPoem.Id &&
|
||||
q.RelatedPoemId == poem.Id
|
||||
&&
|
||||
@ -205,43 +205,45 @@ namespace RMuseum.Services.Implementation
|
||||
&&
|
||||
q.RelatedCoupletIndex == verse.CoupletIndex
|
||||
);
|
||||
if (alreadyAdded2) continue;
|
||||
if (alreadyAdded2) continue;
|
||||
|
||||
GanjoorQuotedPoem reverseRelation = new GanjoorQuotedPoem()
|
||||
{
|
||||
PoemId = otherPoem.Id,
|
||||
PoetId = relatedPoet.Id,
|
||||
RelatedPoetId = poet.Id,
|
||||
RelatedPoemId = poem.Id,
|
||||
IsPriorToRelated = !relatedPoem.IsPriorToRelated,
|
||||
ChosenForMainList = false == await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == otherPoem.Id && p.RelatedPoemId == poem.Id).AnyAsync(),
|
||||
CachedRelatedPoemPoetDeathYearInLHijri = poet.DeathYearInLHijri,
|
||||
CachedRelatedPoemPoetName = poet.Nickname,
|
||||
CachedRelatedPoemPoetUrl = poetCat.FullUrl,
|
||||
CachedRelatedPoemPoetImage = $"/api/ganjoor/poet/image{poetCat.FullUrl}.gif",
|
||||
CachedRelatedPoemFullTitle = poem.FullTitle,
|
||||
CachedRelatedPoemFullUrl = poem.FullUrl,
|
||||
SortOrder = 1000,
|
||||
Note = "",
|
||||
Published = false,
|
||||
RelatedCoupletVerse1 = relatedPoem.CoupletVerse1,
|
||||
RelatedCoupletVerse1ShouldBeEmphasized = relatedPoem.CoupletVerse1ShouldBeEmphasized,
|
||||
RelatedCoupletVerse2 = relatedPoem.CoupletVerse2,
|
||||
RelatedCoupletVerse2ShouldBeEmphasized = relatedPoem.CoupletVerse2ShouldBeEmphasized,
|
||||
RelatedCoupletIndex = relatedPoem.CoupletIndex,
|
||||
CoupletVerse1 = relatedPoem.RelatedCoupletVerse1,
|
||||
CoupletVerse1ShouldBeEmphasized = relatedPoem.RelatedCoupletVerse1ShouldBeEmphasized,
|
||||
CoupletVerse2 = relatedPoem.RelatedCoupletVerse2,
|
||||
CoupletVerse2ShouldBeEmphasized = relatedPoem.RelatedCoupletVerse2ShouldBeEmphasized,
|
||||
CoupletIndex = relatedPoem.RelatedCoupletIndex,
|
||||
ClaimedByBothPoets = false,
|
||||
IndirectQuotation = false,
|
||||
SamePoemsQuotedCount = await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == otherPoem.Id && p.RelatedPoemId == poem.Id).AnyAsync() ?
|
||||
1 + await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == otherPoem.Id && p.RelatedPoemId == poem.Id).CountAsync() : 1
|
||||
GanjoorQuotedPoem reverseRelation = new GanjoorQuotedPoem()
|
||||
{
|
||||
PoemId = otherPoem.Id,
|
||||
PoetId = relatedPoet.Id,
|
||||
RelatedPoetId = poet.Id,
|
||||
RelatedPoemId = poem.Id,
|
||||
IsPriorToRelated = !relatedPoem.IsPriorToRelated,
|
||||
ChosenForMainList = false == await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == otherPoem.Id && p.RelatedPoemId == poem.Id).AnyAsync(),
|
||||
CachedRelatedPoemPoetDeathYearInLHijri = poet.DeathYearInLHijri,
|
||||
CachedRelatedPoemPoetName = poet.Nickname,
|
||||
CachedRelatedPoemPoetUrl = poetCat.FullUrl,
|
||||
CachedRelatedPoemPoetImage = $"/api/ganjoor/poet/image{poetCat.FullUrl}.gif",
|
||||
CachedRelatedPoemFullTitle = poem.FullTitle,
|
||||
CachedRelatedPoemFullUrl = poem.FullUrl,
|
||||
SortOrder = 1000,
|
||||
Note = "",
|
||||
Published = false,
|
||||
RelatedCoupletVerse1 = relatedPoem.CoupletVerse1,
|
||||
RelatedCoupletVerse1ShouldBeEmphasized = relatedPoem.CoupletVerse1ShouldBeEmphasized,
|
||||
RelatedCoupletVerse2 = relatedPoem.CoupletVerse2,
|
||||
RelatedCoupletVerse2ShouldBeEmphasized = relatedPoem.CoupletVerse2ShouldBeEmphasized,
|
||||
RelatedCoupletIndex = relatedPoem.CoupletIndex,
|
||||
CoupletVerse1 = relatedPoem.RelatedCoupletVerse1,
|
||||
CoupletVerse1ShouldBeEmphasized = relatedPoem.RelatedCoupletVerse1ShouldBeEmphasized,
|
||||
CoupletVerse2 = relatedPoem.RelatedCoupletVerse2,
|
||||
CoupletVerse2ShouldBeEmphasized = relatedPoem.RelatedCoupletVerse2ShouldBeEmphasized,
|
||||
CoupletIndex = relatedPoem.RelatedCoupletIndex,
|
||||
ClaimedByBothPoets = false,
|
||||
IndirectQuotation = false,
|
||||
SamePoemsQuotedCount = await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == otherPoem.Id && p.RelatedPoemId == poem.Id).AnyAsync() ?
|
||||
1 + await context.GanjoorQuotedPoems.AsNoTracking().Where(p => p.PoemId == otherPoem.Id && p.RelatedPoemId == poem.Id).CountAsync() : 1
|
||||
|
||||
};
|
||||
context.Add(reverseRelation);
|
||||
await context.SaveChangesAsync();
|
||||
};
|
||||
context.Add(reverseRelation);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
if (breakOnFirstSimilar)
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user