diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 9f530614..f0792597 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -2388,6 +2388,7 @@ namespace RMuseum.Controllers /// send 0 for all /// /// + /// /// return value is not complete or valid for some parts, you should use only the valid parts! [HttpGet] @@ -2396,9 +2397,9 @@ namespace RMuseum.Controllers [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] - public async Task 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 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); diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index d65179d5..a0a65dae 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -1595,7 +1595,7 @@ - + Get Similar Poems accroding to prosody and rhyme informations @@ -1606,6 +1606,7 @@ send 0 for all + return value is not complete or valid for some parts, you should use only the valid parts! @@ -14856,7 +14857,7 @@ - + Get Similar Poems accroding to prosody and rhyme informations @@ -14867,6 +14868,7 @@ + @@ -18292,7 +18294,7 @@ - + Get Similar Poems accroding to prosody and rhyme informations @@ -18303,6 +18305,7 @@ + diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 34827ddf..aced0a17 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -482,8 +482,9 @@ namespace RMuseum.Services /// /// /// + /// /// - Task> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId, int? catId, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown); + Task> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId, int? catId, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown, string term = null); /// /// language tagged poem sections diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 65a36ff6..d06315fe 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -2485,8 +2485,9 @@ namespace RMuseum.Services.Implementation /// /// /// + /// /// - public async Task> GetSimilarPoems(PagingParameterModel paging, string metre, string rhyme, int? poetId, int? catId, string language = "fa-IR", GanjoorPoemFormat format = GanjoorPoemFormat.Unknown) + public async Task> 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