search: ignore punctuation

Ignore punctuation when searching.

Makes the search experience a bit nicer.

Resolves #378.
This commit is contained in:
Alexander Capehart 2023-03-19 13:22:07 -06:00
parent 245896e4a7
commit 8ea637ff05
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 17 additions and 11 deletions

View file

@ -7,12 +7,13 @@
#### What's Improved
- Accept `REPLAYGAIN_*` adjustment information on OPUS files alongside
`R128_*` adjustments.
`R128_*` adjustments
- List updates are now consistent across the app
- Fixed jarring header update in detail view
- Search view now trims search queries
- Audio effect (equalizer) session is now broadcast when playing/pausing
rather than on start/stop.
rather than on start/stop
- Searching now ignores punctuation
#### What's Fixed
- Fixed MP4-AAC files not playing due to an accidental audio extractor

View file

@ -159,11 +159,14 @@ private constructor(private val rawSong: RawSong, private val future: Future<Tra
textFrames["TCON"]?.let { rawSong.genreNames = it }
// Compilation Flag
(textFrames["TCMP"] ?: textFrames["TXXX:compilation"] ?: textFrames["TXXX:itunescompilation"])?.let {
if (it.size != 1 || it[0] != "1") return@let
rawSong.albumArtistNames = rawSong.albumArtistNames.ifEmpty { COMPILATION_ALBUM_ARTISTS }
rawSong.releaseTypes = rawSong.releaseTypes.ifEmpty { COMPILATION_RELEASE_TYPES }
}
(textFrames["TCMP"]
?: textFrames["TXXX:compilation"] ?: textFrames["TXXX:itunescompilation"])
?.let {
if (it.size != 1 || it[0] != "1") return@let
rawSong.albumArtistNames =
rawSong.albumArtistNames.ifEmpty { COMPILATION_ALBUM_ARTISTS }
rawSong.releaseTypes = rawSong.releaseTypes.ifEmpty { COMPILATION_RELEASE_TYPES }
}
}
/**
@ -268,7 +271,8 @@ private constructor(private val rawSong: RawSong, private val future: Future<Tra
// Compilation Flag
(comments["compilation"] ?: comments["itunescompilation"])?.let {
if (it.size != 1 || it[0] != "1") return@let
rawSong.albumArtistNames = rawSong.albumArtistNames.ifEmpty { COMPILATION_ALBUM_ARTISTS }
rawSong.albumArtistNames =
rawSong.albumArtistNames.ifEmpty { COMPILATION_ALBUM_ARTISTS }
rawSong.releaseTypes = rawSong.releaseTypes.ifEmpty { COMPILATION_RELEASE_TYPES }
}
}

View file

@ -102,7 +102,7 @@ class SearchEngineImpl @Inject constructor(@ApplicationContext private val conte
// which
// could make it match the query.
val normalizedName =
NORMALIZATION_SANITIZE_REGEX.replace(
NORMALIZE_POST_PROCESSING_REGEX.replace(
Normalizer.normalize(name, Normalizer.Form.NFKD), "")
if (normalizedName.contains(query, ignoreCase = true)) {
return@filter true
@ -115,8 +115,9 @@ class SearchEngineImpl @Inject constructor(@ApplicationContext private val conte
private companion object {
/**
* Converts the output of [Normalizer] to remove any junk characters added by it's
* replacements.
* replacements, alongside punctuation.
*/
val NORMALIZATION_SANITIZE_REGEX = Regex("\\p{InCombiningDiacriticalMarks}+")
val NORMALIZE_POST_PROCESSING_REGEX =
Regex("(\\p{InCombiningDiacriticalMarks}+)|(\\p{Punct})")
}
}