From ee087e9937a336f67ecb7d7b06ceaddf11a87d06 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 31 Dec 2010 16:21:43 +0100 Subject: anidb: Implemented weighted search. --- modules/anidb.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/anidb.py b/modules/anidb.py index 83e48ea..df068a4 100644 --- a/modules/anidb.py +++ b/modules/anidb.py @@ -34,13 +34,24 @@ class Module: search = '%%%s%%' % search cur = self.db.cursor() if short: - cur.execute('select * from anidb where aid in (select distinct aid from anidb where title ~~* %s and type in (2, 3)) and type = 1', (search,)) + cur.execute('select * from anidb a where aid in (select distinct aid from anidb where title ~~* %s and type in (2, 3)) and type = 1' + 'order by (select hits from anidb_weights w where a.aid = w.aid)', (search,)) else: - cur.execute('select * from anidb where aid in (select distinct aid from anidb where title ~~* %s) and type = 1', (search,)) + cur.execute('select * from anidb a where aid in (select distinct aid from anidb where title ~~* %s) and type = 1 ' + 'order by (select hits from anidb_weights w where a.aid = w.aid)', (search,)) r = cur.fetchall() cur.close() return [(r[0][0], r[0][3])] if len(r) == 1 else [(x[0], x[3]) for x in r] + def got_hit(self, aid): + cur = self.db.cursor() + cur.execute('update anidb_weights set hits = hits + 1 where aid = %s', (aid,)) + # assume no hits yet + if cur.rowcount == 0: + cur.execute('insert into anidb_weights (aid, hits) values (%s, 1)', (aid,)) + cur.close() + self.db.commit() + def get_info(self, aid): cachepath = os.path.expanduser('~/.fotanidbcache/a%d.dat' % aid) if os.access(cachepath, os.F_OK | os.R_OK) and time.time() - os.stat(cachepath).st_mtime < 60*60*24*7: -- cgit v1.2.3