fix: search now ignores accents and diacritics (#274)

* compare normalized search and items to ignore accents and diacritics

* Update CHANGELOG.md

* compare normalized search and items to ignore accents and diacritics

* Update CHANGELOG.md

* fix change print enconding to base64 #104

Signed-off-by: Jan Guegel <jan@guegel.eu>

* ops.. wrong branch..

Signed-off-by: Jan Guegel <jan@guegel.eu>

* Update CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>

* use normalizeString() from commons libs

Signed-off-by: Jan Guegel <jan@guegel.eu>

* use normalizeString() from commons libs also for recentsfragmen

Signed-off-by: Jan Guegel <jan@guegel.eu>

* Apply suggestions from code review

Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>

* use normalizeString() for StorageFragment

Signed-off-by: Jan Guegel <jan@guegel.eu>

* fix last usage of contains() without normalizeString in search context
fix missing expection toast

Signed-off-by: Jan Guegel <jan@guegel.eu>

* remove Toast from loop

Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>

---------

Signed-off-by: Jan Guegel <jan@guegel.eu>
Co-authored-by: Jan Guegel <jan@guegel.eu>
Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>

Refs: https://github.com/FossifyOrg/File-Manager/issues/95
This commit is contained in:
Jan
2025-09-30 11:23:51 +02:00
committed by GitHub
parent eb4d38d25a
commit fec28af74f
5 changed files with 26 additions and 10 deletions

View File

@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Save button now overwrites files directly in the text editor ([#224])
- Search now ignores accents and diacritics ([#95])
## [1.2.3] - 2025-09-15
### Fixed
@@ -85,6 +86,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#267]: https://github.com/FossifyOrg/File-Manager/issues/267
[#250]: https://github.com/FossifyOrg/File-Manager/issues/250
[#85]: https://github.com/FossifyOrg/File-Manager/issues/85
[#95]: https://github.com/FossifyOrg/File-Manager/issues/95
[#104]: https://github.com/FossifyOrg/File-Manager/issues/104
[#224]: https://github.com/FossifyOrg/File-Manager/issues/224

View File

@@ -133,10 +133,11 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
override fun selectedPaths(paths: ArrayList<String>) {}
fun searchQueryChanged(text: String) {
val searchText = text.trim()
lastSearchedText = searchText
val normalizedText = text.normalizeString()
val searchNormalizedText = normalizedText.trim()
lastSearchedText = searchNormalizedText
when {
searchText.isEmpty() -> {
searchNormalizedText.isEmpty() -> {
binding.apply {
mimetypesFastscroller.beVisible()
getRecyclerAdapter()?.updateItems(storedItems)
@@ -145,7 +146,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
}
}
searchText.length == 1 -> {
searchNormalizedText.length == 1 -> {
binding.apply {
mimetypesFastscroller.beGone()
mimetypesPlaceholder.beVisible()
@@ -155,11 +156,13 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
else -> {
ensureBackgroundThread {
if (lastSearchedText != searchText) {
if (lastSearchedText != searchNormalizedText) {
return@ensureBackgroundThread
}
val listItems = storedItems.filter { it.name.contains(searchText, true) } as ArrayList<ListItem>
val listItems = storedItems.filter {
it.name.normalizeString().contains(searchNormalizedText, true)
} as ArrayList<ListItem>
runOnUiThread {
getRecyclerAdapter()?.updateItems(listItems, text)

View File

@@ -377,6 +377,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
return files
}
val normalizedText = text.normalizeString()
val sorting = context!!.config.getFolderSorting(path)
FileDirItem.sorting = context!!.config.getFolderSorting(currentPath)
val isSortingBySize = sorting and SORT_BY_SIZE != 0
@@ -386,7 +387,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
}
if (it.isDirectory) {
if (it.name.contains(text, true)) {
if (it.name.normalizeString().contains(normalizedText, true)) {
val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap(), false)
if (fileDirItem != null) {
files.add(fileDirItem)
@@ -395,7 +396,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
files.addAll(searchFiles(text, it.absolutePath))
} else {
if (it.name.contains(text, true)) {
if (it.name.normalizeString().contains(normalizedText, true)) {
val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap(), false)
if (fileDirItem != null) {
files.add(fileDirItem)

View File

@@ -12,6 +12,7 @@ import org.fossify.commons.extensions.getDoesFilePathExist
import org.fossify.commons.extensions.getFilenameFromPath
import org.fossify.commons.extensions.getLongValue
import org.fossify.commons.extensions.getStringValue
import org.fossify.commons.extensions.normalizeString
import org.fossify.commons.extensions.showErrorToast
import org.fossify.commons.helpers.VIEW_TYPE_GRID
import org.fossify.commons.helpers.VIEW_TYPE_LIST
@@ -242,7 +243,11 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
override fun searchQueryChanged(text: String) {
lastSearchedText = text
val filtered = filesIgnoringSearch.filter { it.mName.contains(text, true) }.toMutableList() as ArrayList<ListItem>
val normalizedText = text.normalizeString()
val filtered = filesIgnoringSearch.filter {
it.mName.normalizeString().contains(normalizedText, true)
}.toMutableList() as ArrayList<ListItem>
binding.apply {
(recentsList.adapter as? ItemsAdapter)?.updateItems(filtered, text)
recentsPlaceholder.beVisibleIf(filtered.isEmpty())

View File

@@ -28,6 +28,7 @@ import org.fossify.commons.extensions.getLongValue
import org.fossify.commons.extensions.getProperBackgroundColor
import org.fossify.commons.extensions.getProperPrimaryColor
import org.fossify.commons.extensions.getStringValue
import org.fossify.commons.extensions.normalizeString
import org.fossify.commons.extensions.queryCursor
import org.fossify.commons.extensions.showErrorToast
import org.fossify.commons.extensions.updateTextColors
@@ -340,6 +341,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
override fun searchQueryChanged(text: String) {
val normalizedText = text.normalizeString()
lastSearchedText = text
binding.apply {
if (text.isNotEmpty()) {
@@ -364,7 +366,10 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
} else {
showProgressBar()
ensureBackgroundThread {
val filtered = allDeviceListItems.filter { it.mName.contains(text, true) }.toMutableList() as ArrayList<ListItem>
val filtered = allDeviceListItems.filter {
it.mName.normalizeString().contains(normalizedText, true)
}.toMutableList() as ArrayList<ListItem>
if (lastSearchedText != text) {
return@ensureBackgroundThread
}