Update:Global library search strips periods, commas and other characters when matching #750

This commit is contained in:
advplyr 2022-06-26 15:46:16 -05:00
parent 256a9322ef
commit 5b4d3f71f9
8 changed files with 20 additions and 26 deletions

View File

@ -62,21 +62,10 @@ export default {
matchHtml() { matchHtml() {
if (!this.matchText || !this.search) return '' if (!this.matchText || !this.search) return ''
if (this.matchKey === 'subtitle') return '' if (this.matchKey === 'subtitle') return ''
var matchSplit = this.matchText.toLowerCase().split(this.search.toLowerCase().trim())
if (matchSplit.length < 2) return ''
var html = '' // This used to highlight the part of the search found
var totalLenSoFar = 0 // but with removing commas periods etc this is no longer plausible
for (let i = 0; i < matchSplit.length - 1; i++) { const html = this.matchText
var indexOf = matchSplit[i].length
var firstPart = this.matchText.substr(totalLenSoFar, indexOf)
var actualWasThere = this.matchText.substr(totalLenSoFar + indexOf, this.search.length)
totalLenSoFar += indexOf + this.search.length
html += `${firstPart}<strong class="text-warning">${actualWasThere}</strong>`
}
var lastPart = this.matchText.substr(totalLenSoFar)
html += lastPart
if (this.matchKey === 'tags') return `<p class="truncate">Tags: ${html}</p>` if (this.matchKey === 'tags') return `<p class="truncate">Tags: ${html}</p>`
if (this.matchKey === 'authors') return `by ${html}` if (this.matchKey === 'authors') return `by ${html}`

View File

@ -204,7 +204,6 @@ Vue.prototype.$copyToClipboard = (str, ctx) => {
}) })
} }
function xmlToJson(xml) { function xmlToJson(xml) {
const json = {}; const json = {};
for (const res of xml.matchAll(/(?:<(\w*)(?:\s[^>]*)*>)((?:(?!<\1).)*)(?:<\/\1>)|<(\w*)(?:\s*)*\/>/gm)) { for (const res of xml.matchAll(/(?:<(\w*)(?:\s[^>]*)*>)((?:(?!<\1).)*)(?:<\/\1>)|<(\w*)(?:\s*)*\/>/gm)) {

View File

@ -7,7 +7,7 @@ const LibraryFile = require('./files/LibraryFile')
const Book = require('./mediaTypes/Book') const Book = require('./mediaTypes/Book')
const Podcast = require('./mediaTypes/Podcast') const Podcast = require('./mediaTypes/Podcast')
const Video = require('./mediaTypes/Video') const Video = require('./mediaTypes/Video')
const { areEquivalent, copyValue, getId } = require('../utils/index') const { areEquivalent, copyValue, getId, cleanStringForSearch } = require('../utils/index')
class LibraryItem { class LibraryItem {
constructor(libraryItem = null) { constructor(libraryItem = null) {
@ -451,7 +451,7 @@ class LibraryItem {
} }
searchQuery(query) { searchQuery(query) {
query = query.toLowerCase() query = cleanStringForSearch(query)
return this.media.searchQuery(query) return this.media.searchQuery(query)
} }

View File

@ -1,7 +1,7 @@
const Path = require('path') const Path = require('path')
const Logger = require('../../Logger') const Logger = require('../../Logger')
const BookMetadata = require('../metadata/BookMetadata') const BookMetadata = require('../metadata/BookMetadata')
const { areEquivalent, copyValue } = require('../../utils/index') const { areEquivalent, copyValue, cleanStringForSearch } = require('../../utils/index')
const { parseOpfMetadataXML } = require('../../utils/parsers/parseOpfMetadata') const { parseOpfMetadataXML } = require('../../utils/parsers/parseOpfMetadata')
const { overdriveMediaMarkersExist, parseOverdriveMediaMarkersAsChapters } = require('../../utils/parsers/parseOverdriveMediaMarkers') const { overdriveMediaMarkersExist, parseOverdriveMediaMarkersAsChapters } = require('../../utils/parsers/parseOverdriveMediaMarkers')
const abmetadataGenerator = require('../../utils/abmetadataGenerator') const abmetadataGenerator = require('../../utils/abmetadataGenerator')
@ -304,7 +304,7 @@ class Book {
searchQuery(query) { searchQuery(query) {
var payload = { var payload = {
tags: this.tags.filter(t => t.toLowerCase().includes(query)), tags: this.tags.filter(t => cleanStringForSearch(t).includes(query)),
series: this.metadata.searchSeries(query), series: this.metadata.searchSeries(query),
authors: this.metadata.searchAuthors(query), authors: this.metadata.searchAuthors(query),
matchKey: null, matchKey: null,

View File

@ -1,5 +1,5 @@
const Logger = require('../../Logger') const Logger = require('../../Logger')
const { areEquivalent, copyValue } = require('../../utils/index') const { areEquivalent, copyValue, cleanStringForSearch } = require('../../utils/index')
const parseNameString = require('../../utils/parsers/parseNameString') const parseNameString = require('../../utils/parsers/parseNameString')
class BookMetadata { class BookMetadata {
constructor(metadata) { constructor(metadata) {
@ -342,15 +342,15 @@ class BookMetadata {
} }
searchSeries(query) { searchSeries(query) {
return this.series.filter(se => se.name.toLowerCase().includes(query)) return this.series.filter(se => cleanStringForSearch(se.name).includes(query))
} }
searchAuthors(query) { searchAuthors(query) {
return this.authors.filter(se => se.name.toLowerCase().includes(query)) return this.authors.filter(au => cleanStringForSearch(au.name).includes(query))
} }
searchQuery(query) { // Returns key if match is found searchQuery(query) { // Returns key if match is found
var keysToCheck = ['title', 'asin', 'isbn'] var keysToCheck = ['title', 'asin', 'isbn']
for (var key of keysToCheck) { for (var key of keysToCheck) {
if (this[key] && this[key].toLowerCase().includes(query)) { if (this[key] && cleanStringForSearch(String(this[key])).includes(query)) {
return { return {
matchKey: key, matchKey: key,
matchText: this[key] matchText: this[key]

View File

@ -1,5 +1,5 @@
const Logger = require('../../Logger') const Logger = require('../../Logger')
const { areEquivalent, copyValue } = require('../../utils/index') const { areEquivalent, copyValue, cleanStringForSearch } = require('../../utils/index')
class PodcastMetadata { class PodcastMetadata {
constructor(metadata) { constructor(metadata) {
@ -94,7 +94,7 @@ class PodcastMetadata {
searchQuery(query) { // Returns key if match is found searchQuery(query) { // Returns key if match is found
var keysToCheck = ['title', 'author', 'itunesId', 'itunesArtistId'] var keysToCheck = ['title', 'author', 'itunesId', 'itunesArtistId']
for (var key of keysToCheck) { for (var key of keysToCheck) {
if (this[key] && String(this[key]).toLowerCase().includes(query)) { if (this[key] && cleanStringForSearch(String(this[key])).includes(query)) {
return { return {
matchKey: key, matchKey: key,
matchText: this[key] matchText: this[key]

View File

@ -130,3 +130,9 @@ module.exports.toNumber = (val, fallback = 0) => {
if (isNaN(val) || val === null) return fallback if (isNaN(val) || val === null) return fallback
return Number(val) return Number(val)
} }
module.exports.cleanStringForSearch = (str) => {
if (!str) return ''
// Remove ' . ` " ,
return str.toLowerCase().replace(/[\'\.\`\",]/g, '').trim()
}