|
a/src/python/samples/recollqsd.py |
|
b/src/python/samples/recollqsd.py |
1 |
#!/usr/bin/env python
|
1 |
#!/usr/bin/env python
|
2 |
"""Example for using the ''searchdata''' structured query interface.
|
2 |
"""Example for using the ''searchdata''' structured query interface.
|
3 |
Not good for anything except showing/trying the code."""
|
3 |
Not good for anything except showing/trying the code."""
|
4 |
|
4 |
|
5 |
import sys
|
5 |
import sys
|
6 |
import recoll
|
6 |
from recoll import recoll
|
7 |
|
7 |
|
8 |
def dotest(db, q):
|
8 |
def dotest(db, q):
|
9 |
query = db.query()
|
9 |
query = db.query()
|
10 |
query.sortby("title", 1)
|
10 |
query.sortby("title", 1)
|
11 |
|
11 |
|
12 |
nres = query.executesd(q)
|
12 |
nres = query.executesd(q)
|
13 |
print "Result count: ", nres
|
13 |
print "Result count: ", nres
|
|
|
14 |
print "Query: ", query.getxquery().encode('utf-8')
|
|
|
15 |
sys.exit(0)
|
14 |
if nres > 10:
|
16 |
if nres > 10:
|
15 |
nres = 10
|
17 |
nres = 10
|
16 |
for i in range(nres):
|
18 |
for i in range(nres):
|
17 |
doc = query.fetchone()
|
19 |
doc = query.fetchone()
|
18 |
print query.next if type(query.next) == int else query.rownumber
|
20 |
print query.next if type(query.next) == int else query.rownumber
|
19 |
for k in ("url", "mtime", "title", "author", "abstract"):
|
21 |
for k in ("url", "mtime", "title", "author", "abstract"):
|
|
|
22 |
if getattr(doc, k):
|
20 |
print k, ":", getattr(doc, k).encode('utf-8')
|
23 |
print k, ":", getattr(doc, k).encode('utf-8')
|
|
|
24 |
else:
|
|
|
25 |
print k, ": None"
|
21 |
#abs = db.makeDocAbstract(doc, query).encode('utf-8')
|
26 |
#abs = db.makeDocAbstract(doc, query).encode('utf-8')
|
22 |
#print abs
|
27 |
#print abs
|
23 |
print
|
28 |
print
|
24 |
# End dotest
|
29 |
# End dotest
|
25 |
|
30 |
|
26 |
sd = recoll.SearchData()
|
|
|
27 |
sd.addclause("and", "essaouira maroc")
|
|
|
28 |
#sd.addclause("and", "dockes", field="author")
|
31 |
#sd.addclause("and", "dockes", field="author")
|
29 |
#sd.addclause("phrase", "jean francois", 1)
|
32 |
#sd.addclause("phrase", "jean francois", 1)
|
30 |
#sd.addclause("excl", "plage")
|
33 |
#sd.addclause("excl", "plage")
|
31 |
|
34 |
|
32 |
db = recoll.connect()
|
35 |
db = recoll.connect(confdir="/home/dockes/.recoll-prod")
|
|
|
36 |
|
|
|
37 |
sd = recoll.SearchData(stemlang="english")
|
|
|
38 |
sd.addclause("and", "dockes", stemming = False, casesens = False, diacsens = True)
|
|
|
39 |
|
33 |
dotest(db, sd)
|
40 |
dotest(db, sd)
|
34 |
|
41 |
|
35 |
sys.exit(0)
|
42 |
sys.exit(0)
|