Fixed a bug where searching on localized name would fail to show on the search. Fixed a bug where extra spaces would cause the search results not to show properly. (#682)

This commit is contained in:
Joseph Milazzo 2021-10-17 07:08:17 -07:00 committed by GitHub
parent c0a8d092e2
commit f3ebc21b97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View File

@ -226,7 +226,7 @@ namespace API.Controllers
[HttpGet("search")]
public async Task<ActionResult<IEnumerable<SearchResultDto>>> Search(string queryString)
{
queryString = queryString.Trim().Replace(@"%", "");
queryString = Uri.UnescapeDataString(queryString).Trim().Replace(@"%", string.Empty);
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
// Get libraries user has access to

View File

@ -6,7 +6,7 @@ export interface SearchResult {
libraryName: string;
name: string;
originalName: string;
localizedName: string;
sortName: string;
coverImage: string; // byte64 encoded (not used)
format: MangaFormat;
}

View File

@ -23,6 +23,7 @@
(selected)='clickSearchResult($event)'
(inputChanged)='onChangeSearch($event)'
[isLoading]="isLoading"
[customFilter]="customFilter"
[debounceTime]="debounceTime"
[itemTemplate]="itemTemplate"
[notFoundTemplate]="notFoundTemplate">
@ -35,7 +36,7 @@
</div>
<div class="ml-1">
<app-series-format [format]="item.format"></app-series-format>
<span *ngIf="item.name.toLowerCase().indexOf(searchTerm) >= 0; else localizedName" [innerHTML]="item.name"></span>
<span *ngIf="item.name.toLowerCase().trim().indexOf(searchTerm) >= 0; else localizedName" [innerHTML]="item.name"></span>
<ng-template #localizedName>
<span [innerHTML]="item.localizedName"></span>
</ng-template>

View File

@ -3,6 +3,7 @@ import { Component, HostListener, Inject, OnDestroy, OnInit, ViewChild } from '@
import { Router } from '@angular/router';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { isTemplateSpan } from 'typescript';
import { ScrollService } from '../scroll.service';
import { SearchResult } from '../_models/search-result';
import { AccountService } from '../_services/account.service';
@ -24,6 +25,16 @@ export class NavHeaderComponent implements OnInit, OnDestroy {
imageStyles = {width: '24px', 'margin-top': '5px'};
searchResults: SearchResult[] = [];
searchTerm = '';
customFilter: (items: SearchResult[], query: string) => SearchResult[] = (items: SearchResult[], query: string) => {
const normalizedQuery = query.trim().toLowerCase();
const matches = items.filter(item => {
const normalizedSeriesName = item.name.toLowerCase().trim();
const normalizedOriginalName = item.originalName.toLowerCase().trim();
const normalizedLocalizedName = item.localizedName.toLowerCase().trim();
return normalizedSeriesName.indexOf(normalizedQuery) >= 0 || normalizedOriginalName.indexOf(normalizedQuery) >= 0 || normalizedLocalizedName.indexOf(normalizedQuery) >= 0;
});
return matches;
};
backToTopNeeded = false;