search: ignore punctuation
Ignore punctuation when searching. Makes the search experience a bit nicer. Resolves #378.
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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})")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user