#445 tajik search

This commit is contained in:
Hamid Reza Mohammadi 2024-08-25 12:23:36 +03:30
parent 99a53cbd96
commit eac9820eed
3 changed files with 69 additions and 26 deletions

View File

@ -22,21 +22,9 @@
@if (Model.Poems == null)
{
<div class="poem">
<h2>شعری با مشخصات مورد نظر شما پیدا نشد.</h2>
<h2>Ёфт менашавад ҷустаем мо</h2>
<p>
<strong>توصیه‌هایی برای دستیابی به نتیجهٔ مطلوبتر در جستجو:</strong>
</p>
<p>
الف) <strong>به جای جستجوی متن کامل یک بیت بهتر است حروف کلیدی آن را وارد کنید.</strong> از آنجا که اشعار به صورتهای مختلف در نسخه‌های متفاوت نقل شده‌اند ممکن است چیزی که شما در ذهن دارید با چیزی که در پایگاه ما ثبت شده متفاوت باشد. به عنوان نمونه مصرع «کشتی شکستگانیم ای باد شرطه برخیز» از حافظ در بعضی از نسخه‌ها به صورت «کشتی نشستگانیم ای باد شرطه برخیز» ضبط شده و شما با تایپ صورت صورت دوم آن را در گنجور نخواهید یافت. بهتر است برای یافتن این شعر کلماتی مانند کشتی و شرطه را جستجو کنیم.
</p>
<p>
ب) کلماتی را که ممکن است به صورت جدا یا سر هم نوشته شوند در گام اول به صورت جدا امتحان کنید (<strong>می شود</strong> و نه <del>میشود</del> یا <del>می‌شود</del>).
</p>
<p>
ج) در صورتی که نام سخنور را می‌دانید بهتر است از طریق لیست بازشوی جلوی جعبهٔ جستجو نام او را انتخاب کنید. این توصیه برای زمانی مناسب است که جستجوی عبارت مورد نظر شما باعث می‌شود آثار سخنورانی که مورد نظر شما نیستند در صدر نتایج قرار گیرد و به این وسیله شما می‌خواهید به فهرست محدودتری از نتایج دست پیدا کنید.
</p>
<p>
د) در صورتی که با فنون اولیهٔ جستجو آشنا نیستید یا <strong>معمولاً جستجوهایتان به نتیجهٔ مطلوب نمی‌رسد</strong> بد نیست نگاهی به <a href="http://hrmoh.ir/1385/04/18/howto-search-better/" title="توصیه هایی برای جستجوی بهتر در اینترنت">این نوشته</a> بیندازید.
Шеърии шомили ин иборат ёфт нашуд .
</p>
</div>
}
@ -65,7 +53,7 @@
<div class="spacer">&nbsp;</div>
@Html.Raw(Model.PagingToolsHtml)
}
else

View File

@ -6,10 +6,9 @@ using Newtonsoft.Json;
using RMuseum.Models.Ganjoor.ViewModels;
using RMuseum.Models.Ganjoor;
using System.Net;
using DNTPersianUtils.Core;
using System.Drawing;
using RSecurityBackend.Models.Generic;
using System.Text.RegularExpressions;
using RSecurityBackend.Models.Generic;
namespace TajikGanjoor.Pages
@ -18,8 +17,6 @@ namespace TajikGanjoor.Pages
{
public bool IsHomePage { get; set; }
public bool IsSearchPage { get; set; }
public string Query { get; set; }
public List<GanjoorPoetViewModel>? Poets { get; set; }
public bool IsPoetPage { get; set; }
public bool IsCatPage { get; set; }
@ -30,6 +27,9 @@ namespace TajikGanjoor.Pages
public string PreviousUrl { get; set; }
public string PreviousTitle { get; set; }
public string BreadCrumpUrls { get; set; }
public string Query { get; set; }
public PaginationMetadata PaginationMetadata { get; set; }
public string PagingToolsHtml { get; set; }
public List<GanjoorPoemCompleteViewModel> Poems { get; set; }
public async Task<IActionResult> OnGetAsync()
@ -46,10 +46,11 @@ namespace TajikGanjoor.Pages
}
IsSearchPage = !string.IsNullOrEmpty(Request.Query["s"]);
IsHomePage = !IsSearchPage && Request.Path == "/";
if(IsSearchPage)
int pageNumber = 1;
if (IsSearchPage)
{
Query = Request.Query["s"].ToString().Trim();
int pageNumber = 1;
if (!string.IsNullOrEmpty(Request.Query["page"]))
{
pageNumber = int.Parse(Request.Query["page"]);
@ -139,7 +140,20 @@ namespace TajikGanjoor.Pages
}
string paginationMetadataJsonValue = searchQueryResponse.Headers.GetValues("paging-headers").FirstOrDefault();
if (!string.IsNullOrEmpty(paginationMetadataJsonValue))
{
PaginationMetadata = JsonConvert.DeserializeObject<PaginationMetadata>(paginationMetadataJsonValue);
string catQuery = "";
if (!string.IsNullOrEmpty(Request.Query["cat"]))
{
catQuery = $"&cat={Request.Query["cat"]}";
}
PagingToolsHtml = GeneratePagingBarHtml(PaginationMetadata, $"/?s={WebUtility.UrlEncode(Query)}");
}
}
}
@ -193,6 +207,10 @@ namespace TajikGanjoor.Pages
if (IsSearchPage)
{
ViewData["Title"] = $"Ганҷур - ҷустуҷӯ - {Query}";
if(pageNumber > 1)
{
ViewData["Title"] += "Сафҳа ӣ " + pageNumber.ToString();
}
}
else
if (IsHomePage)
@ -347,7 +365,44 @@ namespace TajikGanjoor.Pages
}
}
public string? LastError { get; set; }
private string GeneratePagingBarHtml(PaginationMetadata paginationMetadata, string routeStartWithQueryStrings)
{
string htmlText = $"<div>{Environment.NewLine}";
if (paginationMetadata != null && paginationMetadata.totalPages > 1)
{
if (paginationMetadata.currentPage > 3)
{
htmlText += $"<a href=\"{routeStartWithQueryStrings.Replace("\"", "%22")}&amp;page=1\"><div class=\"circled-number\">۱</div></a>{Environment.NewLine} …";
}
for (int i = paginationMetadata.currentPage - 2; i <= (paginationMetadata.currentPage + 2); i++)
{
if (i >= 1 && i <= paginationMetadata.totalPages)
{
if (i == paginationMetadata.currentPage)
{
htmlText += $"<div class=\"circled-number-diff\">{i}</div>";
}
else
{
htmlText += $"<a href=\"{routeStartWithQueryStrings.Replace("\"", "%22")}&amp;page={i}\"><div class=\"circled-number\">{i}</div></a>{Environment.NewLine}";
}
}
}
if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2))
{
htmlText += $"… <a href=\"{routeStartWithQueryStrings.Replace("\"", "%22")}&amp;page={paginationMetadata.totalPages}\"><div class=\"circled-number\">{paginationMetadata.totalPages}</div></a>{Environment.NewLine}";
}
}
htmlText += $"</div>{Environment.NewLine}";
return htmlText;
}
public string? LastError { get; set; }
public bool AggressiveCacheEnabled
{

View File

@ -7,11 +7,11 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;8602;8618;8601;8604;8625</NoWarn>
<NoWarn>1701;1702;8602;8618;8601;8604;8625;8600</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;8602;8618;8601;8604;8625</NoWarn>
<NoWarn>1701;1702;8602;8618;8601;8604;8625;8600</NoWarn>
</PropertyGroup>
<ItemGroup>