Skip to content

Commit

Permalink
Added Fuzzy Search options to be enabled to introduce the old search
Browse files Browse the repository at this point in the history
behavior by adding * automatically to the given words. Issue #244
  • Loading branch information
anaselli committed Jan 11, 2025
1 parent 18684ed commit d164041
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
20 changes: 10 additions & 10 deletions dnfdragora/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,18 +1117,18 @@ def _openSearchOptions(self):
self.factory.createVSpacing(vbox, 0.3)
heading.setAutoWrap()

match_all = self.parent.match_all
fuzzy_search = self.parent.fuzzy_search
newest_only = self.parent.newest_only

self.newest_only = self.factory.createCheckBox(self.factory.createLeft(vbox) , _("Show newest packages only"), newest_only )
self.newest_only.setNotify(True)
self.eventManager.addWidgetEvent(self.newest_only, self.onNewestOnly, True)
self.widget_callbacks.append( { 'widget': self.newest_only, 'handler': self.onNewestOnly} )

self.match_all = self.factory.createCheckBox(self.factory.createLeft(vbox) , _("Match all words"), match_all )
self.match_all.setNotify(True)
self.eventManager.addWidgetEvent(self.match_all, self.onMatchAll, True)
self.widget_callbacks.append( { 'widget': self.match_all, 'handler': self.onMatchAll} )
self.fuzzy_search = self.factory.createCheckBox(self.factory.createLeft(vbox) , _("Fuzzy search (legacy mode)"), fuzzy_search )
self.fuzzy_search.setNotify(True)
self.eventManager.addWidgetEvent(self.fuzzy_search, self.onMatchAll, True)
self.widget_callbacks.append( { 'widget': self.fuzzy_search, 'handler': self.onMatchAll} )

self.factory.createVStretch(vbox)
self.config_tab.showChild()
Expand Down Expand Up @@ -1252,10 +1252,10 @@ def onMatchAll(self, obj):
'''
if isinstance(obj, yui.YCheckBox):
try:
self.parent.config.userPreferences['settings']['search']['match_all'] = obj.isChecked()
self.parent.config.userPreferences['settings']['search']['fuzzy_search'] = obj.isChecked()
except:
self.parent.config.userPreferences['settings']['search'] = { 'match_all' : obj.isChecked() }
self.parent.match_all = obj.isChecked()
self.parent.config.userPreferences['settings']['search'] = { 'fuzzy_search' : obj.isChecked() }
self.parent.fuzzy_search = obj.isChecked()
else:
logger.error("Invalid object passed %s", obj.widgetClass())

Expand Down Expand Up @@ -1357,10 +1357,10 @@ def onRestoreButton(self) :
self._openLayoutOptions()
elif k == "search":
self.parent.config.userPreferences['settings']['search'] = {
'match_all': True,
'fuzzy_search': False,
'newest_only': False,
}
self.parent.match_all = True
self.parent.fuzzy_search = False
self.parent.newest_only = False
self._openSearchOptions()
elif k == "logging":
Expand Down
2 changes: 1 addition & 1 deletion dnfdragora/helpinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self):
_('<b>NOTE</b> that the above options require dnfdragora to be restarted.') + \
_('<h2>Search options</h2>') + \
_('<ul><li><b>Show newest packages only</b>: if checked dnfdragora shows only newest packages on search. <i>Note that is valid if searches are not performed by using regular expressions</i></li>') + \
_('<li><b>Match all words</b>: if checked a search without using regular expressions will match all the given words into the text field.</li></ul>') + \
_('<li><b>Fuzzy search (legacy mode)</b>: if checked a search without using regular expressions will add "*" to the given words, restoring the behavior dnfdragora had usnig dnffdaemon 4.</li></ul>') + \
_('<h2>Logging options</h2>') + \
_('Enable these options to let dnfdragora log on file called <i>dnfdragora.log</i>.') + \
_('<ul><li><b>Change directory</b>: this option allows to set logging directory, directory must exist and needs write permission.</li>') + \
Expand Down
17 changes: 9 additions & 8 deletions dnfdragora/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, options={}):
self.group_icon_path = None
self.images_path = '/usr/share/dnfdragora/images/'
self.always_yes = False
self.match_all = False
self.fuzzy_search = False
self.newest_only = False
self.all_updates_filter = False
self.log_enabled = False
Expand Down Expand Up @@ -320,8 +320,8 @@ def _configFileRead(self) :
search = {}
if 'search' in settings.keys():
search = settings['search']
if 'match_all' in search.keys():
self.match_all = search['match_all']
if 'fuzzy_search' in search.keys():
self.fuzzy_search = search['fuzzy_search']
if 'newest_only' in search.keys():
self.newest_only = search['newest_only']

Expand Down Expand Up @@ -360,8 +360,8 @@ def _configFileRead(self) :
search = user_settings['search']
if 'newest_only' in search.keys():
self.newest_only = search['newest_only']
if 'match_all' in search.keys():
self.match_all = search['match_all']
if 'fuzzy_search' in search.keys():
self.fuzzy_search = search['fuzzy_search']
#### Logging
if 'log' in user_settings.keys():
log = user_settings['log']
Expand Down Expand Up @@ -1334,10 +1334,11 @@ def _searchPackages(self) :
# fixing attribute names
if field == 'name' :
field = 'fullname'

self.backend.search(filter, field, search_string)
else:
strings = re.split('[ ,|:;]',search_string)
strings = [s for s in re.split('[ ,|:;]',search_string) if s]
if self.fuzzy_search:
strings = [s.join(["*","*"]) for s in strings]

options = {
"scope": filter,
Expand Down Expand Up @@ -1486,7 +1487,7 @@ def saveUserPreference(self):
}

search = {
'match_all': self.match_all,
'fuzzy_search': self.fuzzy_search,
'newest_only': self.newest_only
}

Expand Down

0 comments on commit d164041

Please sign in to comment.