This commit is contained in:
Hamid Reza Mohammadi 2023-12-24 18:59:31 +03:30
parent d14666ccab
commit 11a0e28454
4 changed files with 43 additions and 12 deletions

View File

@ -3674,15 +3674,17 @@ namespace RMuseum.Controllers
/// </summary>
/// <param name="poetId"></param>
/// <param name="relatedPoetId"></param>
/// <param name="breakOnFirstSimilar"></param>
/// <param name="relatedSubCatId"></param>
/// <returns></returns>
[HttpPost("quoted/discover/{poetId}/{relatedPoetId}")]
[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)
public IActionResult StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar = false, int relatedSubCatId = 0)
{
var res = _ganjoorService.StartDiscoverRelatedPoems(poetId, relatedPoetId);
var res = _ganjoorService.StartDiscoverRelatedPoems(poetId, relatedPoetId, breakOnFirstSimilar, relatedSubCatId == 0 ? null : relatedSubCatId);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);

View File

@ -2019,12 +2019,14 @@
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.StartDiscoverRelatedPoems(System.Int32,System.Int32)">
<member name="M:RMuseum.Controllers.GanjoorController.StartDiscoverRelatedPoems(System.Int32,System.Int32,System.Boolean,System.Int32)">
<summary>
discover related poems
</summary>
<param name="poetId"></param>
<param name="relatedPoetId"></param>
<param name="breakOnFirstSimilar"></param>
<param name="relatedSubCatId"></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})">
@ -15591,12 +15593,14 @@
<param name="editingUserId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.StartDiscoverRelatedPoems(System.Int32,System.Int32)">
<member name="M:RMuseum.Services.IGanjoorService.StartDiscoverRelatedPoems(System.Int32,System.Int32,System.Boolean,System.Nullable{System.Int32})">
<summary>
discover related poems
</summary>
<param name="poetId"></param>
<param name="relatedPoetId"></param>
<param name="breakOnFirstSimilar"></param>
<param name="relatedSubCatId"></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})">
@ -17639,12 +17643,14 @@
<param name="metre"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartDiscoverRelatedPoems(System.Int32,System.Int32)">
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartDiscoverRelatedPoems(System.Int32,System.Int32,System.Boolean,System.Nullable{System.Int32})">
<summary>
discover related poems
</summary>
<param name="poetId"></param>
<param name="relatedPoetId"></param>
<param name="breakOnFirstSimilar"></param>
<param name="relatedSubCatId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartRegeneratingRelatedPoemsPages(System.Guid)">

View File

@ -1229,8 +1229,10 @@ namespace RMuseum.Services
/// </summary>
/// <param name="poetId"></param>
/// <param name="relatedPoetId"></param>
/// <param name="breakOnFirstSimilar"></param>
/// <param name="relatedSubCatId"></param>
/// <returns></returns>
RServiceResult<bool> StartDiscoverRelatedPoems(int poetId, int relatedPoetId);
RServiceResult<bool> StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar, int? relatedSubCatId);
/// <summary>
/// get quoted poems for a poem

View File

@ -23,8 +23,10 @@ namespace RMuseum.Services.Implementation
/// </summary>
/// <param name="poetId"></param>
/// <param name="relatedPoetId"></param>
/// <param name="breakOnFirstSimilar"></param>
/// <param name="relatedSubCatId"></param>
/// <returns></returns>
public RServiceResult<bool> StartDiscoverRelatedPoems(int poetId, int relatedPoetId)
public RServiceResult<bool> StartDiscoverRelatedPoems(int poetId, int relatedPoetId, bool breakOnFirstSimilar, int? relatedSubCatId)
{
try
{
@ -40,7 +42,7 @@ namespace RMuseum.Services.Implementation
try
{
await _DiscoverRelatedPoemsAsync(context, poetId, relatedPoetId, jobProgressServiceEF, job);
await _DiscoverRelatedPoemsAsync(context, poetId, relatedPoetId, jobProgressServiceEF, job, breakOnFirstSimilar, relatedSubCatId);
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
}
@ -79,7 +81,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)
private async Task<RServiceResult<bool>> _DiscoverRelatedPoemsAsync(RMuseumDbContext context, int poetId, int relatedPoetId, 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)
@ -101,6 +103,13 @@ namespace RMuseum.Services.Implementation
var relatedPoetCat = await context.GanjoorCategories.AsNoTracking().Where(c => c.PoetId == relatedPoetId && c.ParentId == null).SingleAsync();
bool isPriorToRelated = poet.DeathYearInLHijri < relatedPoet.DeathYearInLHijri;
List<int> catIdList = new List<int>();
if (relatedSubCatId != null)
{
catIdList.Add((int)relatedSubCatId);
await _populateCategoryChildren(_context, (int)relatedSubCatId, catIdList);
}
var poems = await context.GanjoorPoems.AsNoTracking().Include(p => p.Cat).Where(p => p.Id >= discoverQuotedQueueItem.PoemId && p.Cat.PoetId == poetId).OrderBy(p => p.Id).ToListAsync();
foreach (var poem in poems)
@ -115,7 +124,10 @@ namespace RMuseum.Services.Implementation
&& v.VersePosition != VersePosition.Comment
&& v.CoupletIndex != null
).OrderBy(v => v.VOrder).ToListAsync();
var relatedPoems = await context.GanjoorPoems.AsNoTracking().Include(p => p.Cat).Where(p => p.Id >= discoverQuotedQueueItem.RelatedPoemId && p.Cat.PoetId == relatedPoetId).OrderBy(p => p.Id).ToListAsync();
var relatedPoems = await context.GanjoorPoems.AsNoTracking().Include(p => p.Cat)
.Where(p => p.Id >= discoverQuotedQueueItem.RelatedPoemId && p.Cat.PoetId == relatedPoetId && (relatedSubCatId == null || catIdList.Contains(p.CatId)))
.OrderBy(p => p.Id).ToListAsync();
foreach (var otherPoem in relatedPoems)
{
discoverQuotedQueueItem.RelatedPoetId = otherPoem.Id;
@ -190,7 +202,13 @@ namespace RMuseum.Services.Implementation
&&
q.RelatedCoupletIndex == verse.CoupletIndex
);
if (alreadyAdded2) continue;
if (alreadyAdded2)
{
if (breakOnFirstSimilar)
break;
else
continue;
}
GanjoorQuotedPoem reverseRelation = new GanjoorQuotedPoem()
{
@ -228,6 +246,9 @@ namespace RMuseum.Services.Implementation
context.Add(reverseRelation);
await context.SaveChangesAsync();
if (breakOnFirstSimilar)
break;
}
}
}