r6857 - in bigboard/trunk/bigboard/stocks: apps search
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r6857 - in bigboard/trunk/bigboard/stocks: apps search
- Date: Thu, 1 Nov 2007 13:06:16 -0500 (CDT)
Author: hp
Date: 2007-11-01 13:06:16 -0500 (Thu, 01 Nov 2007)
New Revision: 6857
Modified:
bigboard/trunk/bigboard/stocks/apps/apps.py
bigboard/trunk/bigboard/stocks/search/SearchStock.py
Log:
improve app search to rank by matches and then by usage, and to match on the name of the executable; show 4 search results for each type of search instead of 3
Modified: bigboard/trunk/bigboard/stocks/apps/apps.py
===================================================================
--- bigboard/trunk/bigboard/stocks/apps/apps.py 2007-10-31 22:35:32 UTC (rev 6856)
+++ bigboard/trunk/bigboard/stocks/apps/apps.py 2007-11-01 18:06:16 UTC (rev 6857)
@@ -58,6 +58,9 @@
def get_desktop(self):
return self.__desktop_entry
+ def get_exec_format_string(self):
+ return self.__desktop_entry and self.__desktop_entry.get_string("Exec") or None
+
def get_pinned(self):
return self.__pinned
@@ -610,24 +613,41 @@
def search_local_fast_sync(self, search_terms):
ws_re = re.compile('\s+')
- searched_attrs = ['name',]
+
def get_searchable_values(app):
- return map(string.lower, (app.get_name(), app.get_generic_name()))
+ ## these should be in order of "relevance" i.e. we give a higher result score
+ ## for matching earlier searchable values
+ return map(string.lower, (app.get_name(), app.get_generic_name(), app.get_exec_format_string()))
def app_matches(app):
+ match_rank = 0
for term in ws_re.split(search_terms):
term = term.lower()
- for attr in get_searchable_values(appvalue):
+ searchable_values = get_searchable_values(appvalue)
+ for i, attr in enumerate(searchable_values):
+ if not attr:
+ continue
for word in ws_re.split(attr):
if word.startswith(term):
- matched = True
- return True
- return False
+ match_rank = match_rank + (len(searchable_values) - i)
+ return match_rank
+
+ results = []
for appvalue in self.__all_apps:
if not appvalue.is_installed():
continue
- if app_matches(appvalue):
- yield appvalue
+ rank = app_matches(appvalue)
+ if rank > 0:
+ results.append( (rank, appvalue.get_usage_count(), appvalue) )
+ ## sort descending by rank then usage count
+ results.sort(lambda a, b: a[0] == b[0] and \
+ cmp(b[1], a[1]) or \
+ cmp(b[0], a[0]))
+
+ _logger.debug("search results %s" % (str(results)))
+
+ return map(lambda r: r[2], results)
+
__apps_repo = None
def get_apps_repo():
global __apps_repo
Modified: bigboard/trunk/bigboard/stocks/search/SearchStock.py
===================================================================
--- bigboard/trunk/bigboard/stocks/search/SearchStock.py 2007-10-31 22:35:32 UTC (rev 6856)
+++ bigboard/trunk/bigboard/stocks/search/SearchStock.py 2007-11-01 18:06:16 UTC (rev 6857)
@@ -48,7 +48,7 @@
class ResultsView(search.SearchConsumer):
- RESULT_TYPE_MAX = 3
+ RESULT_TYPE_MAX = 4
def __init__(self, *args, **kwargs):
super(ResultsView, self).__init__(*args, **kwargs)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]