temporary checkpoint for python module modifs

This commit is contained in:
Jean-Francois Dockes
2012-12-19 19:59:31 +01:00
parent a9599be5f9
commit 3be5e982b7
5 changed files with 695 additions and 28 deletions
+38 -6
View File
@@ -7,6 +7,7 @@ This could actually be useful for something after some customization
import sys
from getopt import getopt
import recoll
import rclextract
allmeta = ("title", "keywords", "abstract", "url", "mimetype", "mtime",
"ipath", "fbytes", "dbytes", "relevancyrating")
@@ -15,26 +16,59 @@ def Usage():
print >> sys.stderr, "Usage: recollq.py [-c conf] [-i extra_index] <recoll query>"
sys.exit(1);
class ptrmeths:
def __init__(self, groups):
self.groups = groups
def startMatch(self, idx):
ugroup = " ".join(self.groups[idx][1])
return '<span class="pyrclstart" idx="%d" ugroup="%s">' % (idx, ugroup)
def endMatch(self):
return '</span>'
def extract(doc):
extractor = rclextract.Extractor(doc)
newdoc = extractor.extract(doc.ipath)
return newdoc
def doquery(db, q):
# Get query object
query = db.query()
# Parse/run input query string
nres = query.execute(q, stemming = 1, stemlang="english")
nres = query.execute(q, stemming = 0, stemlang="english")
qs = u"Xapian query: [%s]" % query.getxquery()
print(qs.encode("utf-8"))
groups = query.getgroups()
print "Groups:", groups
m = ptrmeths(groups)
# Print results:
print "Result count: ", nres
if nres > 20:
nres = 20
while query.next >= 0 and query.next < nres:
doc = query.fetchone()
print query.next, ":",
# for k,v in doc.items().items():
# print "KEY:", k.encode('utf-8'), "VALUE", v.encode('utf-8')
# continue
for k in ("title", "mtime", "author"):
print k, ":", getattr(doc, k).encode('utf-8')
value = getattr(doc, k)
# value = doc.get(k)
if value is None:
print k, ":", "(None)"
else:
print k, ":", value.encode('utf-8')
#doc.setbinurl(bytearray("toto"))
#burl = doc.getbinurl(); print "Bin URL :", doc.getbinurl()
abs = db.makeDocAbstract(doc, query).encode('utf-8')
print abs
abs = query.makedocabstract(doc, methods=m)
print abs.encode('utf-8')
print
# fulldoc = extract(doc)
# print "FULLDOC MIMETYPE", fulldoc.mimetype, "TEXT:", fulldoc.text.encode("utf-8")
########################################### MAIN
if len(sys.argv) < 2:
Usage()
@@ -68,5 +102,3 @@ db = recoll.connect(confdir=confdir,
db.setAbstractParams(maxchars=maxchars, contextwords=contextwords)
doquery(db, q)