#419 search term in similarity finder

This commit is contained in:
Hamid Reza Mohammadi 2023-12-29 08:30:28 +03:30
parent 1e86517d37
commit cb394c1e62
4 changed files with 37 additions and 7 deletions

View File

@ -2388,6 +2388,7 @@ namespace RMuseum.Controllers
/// <param name="catId">send 0 for all</param>
/// <param name="language"></param>
/// <param name="format"></param>
/// <param name="term"></param>
/// <returns>return value is not complete or valid for some parts, you should use only the valid parts!</returns>
[HttpGet]
@ -2396,9 +2397,9 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<GanjoorPoemCompleteViewModel>))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> GetSimilarPoems([FromQuery] PagingParameterModel paging, string metre, string rhyme, int poetId = 0, int catId = 0, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown)
public async Task<IActionResult> GetSimilarPoems([FromQuery] PagingParameterModel paging, string metre, string rhyme, int poetId = 0, int catId = 0, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown, string term = null)
{
var pagedResult = await _ganjoorService.GetSimilarPoems(paging, metre, rhyme, poetId == 0 ? null : poetId, catId == 0 ? null : catId, language, format);
var pagedResult = await _ganjoorService.GetSimilarPoems(paging, metre, rhyme, poetId == 0 ? null : poetId, catId == 0 ? null : catId, language, format, term);
if (!string.IsNullOrEmpty(pagedResult.ExceptionString))
return BadRequest(pagedResult.ExceptionString);

View File

@ -1595,7 +1595,7 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Int32,System.Int32,System.String,RMuseum.Models.Ganjoor.GanjoorPoemFormat)">
<member name="M:RMuseum.Controllers.GanjoorController.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Int32,System.Int32,System.String,RMuseum.Models.Ganjoor.GanjoorPoemFormat,System.String)">
<summary>
Get Similar Poems accroding to prosody and rhyme informations
</summary>
@ -1606,6 +1606,7 @@
<param name="catId">send 0 for all</param>
<param name="language"></param>
<param name="format"></param>
<param name="term"></param>
<returns>return value is not complete or valid for some parts, you should use only the valid parts!</returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetLanguageTaggedPoemSections(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.Int32)">
@ -14856,7 +14857,7 @@
<param name="paging"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Nullable{System.Int32},System.Nullable{System.Int32},System.String,RMuseum.Models.Ganjoor.GanjoorPoemFormat)">
<member name="M:RMuseum.Services.IGanjoorService.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Nullable{System.Int32},System.Nullable{System.Int32},System.String,RMuseum.Models.Ganjoor.GanjoorPoemFormat,System.String)">
<summary>
Get Similar Poems accroding to prosody and rhyme informations
</summary>
@ -14867,6 +14868,7 @@
<param name="catId"></param>
<param name="language"></param>
<param name="format"></param>
<param name="term"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.GetLanguageTaggedPoemSections(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.Nullable{System.Int32})">
@ -18292,7 +18294,7 @@
<param name="recitation"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Nullable{System.Int32},System.Nullable{System.Int32},System.String,RMuseum.Models.Ganjoor.GanjoorPoemFormat)">
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetSimilarPoems(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.String,System.Nullable{System.Int32},System.Nullable{System.Int32},System.String,RMuseum.Models.Ganjoor.GanjoorPoemFormat,System.String)">
<summary>
Get Similar Poems accroding to prosody and rhyme informations
</summary>
@ -18303,6 +18305,7 @@
<param name="language"></param>
<param name="format"></param>
<param name="catId"></param>
<param name="term"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetLanguageTaggedPoemSections(RSecurityBackend.Models.Generic.PagingParameterModel,System.String,System.Nullable{System.Int32})">

View File

@ -482,8 +482,9 @@ namespace RMuseum.Services
/// <param name="catId"></param>
/// <param name="language"></param>
/// <param name="format"></param>
/// <param name="term"></param>
/// <returns></returns>
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId, int? catId, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown);
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId, int? catId, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown, string term = null);
/// <summary>
/// language tagged poem sections

View File

@ -2485,8 +2485,9 @@ namespace RMuseum.Services.Implementation
/// <param name="language"></param>
/// <param name="format"></param>
/// <param name="catId"></param>
/// <param name="term"></param>
/// <returns></returns>
public async Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId, int? catId, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown)
public async Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorPoemCompleteViewModel[] Items)>> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId, int? catId, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown, string term = null)
{
if (poetId == null)
{
@ -2498,6 +2499,28 @@ namespace RMuseum.Services.Implementation
catIdList.Add((int)catId);
await _populateCategoryChildren(_context, (int)catId, catIdList);
}
string searchConditions = "";
if (!string.IsNullOrEmpty(term))
{
term = term.Replace("‌", " ");//replace zwnj with space
if (term.IndexOf('"') == 0 && term.LastIndexOf('"') == (term.Length - 1))
{
searchConditions = term.Replace("\"", "").Replace("'", "");
searchConditions = $"\"{searchConditions}\"";
}
else
{
string[] words = term.Replace("\"", "").Replace("'", "").Split(' ', StringSplitOptions.RemoveEmptyEntries);
searchConditions = "";
string emptyOrAnd = "";
foreach (string word in words)
{
searchConditions += $" {emptyOrAnd} \"*{word}*\" ";
emptyOrAnd = " AND ";
}
}
}
var source =
_context.GanjoorPoemSections.Include(s => s.Poem).Include(s => s.Poet).Include(s => s.GanjoorMetre)
.Where(s =>
@ -2512,6 +2535,8 @@ namespace RMuseum.Services.Implementation
(format == GanjoorPoemFormat.Unknown || s.PoemFormat == format)
&&
(catId == null || catIdList.Contains(s.Poem.CatId))
&&
(searchConditions == "" || (searchConditions != "" && EF.Functions.Contains(s.Poem.PlainText, searchConditions)))
)
.OrderBy(p => p.Poet.BirthYearInLHijri).ThenBy(p => p.Poet.Nickname).ThenBy(p => p.SectionType).ThenBy(p => p.Poem.Id)
.Select