Switch to unified view

a/src/python/samples/recollq.py b/src/python/samples/recollq.py
1
#!/usr/bin/env python
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
2
"""A python version of the command line query tool recollq (a bit simplified)
3
"""A python version of the command line query tool recollq (a bit simplified)
3
The input string is always interpreted as a query language string.
4
The input string is always interpreted as a query language string.
4
This could actually be useful for something after some customization
5
This could actually be useful for something after some customization
5
"""
6
"""
6
7
7
import sys
8
import sys
9
import locale
8
from getopt import getopt
10
from getopt import getopt
9
11
10
try:
12
try:
11
    from recoll import recoll
13
    from recoll import recoll
12
    from recoll import rclextract
14
    from recoll import rclextract
...
...
91
########################################### MAIN
93
########################################### MAIN
92
94
93
if len(sys.argv) < 2:
95
if len(sys.argv) < 2:
94
    Usage()
96
    Usage()
95
97
98
language, localecharset = locale.getdefaultlocale()
96
confdir=""
99
confdir=""
97
extra_dbs = []
100
extra_dbs = []
98
# Snippet params
101
# Snippet params
99
maxchars = 120
102
maxchars = 120
100
contextwords = 4
103
contextwords = 4
...
...
111
114
112
# The query should be in the remaining arg(s)
115
# The query should be in the remaining arg(s)
113
if len(args) == 0:
116
if len(args) == 0:
114
    print >> sys.stderr, "No query found in command line"
117
    print >> sys.stderr, "No query found in command line"
115
    Usage()
118
    Usage()
116
q = ""
119
q = u''
117
for word in args:
120
for word in args:
118
    q += word + " "
121
    q += word.decode(localecharset) + u' '
119
122
120
print "QUERY: [", q, "]"
123
print "QUERY: [", q, "]"
121
db = recoll.connect(confdir=confdir, 
124
db = recoll.connect(confdir=confdir, 
122
                    extra_dbs=extra_dbs)
125
                    extra_dbs=extra_dbs)
123
db.setAbstractParams(maxchars=maxchars, contextwords=contextwords)
126
db.setAbstractParams(maxchars=maxchars, contextwords=contextwords)