summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsand <daniel@spatof.org>2013-05-16 17:49:45 (GMT)
committer sand <daniel@spatof.org>2013-05-16 17:49:45 (GMT)
commit0ec7cce5fb1cb59b9e459d42cf813152ba02907c (patch)
tree3c0efab82b387aead27a3cf4e3eaf9c8a6f83e85
parent064d300477ab7f93c0daa6b71693bd49a688fd96 (diff)
quotes: supporto pagine per la ricerca
-rw-r--r--pinolo/plugins/quotes2.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/pinolo/plugins/quotes2.py b/pinolo/plugins/quotes2.py
index d46551b..fe252ac 100644
--- a/pinolo/plugins/quotes2.py
+++ b/pinolo/plugins/quotes2.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import os
+import re
import logging
import unicodedata
from datetime import datetime
@@ -24,6 +25,9 @@ stem_lang = "italian"
my_analyzer = RegexTokenizer() | LowercaseFilter() | StopFilter(stoplist=stoplist) | CharsetFilter(accent_map) | PyStemmerFilter(stem_lang)
+r_search_page = re.compile(r"--(?P<page>\d+)\s+")
+
+
class Quote(Base):
__tablename__ = 'quotes'
@@ -116,27 +120,28 @@ class QuotesPlugin(Plugin):
event.reply(u"Eh sì, stocazzo")
return
+ match = r_search_page.match(event.text)
+ if match:
+ page = int(match.group(1))
+ else:
+ page = 1
+
session = Session()
results_id = []
with self.ix.searcher() as searcher:
qp = QueryParser("quote", self.ix.schema)
query = qp.parse(event.text)
- results = searcher.search(query, limit=limit)
+ # results = searcher.search(query, limit=limit)
+ results = searcher.search_page(query, page, pagelen=limit)
found = results.scored_length()
if not found:
event.reply(u"Non ho trovato un cazzo!")
return
-
- if results.has_exact_length():
- event.reply(u"Ho trovato %d di %d risultati" % (found, len(results)))
- else:
- low = results.estimated_min_length()
- high = results.estimated_length()
- if low == high:
- event.reply(u"Ho trovato %d tra circa %d risultati" % (found, low))
- else:
- event.reply(u"Ho trovato %d tra circa %d/%d risultati" % (found, low, high))
-
+
+ event.reply(u"Risultati pagina %d di %d, risultati %d-%d di %d" % (
+ results.pagenum, results.pagecount, results.offset + 1,
+ results.offset + results.pagelen + 1, len(results)))
+
for result in results:
results_id.append(result['id'])