diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs
index bcc59a4a..1d374b48 100644
--- a/RMuseum/Controllers/GanjoorController.cs
+++ b/RMuseum/Controllers/GanjoorController.cs
@@ -1599,6 +1599,7 @@ namespace RMuseum.Controllers
///
///
///
+ ///
///
[HttpGet]
[Route("comments")]
@@ -1606,9 +1607,9 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
- public async Task GetRecentComments([FromQuery] PagingParameterModel paging, Guid? filterUserId = null)
+ public async Task 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);
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index af7ede0c..5cde47fd 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -1342,12 +1342,13 @@
-
+
get recent comments
+
@@ -11490,7 +11491,7 @@
-
+
get recent comments
@@ -11498,6 +11499,7 @@
Guid.Empty
+
@@ -14038,7 +14040,7 @@
-
+
get recent comments
@@ -14046,6 +14048,7 @@
+
diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs
index f7ee6d42..c534edd9 100644
--- a/RMuseum/Services/IGanjoorService.cs
+++ b/RMuseum/Services/IGanjoorService.cs
@@ -404,8 +404,9 @@ namespace RMuseum.Services
/// Guid.Empty
///
///
+ ///
///
- Task> GetRecentComments(PagingParameterModel paging, Guid filterUserId, bool onlyPublished, bool onlyAwaiting = false);
+ Task> GetRecentComments(PagingParameterModel paging, Guid filterUserId, bool onlyPublished, bool onlyAwaiting = false, string term = null);
///
/// report a comment
diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs
index e6cfb877..95533a04 100644
--- a/RMuseum/Services/Implementation/GanjoorService.cs
+++ b/RMuseum/Services/Implementation/GanjoorService.cs
@@ -1190,9 +1190,43 @@ namespace RMuseum.Services.Implementation
///
///
///
+ ///
///
- public async Task> GetRecentComments(PagingParameterModel paging, Guid filterUserId, bool onlyPublished, bool onlyAwaiting = false)
+ public async Task> 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()
{