|
a/src/query/recollq.cpp |
|
b/src/query/recollq.cpp |
|
... |
|
... |
61 |
}
|
61 |
}
|
62 |
|
62 |
|
63 |
|
63 |
|
64 |
static char *thisprog;
|
64 |
static char *thisprog;
|
65 |
static char usage [] =
|
65 |
static char usage [] =
|
|
|
66 |
" -P: Show date span for documents in index\n"
|
66 |
" [-o|-a|-f] <query string>\n"
|
67 |
" [-o|-a|-f] <query string>\n"
|
67 |
" Runs a recoll query and displays result lines. \n"
|
68 |
" Runs a recoll query and displays result lines. \n"
|
68 |
" Default: will interpret the argument(s) as a xesam query string\n"
|
69 |
" Default: will interpret the argument(s) as a xesam query string\n"
|
69 |
" query may be like: \n"
|
70 |
" query may be like: \n"
|
70 |
" implicit AND, Exclusion, field spec: t1 -t2 title:t3\n"
|
71 |
" implicit AND, Exclusion, field spec: t1 -t2 title:t3\n"
|
|
... |
|
... |
108 |
#define OPT_D 0x1000
|
109 |
#define OPT_D 0x1000
|
109 |
#define OPT_S 0x2000
|
110 |
#define OPT_S 0x2000
|
110 |
#define OPT_s 0x4000
|
111 |
#define OPT_s 0x4000
|
111 |
#define OPT_A 0x8000
|
112 |
#define OPT_A 0x8000
|
112 |
#define OPT_i 0x10000
|
113 |
#define OPT_i 0x10000
|
|
|
114 |
#define OPT_P 0x20000
|
113 |
|
115 |
|
114 |
int recollq(RclConfig **cfp, int argc, char **argv)
|
116 |
int recollq(RclConfig **cfp, int argc, char **argv)
|
115 |
{
|
117 |
{
|
116 |
string a_config;
|
118 |
string a_config;
|
117 |
string sortfield;
|
119 |
string sortfield;
|
|
... |
|
... |
146 |
case 'n': op_flags |= OPT_n; if (argc < 2) Usage();
|
148 |
case 'n': op_flags |= OPT_n; if (argc < 2) Usage();
|
147 |
limit = atoi(*(++argv));
|
149 |
limit = atoi(*(++argv));
|
148 |
if (limit <= 0) limit = INT_MAX;
|
150 |
if (limit <= 0) limit = INT_MAX;
|
149 |
argc--; goto b1;
|
151 |
argc--; goto b1;
|
150 |
case 'o': op_flags |= OPT_o; break;
|
152 |
case 'o': op_flags |= OPT_o; break;
|
|
|
153 |
case 'P': op_flags |= OPT_P; break;
|
151 |
case 'q': op_flags |= OPT_q; break;
|
154 |
case 'q': op_flags |= OPT_q; break;
|
152 |
case 'S': op_flags |= OPT_S; if (argc < 2) Usage();
|
155 |
case 'S': op_flags |= OPT_S; if (argc < 2) Usage();
|
153 |
sortfield = *(++argv);
|
156 |
sortfield = *(++argv);
|
154 |
argc--; goto b1;
|
157 |
argc--; goto b1;
|
155 |
case 's': op_flags |= OPT_s; if (argc < 2) Usage();
|
158 |
case 's': op_flags |= OPT_s; if (argc < 2) Usage();
|
|
... |
|
... |
159 |
default: Usage(); break;
|
162 |
default: Usage(); break;
|
160 |
}
|
163 |
}
|
161 |
b1: argc--; argv++;
|
164 |
b1: argc--; argv++;
|
162 |
}
|
165 |
}
|
163 |
|
166 |
|
164 |
if (argc < 1) {
|
|
|
165 |
Usage();
|
|
|
166 |
}
|
|
|
167 |
string qs = *argv++;argc--;
|
|
|
168 |
while (argc > 0) {
|
|
|
169 |
qs += string(" ") + *argv++;argc--;
|
|
|
170 |
}
|
|
|
171 |
string reason;
|
167 |
string reason;
|
172 |
*cfp = recollinit(0, 0, reason, &a_config);
|
168 |
*cfp = recollinit(0, 0, reason, &a_config);
|
173 |
RclConfig *rclconfig = *cfp;
|
169 |
RclConfig *rclconfig = *cfp;
|
174 |
if (!rclconfig || !rclconfig->ok()) {
|
170 |
if (!rclconfig || !rclconfig->ok()) {
|
175 |
fprintf(stderr, "Recoll init failed: %s\n", reason.c_str());
|
171 |
fprintf(stderr, "Recoll init failed: %s\n", reason.c_str());
|
176 |
exit(1);
|
172 |
exit(1);
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
if (argc < 1 && !(op_flags & OPT_P)) {
|
|
|
176 |
Usage();
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
Rcl::Db rcldb(rclconfig);
|
|
|
180 |
if (!extra_dbs.empty()) {
|
|
|
181 |
for (list<string>::iterator it = extra_dbs.begin();
|
|
|
182 |
it != extra_dbs.end(); it++) {
|
|
|
183 |
if (!rcldb.addQueryDb(*it)) {
|
|
|
184 |
cerr << "Can't add index: " << *it << endl;
|
|
|
185 |
exit(1);
|
|
|
186 |
}
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
if (!rcldb.open(Rcl::Db::DbRO)) {
|
|
|
191 |
cerr << "Cant open database in " << rclconfig->getDbDir() <<
|
|
|
192 |
" reason: " << rcldb.getReason() << endl;
|
|
|
193 |
exit(1);
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
if (op_flags & OPT_P) {
|
|
|
197 |
int minyear, maxyear;
|
|
|
198 |
if (!rcldb.maxYearSpan(&minyear, &maxyear)) {
|
|
|
199 |
cerr << "maxYearSpan failed: " << rcldb.getReason() << endl;
|
|
|
200 |
exit(1);
|
|
|
201 |
} else {
|
|
|
202 |
cout << "Min year " << minyear << " Max year " << maxyear << endl;
|
|
|
203 |
exit(0);
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
if (argc < 1) {
|
|
|
208 |
Usage();
|
|
|
209 |
}
|
|
|
210 |
string qs = *argv++;argc--;
|
|
|
211 |
while (argc > 0) {
|
|
|
212 |
qs += string(" ") + *argv++;argc--;
|
177 |
}
|
213 |
}
|
178 |
|
214 |
|
179 |
{
|
215 |
{
|
180 |
string uq;
|
216 |
string uq;
|
181 |
string charset = rclconfig->getDefCharset(true);
|
217 |
string charset = rclconfig->getDefCharset(true);
|
|
... |
|
... |
186 |
} else if (ercnt) {
|
222 |
} else if (ercnt) {
|
187 |
fprintf(stderr, "%d errors while converting arguments from %s "
|
223 |
fprintf(stderr, "%d errors while converting arguments from %s "
|
188 |
"to utf-8\n", ercnt, charset.c_str());
|
224 |
"to utf-8\n", ercnt, charset.c_str());
|
189 |
}
|
225 |
}
|
190 |
qs = uq;
|
226 |
qs = uq;
|
191 |
}
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
Rcl::Db rcldb(rclconfig);
|
|
|
195 |
if (!extra_dbs.empty()) {
|
|
|
196 |
for (list<string>::iterator it = extra_dbs.begin();
|
|
|
197 |
it != extra_dbs.end(); it++) {
|
|
|
198 |
if (!rcldb.addQueryDb(*it)) {
|
|
|
199 |
cerr << "Can't add index: " << *it << endl;
|
|
|
200 |
exit(1);
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
if (!rcldb.open(Rcl::Db::DbRO)) {
|
|
|
206 |
cerr << "Cant open database in " << rclconfig->getDbDir() <<
|
|
|
207 |
" reason: " << rcldb.getReason() << endl;
|
|
|
208 |
exit(1);
|
|
|
209 |
}
|
227 |
}
|
210 |
|
228 |
|
211 |
Rcl::SearchData *sd = 0;
|
229 |
Rcl::SearchData *sd = 0;
|
212 |
|
230 |
|
213 |
if (op_flags & (OPT_a|OPT_o|OPT_f)) {
|
231 |
if (op_flags & (OPT_a|OPT_o|OPT_f)) {
|