diff --git a/src/Javascript/Workers/search.js b/src/Javascript/Workers/search.js index 9bf06d1f..75e3c45f 100644 --- a/src/Javascript/Workers/search.js +++ b/src/Javascript/Workers/search.js @@ -35,7 +35,7 @@ const mapTrack = track => ({ id: track.id, album: track.tags.album, artist: track.tags.artist, - title: track.tags.title + title: track.tags.title, }) @@ -43,12 +43,37 @@ const mapTrack = track => ({ // Actions // ------- -function performSearch(searchTerm) { - let results = [] +function performSearch(rawSearchTerm) { + let results = + [] + + const searchTerm = rawSearchTerm + .replace(/\-\s+/g, "-") + .replace(/\+\s+/g, "+") + .split(/ +/) + .reduce( + ([ acc, previousOperator, previousPrefix ], chunk) => { + const operator = (a => a && a[0])( chunk.match(/^(\+|\-)/) ) + const chunkWithoutOperator = chunk.replace(/^(\+|\-)/, "") + const prefix = (a => a && a[1])( chunkWithoutOperator.match(/^([^:]+:)/) ) + const chunkWithoutPrefix = chunkWithoutOperator.replace(/^([^:]+:)/, "") + + const op = operator || previousOperator + const pr = prefix ? "" : (operator ? "" : previousPrefix) + + return chunkWithoutPrefix.trim().length > 0 + ? [ [ ...acc, op + pr + chunkWithoutOperator ], op, prefix || pr ] + : [ acc, previousOperator, previousPrefix ] + }, + [ [], "+", "" ] + )[0] + .join(" ") + + console.log(searchTerm) if (index) { results = index - .search(searchTerm.replace(" *", "")) + .search(searchTerm) .map(s => s.ref) } @@ -65,9 +90,9 @@ function updateSearchIndex(input) { : input index = lunr(function() { - this.field("album", {}); - this.field("artist", {}); - this.field("title", {}); + this.field("album"); + this.field("artist"); + this.field("title"); (tracks || []) .map(mapTrack) diff --git a/src/Static/About/About.md b/src/Static/About/About.md index 88814e15..4216e10f 100644 --- a/src/Static/About/About.md +++ b/src/Static/About/About.md @@ -53,6 +53,9 @@ Diffuse locates all the music files on the given services, extracts the metadata - MP3 - MP4/M4A - FLAC +- OGG +- WAV +- WEBM
@@ -126,19 +129,16 @@ The user interface should be self explanatory, but there are a few "hidden" feat ### Search -Searching is powered by [lunr.js](https://lunrjs.com/), which means you can use all [these wildcards](https://lunrjs.com/guides/searching.html) and other stuff to refine your search. A few examples: - -```elm -# "Parkway Drive" or "Iron Maiden". -# The non-escaped space (ie. ` `, not `\ `) indicates a new term. -Parkway\ Drive Iron\ Maiden +```shell +# Show me every track where the title, artist or album contains the term 'Parkway' and the term 'Drive'. Terms are separated by spaces (eg. "Killing with a smile" has four terms). +Parkway Drive -# Show me every track of which the artist's name starts with 'park'. +# Show me every track of which the artist's name contains 'park'. artist:park* # Show me every track from Parkway Drive's "Deep Blue" album. -artist:Parkway\ Drive + album:Deep\ Blue +artist:Parkway Drive album:Deep Blue # Show me every track from Parkway Drive but not their "Atlas" album. -artist:Parkway\ Drive - album:Atlas +artist:Parkway Drive - album:Atlas ```