diff --git a/client/components/cards/EpisodeSearchCard.vue b/client/components/cards/EpisodeSearchCard.vue new file mode 100644 index 00000000..e69de29b diff --git a/client/components/cards/ItemSearchCard.vue b/client/components/cards/ItemSearchCard.vue index 139a3158..f29888e5 100644 --- a/client/components/cards/ItemSearchCard.vue +++ b/client/components/cards/ItemSearchCard.vue @@ -10,7 +10,7 @@

by {{ authorName }}

-

+
@@ -67,6 +67,7 @@ export default { // but with removing commas periods etc this is no longer plausible const html = this.matchText + if (this.matchKey === 'episode') return `

Episode: ${html}

` if (this.matchKey === 'tags') return `

Tags: ${html}

` if (this.matchKey === 'authors') return `by ${html}` if (this.matchKey === 'isbn') return `

ISBN: ${html}

` diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index b99e534b..28b61099 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -572,16 +572,16 @@ class LibraryController { if (!req.query.q) { return res.status(400).send('No query string') } - var libraryItems = req.libraryItems - var maxResults = req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 12 + const libraryItems = req.libraryItems + const maxResults = req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 12 - var itemMatches = [] - var authorMatches = {} - var seriesMatches = {} - var tagMatches = {} + const itemMatches = [] + const authorMatches = {} + const seriesMatches = {} + const tagMatches = {} libraryItems.forEach((li) => { - var queryResult = li.searchQuery(req.query.q) + const queryResult = li.searchQuery(req.query.q) if (queryResult.matchKey) { itemMatches.push({ libraryItem: li.toJSONExpanded(), @@ -592,7 +592,7 @@ class LibraryController { if (queryResult.series && queryResult.series.length) { queryResult.series.forEach((se) => { if (!seriesMatches[se.id]) { - var _series = this.db.series.find(_se => _se.id === se.id) + const _series = this.db.series.find(_se => _se.id === se.id) if (_series) seriesMatches[se.id] = { series: _series.toJSON(), books: [li.toJSON()] } } else { seriesMatches[se.id].books.push(li.toJSON()) @@ -602,7 +602,7 @@ class LibraryController { if (queryResult.authors && queryResult.authors.length) { queryResult.authors.forEach((au) => { if (!authorMatches[au.id]) { - var _author = this.db.authors.find(_au => _au.id === au.id) + const _author = this.db.authors.find(_au => _au.id === au.id) if (_author) { authorMatches[au.id] = _author.toJSON() authorMatches[au.id].numBooks = 1 @@ -622,8 +622,8 @@ class LibraryController { }) } }) - var itemKey = req.library.mediaType - var results = { + const itemKey = req.library.mediaType + const results = { [itemKey]: itemMatches.slice(0, maxResults), tags: Object.values(tagMatches).slice(0, maxResults), authors: Object.values(authorMatches).slice(0, maxResults), diff --git a/server/objects/entities/PodcastEpisode.js b/server/objects/entities/PodcastEpisode.js index b6363189..892a18e8 100644 --- a/server/objects/entities/PodcastEpisode.js +++ b/server/objects/entities/PodcastEpisode.js @@ -1,5 +1,5 @@ const Path = require('path') -const { getId } = require('../../utils/index') +const { getId, cleanStringForSearch } = require('../../utils/index') const AudioFile = require('../files/AudioFile') const AudioTrack = require('../files/AudioTrack') @@ -160,5 +160,9 @@ class PodcastEpisode { if (!this.enclosure || !this.enclosure.url) return false return this.enclosure.url == url } + + searchQuery(query) { + return cleanStringForSearch(this.title).includes(query) + } } module.exports = PodcastEpisode \ No newline at end of file diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index bcad931d..0fac4270 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -311,14 +311,14 @@ class Book { } searchQuery(query) { - var payload = { + const payload = { tags: this.tags.filter(t => cleanStringForSearch(t).includes(query)), series: this.metadata.searchSeries(query), authors: this.metadata.searchAuthors(query), matchKey: null, matchText: null } - var metadataMatch = this.metadata.searchQuery(query) + const metadataMatch = this.metadata.searchQuery(query) if (metadataMatch) { payload.matchKey = metadataMatch.matchKey payload.matchText = metadataMatch.matchText diff --git a/server/objects/mediaTypes/Podcast.js b/server/objects/mediaTypes/Podcast.js index d0f1da94..5f05fed9 100644 --- a/server/objects/mediaTypes/Podcast.js +++ b/server/objects/mediaTypes/Podcast.js @@ -1,7 +1,7 @@ const Logger = require('../../Logger') const PodcastEpisode = require('../entities/PodcastEpisode') const PodcastMetadata = require('../metadata/PodcastMetadata') -const { areEquivalent, copyValue } = require('../../utils/index') +const { areEquivalent, copyValue, cleanStringForSearch } = require('../../utils/index') const abmetadataGenerator = require('../../utils/abmetadataGenerator') const { readTextFile } = require('../../utils/fileUtils') const { createNewSortInstance } = require('../../libs/fastSort') @@ -206,9 +206,29 @@ class Podcast { return false } + searchEpisodes(query) { + return this.episodes.filter(ep => ep.searchQuery(query)) + } + searchQuery(query) { - var payload = this.metadata.searchQuery(query) - return payload || {} + const payload = { + tags: this.tags.filter(t => cleanStringForSearch(t).includes(query)), + matchKey: null, + matchText: null + } + const metadataMatch = this.metadata.searchQuery(query) + if (metadataMatch) { + payload.matchKey = metadataMatch.matchKey + payload.matchText = metadataMatch.matchText + } else { + const matchingEpisodes = this.searchEpisodes(query) + if (matchingEpisodes.length) { + payload.matchKey = 'episode' + payload.matchText = matchingEpisodes[0].title + } + } + + return payload } checkHasEpisode(episodeId) { diff --git a/server/objects/metadata/BookMetadata.js b/server/objects/metadata/BookMetadata.js index dc3f1558..17eaff52 100644 --- a/server/objects/metadata/BookMetadata.js +++ b/server/objects/metadata/BookMetadata.js @@ -377,8 +377,8 @@ class BookMetadata { return this.authors.filter(au => cleanStringForSearch(au.name).includes(query)) } searchQuery(query) { // Returns key if match is found - var keysToCheck = ['title', 'asin', 'isbn'] - for (var key of keysToCheck) { + const keysToCheck = ['title', 'asin', 'isbn'] + for (const key of keysToCheck) { if (this[key] && cleanStringForSearch(String(this[key])).includes(query)) { return { matchKey: key,