File: recollqsd.py

package info (click to toggle)
recoll 1.43.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,468 kB
  • sloc: cpp: 103,827; python: 9,498; xml: 7,218; ansic: 6,447; sh: 1,212; perl: 130; makefile: 72
file content (46 lines) | stat: -rwxr-xr-x 1,317 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
"""Example for using the ''searchdata''' structured query interface.
Not good for anything except showing/trying the code."""

import sys
from recoll import recoll


def dotest(db, q):
    query = db.query()
    query.sortby("title", 1)

    nres = query.executesd(q)
    print(f"Result count: {nres}")
    print(f"Query: {query.getxquery().encode('utf-8')}")
    if nres > 10:
        nres = 10
    for i in range(nres):
        doc = query.fetchone()
        print(query.next if type(query.next) == int else query.rownumber)
        for k in ("url", "mtime", "title", "author", "abstract"):
            if getattr(doc, k):
                print(f"{k} : {getattr(doc, k).encode('utf-8')}")
            else:
                print(f"{k} : None")
        print("")


# End dotest

# addclause(type='and'|'or'|'filename'|'phrase'|'near'|'path'|'sub'
#          qstring=string, slack=int, field=string, stemming=1|0,
#          subSearch=SearchData, exclude=0|1, anchorstart=0|1, anchorend=0|1
#          casesens=0|1, diacsens=0|1)

# sd.addclause("and", "dockes", field="author")
# sd.addclause("phrase", "jean francois", 1)

db = recoll.connect(confdir="/home/dockes/.recoll-prod")

sd = recoll.SearchData(stemlang="english")
sd.addclause("filename", "recollqsd*")

dotest(db, sd)

sys.exit(0)