docs: #321 make exact search more accessible

This commit is contained in:
Hamid Reza Mohammadi 2022-05-19 21:16:49 +04:30
parent 610e5f056d
commit 8b65c04a51
2 changed files with 52 additions and 4 deletions

View File

@ -118,7 +118,7 @@
<input type="submit" value="بیاب" />
</form>
</div><!-- .actionbox -->
</div>
</div>
<!-- #hdr2 -->
@ -130,6 +130,22 @@
<div class="spacer">&nbsp;</div>
@if (!string.IsNullOrEmpty(Model.AlternativeSearchPhrase))
{
if (Model.Quoted)
{
<div class="poem">
<a role="button" class="pagebutton" href="/search?s=@Model.AlternativeSearchPhrase&amp;author=@Model.PoetId">@Model.AlternativeSearchPhraseDescription</a>
</div>
}
else
{
<div class="poem">
<a role="button" class="pagebutton" href="/search?s=@Model.AlternativeSearchPhrase&amp;author=@Model.PoetId">@Model.AlternativeSearchPhraseDescription</a>
</div>
}
}
@if (Model.Poems == null)
{
<div class="poem">
@ -190,8 +206,8 @@
@if (!string.IsNullOrEmpty(ViewData["GoogleAnalyticsCode"].ToString()))
{
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)

View File

@ -139,6 +139,12 @@ namespace GanjooRazor.Pages
return new OkObjectResult(poet);
}
public string AlternativeSearchPhrase { get; set; }
public string AlternativeSearchPhraseDescription { get; set; }
public bool Quoted { get; set; }
public async Task<IActionResult> OnGetAsync()
{
LoggedIn = !string.IsNullOrEmpty(Request.Cookies["Token"]);
@ -148,6 +154,32 @@ namespace GanjooRazor.Pages
Query = LanguageUtils.MakeTextSearchable(Query); //replace zwnj with space
if (quotes)
Query = $"\"{Query}\"";
Quoted = quotes && Query.Contains(" ");
AlternativeSearchPhrase = Quoted ? WebUtility.UrlEncode(Query.Replace("\"", "")) : Query.Contains(" ") ? WebUtility.UrlEncode($"\"{Query}\"") : "";
AlternativeSearchPhraseDescription = "";
if (Quoted)
{
AlternativeSearchPhraseDescription = "جستجوی ";
bool needsComma = false;
var splitteds = Query.Replace("\"", "").Split(' ');
for(int sp = 0; sp < splitteds.Length - 1; sp++)
{
var splitted = splitteds[sp];
if (needsComma)
AlternativeSearchPhraseDescription += "، ";
AlternativeSearchPhraseDescription += $"«{splitted}»";
needsComma = true;
}
AlternativeSearchPhraseDescription += $" و «{splitteds[splitteds.Length - 1]}»";
AlternativeSearchPhraseDescription += " بدون لحاظ کردن ترتیب واژگان";
}
else
if (Query.Contains(" "))
{
AlternativeSearchPhraseDescription = $"جستجوی دقیق عبارت «{Query}»";
}
PoetId = string.IsNullOrEmpty(Request.Query["author"]) ? 0 : int.Parse(Request.Query["author"]);
CatId = string.IsNullOrEmpty(Request.Query["cat"]) ? 0 : int.Parse(Request.Query["cat"]);
@ -189,7 +221,7 @@ namespace GanjooRazor.Pages
pageNumber = int.Parse(Request.Query["page"]);
}
if(pageNumber > 1)
if (pageNumber > 1)
{
ViewData["Title"] += $" - صفحهٔ {pageNumber.ToPersianNumbers()}";
}