add exception for poets in search

#460
This commit is contained in:
Hamid Reza Mohammadi 2025-01-10 18:22:59 +03:30
parent a163082039
commit da49701d3d
3 changed files with 46 additions and 14 deletions

View File

@ -29,6 +29,17 @@
cookieValue = getCookie("stickyEnabled");
var stickyEnabled = cookieValue != "false";
</script>
<script>
function deletePoetFromSearch(poetId, poetName){
if(!confirm('آیا می‌خواهید '+ poetName+ ' را از نتایج حذف کنید؟')) return;
const currentUrl = new URL(window.location.href);
const params = currentUrl.searchParams;
params.append('e', poetId.toString());
currentUrl.search = params.toString();
window.location.href = currentUrl.toString();
}
</script>
</head>
<body>
@ -188,20 +199,25 @@
var poem = Model.Poems[poemIndex];
<div class="sitem">
@if(Model.PaginationMetadata != null)
@if (Model.PaginationMetadata != null)
{
<div class="circled-number-diff">@(((Model.PaginationMetadata.currentPage - 1) * Model.PaginationMetadata.pageSize + poemIndex + 1).ToPersianNumbers())</div>
}
<h2>
<a href="@poem.FullUrl">@poem.FullTitle</a>
<a href="@poem.FullUrl">@poem.FullTitle</a>
</h2>
<div class="spacer">&nbsp;</div>
<div class="sit">
@Html.Raw(poem.PlainText)
</div>
<img src="@($"{GanjooRazor.APIRoot.InternetUrl}{poem.Category.Poet.ImageUrl}")" alt="@($"{poem.Category.Poet.Nickname}")" />
<div class="poet">
<img src="@($"{GanjooRazor.APIRoot.InternetUrl}{poem.Category.Poet.ImageUrl}")" alt="@($"{poem.Category.Poet.Nickname}")" />
<a role="button" onclick="deletePoetFromSearch(@poem.Category.Poet.Id, '@(poem.Category.Poet.Nickname)')" class="actionlink" title="حذف @($"{poem.Category.Poet.Nickname}") از نتایج"><i class="notranslate noindent-info-button delete-icon"></i></a>
</div>
<div class="spacer">&nbsp;</div>

View File

@ -74,8 +74,8 @@ namespace GanjooRazor.Pages
public List<GanjoorPoemCompleteViewModel> Poems { get; set; }
public PaginationMetadata PaginationMetadata { get; set; }
public string PagingToolsHtml { get; set; }
public string LastError { get; set; }
public int[] ExceptPoetId { get; set; }
private async Task<bool> preparePoets()
{
@ -174,7 +174,7 @@ namespace GanjooRazor.Pages
AlternativeSearchPhraseDescription = "راضی نشدید؟! ";
bool needsComma = false;
var splitteds = Query.Replace("\"", "").Split(' ');
for(int sp = 0; sp < splitteds.Length - 1; sp++)
for (int sp = 0; sp < splitteds.Length - 1; sp++)
{
var splitted = splitteds[sp];
if (needsComma)
@ -194,6 +194,7 @@ namespace GanjooRazor.Pages
PoetId = string.IsNullOrEmpty(Request.Query["author"]) ? 0 : int.Parse(Request.Query["author"]);
CatId = string.IsNullOrEmpty(Request.Query["cat"]) ? 0 : int.Parse(Request.Query["cat"]);
if (CatId != 0)
{
var catResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/cat/{CatId}?poems=false&mainSections=false");
@ -231,7 +232,7 @@ namespace GanjooRazor.Pages
var poetName = Poets.SingleOrDefault(p => p.Id == PoetId);
if (poetName != null)
{
if(CatFullTitle != "")
if (CatFullTitle != "")
{
ViewData["Title"] = $"گنجور » نتایج جستجو برای {Query} در بخش {CatFullTitle}";
}
@ -273,9 +274,24 @@ namespace GanjooRazor.Pages
HttpResponseMessage searchQueryResponse = null;
List<int> exceptPoetId = new List<int>();
foreach (var e in Request.Query["e"])
{
exceptPoetId.Add(int.Parse(e));
}
ExceptPoetId = exceptPoetId.ToArray();
string exceptUrl = "";
if (!string.IsNullOrEmpty(Query))
{
searchQueryResponse = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poems/search?term={Query}&poetId={PoetId}&catId={CatId}&PageNumber={pageNumber}&PageSize=20");
string url = $"{APIRoot.Url}/api/ganjoor/poems/search?term={Query}&poetId={PoetId}&catId={CatId}&PageNumber={pageNumber}&PageSize=20";
foreach (var e in exceptPoetId)
{
exceptUrl += $"&e={e}";
}
url += exceptUrl;
searchQueryResponse = await _httpClient.GetAsync(url);
if (!searchQueryResponse.IsSuccessStatusCode)
{
@ -330,7 +346,7 @@ namespace GanjooRazor.Pages
}
}
string plainText = "";
@ -349,7 +365,7 @@ namespace GanjooRazor.Pages
{
finalPlainText += $"<p>{line}</p>";
}
if(linesInExcerpt.Count >0 )
if (linesInExcerpt.Count > 0)
{
poem.PlainText = finalPlainText;
}
@ -375,7 +391,7 @@ namespace GanjooRazor.Pages
{
catQuery = $"&cat={Request.Query["cat"]}";
}
PagingToolsHtml = GeneratePagingBarHtml(PaginationMetadata, $"/search?s={WebUtility.UrlEncode(Query)}&amp;author={PoetId}{catQuery}");
PagingToolsHtml = GeneratePagingBarHtml(PaginationMetadata, $"/search?s={WebUtility.UrlEncode(Query)}&amp;author={PoetId}{catQuery}{exceptUrl}");
}
}

View File

@ -2474,7 +2474,7 @@ namespace RMuseum.Controllers
/// <param name="term"></param>
/// <param name="poetId"></param>
/// <param name="catId"></param>
/// <param name="exceptPoetId"></param>
/// <param name="e"></param>
/// <returns></returns>
[HttpGet]
[Route("poems/search")]
@ -2482,9 +2482,9 @@ namespace RMuseum.Controllers
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<GanjoorPoemCompleteViewModel>))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> Search([FromQuery] PagingParameterModel paging, string term, int poetId = 0, int catId = 0, int[] exceptPoetId = null)
public async Task<IActionResult> Search([FromQuery] PagingParameterModel paging, string term, int poetId = 0, int catId = 0, int[] e = null)
{
var pagedResult = await _ganjoorService.Search(paging, term, poetId == 0 ? (int?)null : poetId, catId == 0 ? (int?)null : catId, exceptPoetId == null ?[] : exceptPoetId);
var pagedResult = await _ganjoorService.Search(paging, term, poetId == 0 ? (int?)null : poetId, catId == 0 ? (int?)null : catId, e == null ?[] : e);
if (!string.IsNullOrEmpty(pagedResult.ExceptionString))
return BadRequest(pagedResult.ExceptionString);