summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-12-31 16:21:43 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-12-31 16:21:43 +0100
commitee087e9937a336f67ecb7d7b06ceaddf11a87d06 (patch)
tree008e683e282791d797dafdea93d6066409bed5f2 /modules
parentfad55f6c208aad8f1699d9b6b7feca3889fb6f6d (diff)
anidb: Implemented weighted search.
Diffstat (limited to 'modules')
-rw-r--r--modules/anidb.py15
1 files 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: