~ubuntu-branches/ubuntu/quantal/recoll/quantal

« back to all changes in this revision

Viewing changes to query/recollq.cpp

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2012-03-27 12:15:51 UTC
  • mfrom: (1.3.8)
  • Revision ID: package-import@ubuntu.com-20120327121551-nmntidzpehudushy
Tags: 1.17.1-1
* New upstream release.
* Enable Python module resulting into new binary: python-recoll.
* debian/control:
  + Updated Build-Deps: libqtwebkit-dev, python-all-dev.
  + Added python-recoll binary.
  + Updated Standards-Version to 3.9.3
* debian/rules:
  + Build Python module by default.
* debian/recoll.menu, debian/python-recoll.install, debian/recoll.install:
  + Changes for new binary package.
* debian/copyright:
  + Updated to copyright-format 1.0
  + Updated upstream and Debian copyright.
  + Fixed unicode.org/copyright.html URL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
 
80
80
static char *thisprog;
81
81
static char usage [] =
82
 
" -P: Show date span for documents in index\n"
83
 
" [-o|-a|-f] <query string>\n"
 
82
" -P: Show the date span for all the documents present in the index\n"
 
83
" [-o|-a|-f] [-q] <query string>\n"
84
84
" Runs a recoll query and displays result lines. \n"
85
85
"  Default: will interpret the argument(s) as a xesam query string\n"
86
86
"    query may be like: \n"
87
87
"    implicit AND, Exclusion, field spec:    t1 -t2 title:t3\n"
88
88
"    OR has priority: t1 OR t2 t3 OR t4 means (t1 OR t2) AND (t3 OR t4)\n"
89
89
"    Phrase: \"t1 t2\" (needs additional quoting on cmd line)\n"
90
 
"  -o Emulate the gui simple search in ANY TERM mode\n"
91
 
"  -a Emulate the gui simple search in ALL TERMS mode\n"
92
 
"  -f Emulate the gui simple search in filename mode\n"
 
90
"  -o Emulate the GUI simple search in ANY TERM mode\n"
 
91
"  -a Emulate the GUI simple search in ALL TERMS mode\n"
 
92
"  -f Emulate the GUI simple search in filename mode\n"
 
93
"  -q is just ignored (compatibility with the recoll GUI command line)\n"
93
94
"Common options:\n"
94
95
"    -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n"
95
96
"    -d also dump file contents\n"
96
 
"    -n <cnt> limit the maximum number of results (0->no limit, default 2000)\n"
 
97
"    -n [first-]<cnt> define the result slice. The default value for [first]\n"
 
98
"       is 0. Without the option, the default max count is 2000.\n"
 
99
"       Use n=0 for no limit\n"
97
100
"    -b : basic. Just output urls, no mime types or titles\n"
98
101
"    -Q : no result lines, just the processed query and result count\n"
99
 
"    -m : dump the whole document meta[] array\n"
 
102
"    -m : dump the whole document meta[] array for each result\n"
100
103
"    -A : output the document abstracts\n"
101
 
"    -S fld : sort by field name\n"
 
104
"    -S fld : sort by field <fld>\n"
102
105
"    -D : sort descending\n"
103
106
"    -i <dbdir> : additional index, several can be given\n"
104
107
"    -e use url encoding (%xx) for urls\n"
151
154
    string sf;
152
155
    vector<string> fields;
153
156
 
154
 
    int limit = 2000;
 
157
    int firstres = 0;
 
158
    int maxcount = 2000;
155
159
    thisprog = argv[0];
156
160
    argc--; argv++;
157
161
 
181
185
            case 'l':   op_flags |= OPT_l; break;
182
186
            case 'm':   op_flags |= OPT_m; break;
183
187
            case 'n':   op_flags |= OPT_n; if (argc < 2)  Usage();
184
 
                limit = atoi(*(++argv));
185
 
                if (limit <= 0) limit = INT_MAX;
186
 
                argc--; goto b1;
 
188
            {
 
189
                string rescnt = *(++argv);
 
190
                string::size_type dash = rescnt.find("-");
 
191
                if (dash != string::npos) {
 
192
                    firstres = atoi(rescnt.substr(0, dash).c_str());
 
193
                    if (dash < rescnt.size()-1) {
 
194
                        maxcount = atoi(rescnt.substr(dash+1).c_str());
 
195
                    }
 
196
                } else {
 
197
                    maxcount = atoi(rescnt.c_str());
 
198
                }
 
199
                if (maxcount <= 0) maxcount = INT_MAX;
 
200
            }
 
201
            argc--; goto b1;
187
202
            case 'o':   op_flags |= OPT_o; break;
188
203
            case 'P':   op_flags |= OPT_P; break;
189
204
            case 'q':   op_flags |= OPT_q; break;
307
322
    int cnt = query.getResCnt();
308
323
    if (!(op_flags & OPT_b)) {
309
324
        cout << "Recoll query: " << rq->getDescription() << endl;
310
 
        if (cnt <= limit)
311
 
            cout << cnt << " results" << endl;
312
 
        else
313
 
            cout << cnt << " results (printing  " << limit << " max):" << endl;
 
325
        if (firstres == 0) {
 
326
            if (cnt <= maxcount)
 
327
                cout << cnt << " results" << endl;
 
328
            else
 
329
                cout << cnt << " results (printing  " << maxcount << " max):" 
 
330
                     << endl;
 
331
        } else {
 
332
            cout << "Printing at most " << cnt - (firstres+maxcount) <<
 
333
                " results from first " << firstres << endl;
 
334
        }
314
335
    }
315
336
    if (op_flags & OPT_Q)
316
337
        cout << "Query setup took " << chron.millis() << " mS" << endl;
317
338
 
318
 
    TempDir tmpdir;
319
 
    if (!tmpdir.ok()) {
320
 
        cerr << "Can't create temporary directory: " << 
321
 
            tmpdir.getreason() << endl;
322
 
        return(1);
323
 
    }
324
 
 
325
339
    if (op_flags & OPT_Q)
326
340
        return(0);
327
341
 
328
 
    for (int i = 0; i < limit; i++) {
 
342
    for (int i = firstres; i < firstres + maxcount; i++) {
329
343
        Rcl::Doc doc;
330
344
        if (!query.getDoc(i, doc))
331
345
            break;
341
355
        if (op_flags & OPT_b) {
342
356
                cout << doc.url << endl;
343
357
        } else {
 
358
            string titleorfn = doc.meta[Rcl::Doc::keytt];
 
359
            if (titleorfn.empty())
 
360
                titleorfn = doc.meta[Rcl::Doc::keyfn];
 
361
 
344
362
            char cpc[20];
345
363
            sprintf(cpc, "%d", doc.pc);
346
364
            cout 
347
365
                << doc.mimetype << "\t"
348
366
                << "[" << doc.url << "]" << "\t" 
349
 
                << "[" << doc.meta[Rcl::Doc::keytt] << "]" << "\t"
 
367
                << "[" << titleorfn << "]" << "\t"
350
368
                << doc.fbytes << "\tbytes" << "\t"
351
369
                <<  endl;
352
370
            if (op_flags & OPT_m) {
365
383
            }
366
384
        }
367
385
        if (op_flags & OPT_d) {
 
386
            static TempDir tmpdir;
 
387
            if (!tmpdir.ok()) {
 
388
                cerr << "Can't create temporary directory: " << 
 
389
                    tmpdir.getreason() << endl;
 
390
                return(1);
 
391
            }
368
392
            dump_contents(rclconfig, tmpdir, doc);
369
393
        }       
370
394
    }