docs: #315 search in comments API

This commit is contained in:
Hamid Reza Mohammadi 2022-05-04 20:57:27 +04:30
parent d101a71182
commit 2900edff38
4 changed files with 48 additions and 7 deletions

View File

@ -1599,6 +1599,7 @@ namespace RMuseum.Controllers
/// </summary>
/// <param name="paging"></param>
/// <param name="filterUserId"></param>
/// <param name="term"></param>
/// <returns></returns>
[HttpGet]
[Route("comments")]
@ -1606,9 +1607,9 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<GanjoorCommentFullViewModel>))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> GetRecentComments([FromQuery] PagingParameterModel paging, Guid? filterUserId = null)
public async Task<IActionResult> GetRecentComments([FromQuery] PagingParameterModel paging, Guid? filterUserId = null, string term = null)
{
var comments = await _ganjoorService.GetRecentComments(paging, filterUserId == null ? Guid.Empty : (Guid)filterUserId, true);
var comments = await _ganjoorService.GetRecentComments(paging, filterUserId == null ? Guid.Empty : (Guid)filterUserId, true, false, term);
if (!string.IsNullOrEmpty(comments.ExceptionString))
{
return BadRequest(comments.ExceptionString);

View File

@ -1342,12 +1342,13 @@
<param name="poetId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetRecentComments(RSecurityBackend.Models.Generic.PagingParameterModel,System.Nullable{System.Guid})">
<member name="M:RMuseum.Controllers.GanjoorController.GetRecentComments(RSecurityBackend.Models.Generic.PagingParameterModel,System.Nullable{System.Guid},System.String)">
<summary>
get recent comments
</summary>
<param name="paging"></param>
<param name="filterUserId"></param>
<param name="term"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.GetMyRecentComments(RSecurityBackend.Models.Generic.PagingParameterModel)">
@ -11490,7 +11491,7 @@
<param name="commentId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.GetRecentComments(RSecurityBackend.Models.Generic.PagingParameterModel,System.Guid,System.Boolean,System.Boolean)">
<member name="M:RMuseum.Services.IGanjoorService.GetRecentComments(RSecurityBackend.Models.Generic.PagingParameterModel,System.Guid,System.Boolean,System.Boolean,System.String)">
<summary>
get recent comments
</summary>
@ -11498,6 +11499,7 @@
<param name="filterUserId">Guid.Empty</param>
<param name="onlyPublished"></param>
<param name="onlyAwaiting"></param>
<param name="term"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.ReportComment(System.Guid,RMuseum.Models.Ganjoor.ViewModels.GanjoorPostReportCommentViewModel)">
@ -14038,7 +14040,7 @@
<param name="commentId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetRecentComments(RSecurityBackend.Models.Generic.PagingParameterModel,System.Guid,System.Boolean,System.Boolean)">
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetRecentComments(RSecurityBackend.Models.Generic.PagingParameterModel,System.Guid,System.Boolean,System.Boolean,System.String)">
<summary>
get recent comments
</summary>
@ -14046,6 +14048,7 @@
<param name="filterUserId"></param>
<param name="onlyPublished"></param>
<param name="onlyAwaiting"></param>
<param name="term"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.ReportComment(System.Guid,RMuseum.Models.Ganjoor.ViewModels.GanjoorPostReportCommentViewModel)">

View File

@ -404,8 +404,9 @@ namespace RMuseum.Services
/// <param name="filterUserId">Guid.Empty</param>
/// <param name="onlyPublished"></param>
/// <param name="onlyAwaiting"></param>
/// <param name="term"></param>
/// <returns></returns>
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorCommentFullViewModel[] Items)>> GetRecentComments(PagingParameterModel paging, Guid filterUserId, bool onlyPublished, bool onlyAwaiting = false);
Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorCommentFullViewModel[] Items)>> GetRecentComments(PagingParameterModel paging, Guid filterUserId, bool onlyPublished, bool onlyAwaiting = false, string term = null);
/// <summary>
/// report a comment

View File

@ -1190,9 +1190,43 @@ namespace RMuseum.Services.Implementation
/// <param name="filterUserId"></param>
/// <param name="onlyPublished"></param>
/// <param name="onlyAwaiting"></param>
/// <param name="term"></param>
/// <returns></returns>
public async Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorCommentFullViewModel[] Items)>> GetRecentComments(PagingParameterModel paging, Guid filterUserId, bool onlyPublished, bool onlyAwaiting = false)
public async Task<RServiceResult<(PaginationMetadata PagingMeta, GanjoorCommentFullViewModel[] Items)>> GetRecentComments(PagingParameterModel paging, Guid filterUserId, bool onlyPublished, bool onlyAwaiting = false, string term = null)
{
string searchConditions = null;
if (!string.IsNullOrEmpty(term))
{
/// You need to run this scripts manually on the database before using this method:
///
/// CREATE FULLTEXT CATALOG [GanjoorHtmlCommentTextCatalog] WITH ACCENT_SENSITIVITY = OFF AS DEFAULT
///
/// CREATE FULLTEXT INDEX ON [dbo].[GanjoorComments](
/// [HtmlComment] LANGUAGE 'English')
/// KEY INDEX [PK_GanjoorComments]ON ([GanjoorHtmlCommentTextCatalog], FILEGROUP [PRIMARY])
/// WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
///
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 =
from comment in _context.GanjoorComments.Include(c => c.Poem).Include(c => c.User).Include(c => c.InReplyTo).ThenInclude(r => r.User)
where
@ -1201,6 +1235,8 @@ namespace RMuseum.Services.Implementation
((comment.Status == PublishStatus.Awaiting) || !onlyAwaiting)
&&
((filterUserId == Guid.Empty) || (filterUserId != Guid.Empty && comment.UserId == filterUserId))
&&
(string.IsNullOrEmpty(searchConditions) || (!string.IsNullOrEmpty(searchConditions) && EF.Functions.Contains(comment.HtmlComment, searchConditions)) )
orderby comment.CommentDate descending
select new GanjoorCommentFullViewModel()
{