Switch to unified view

a/src/query/recollq.cpp b/src/query/recollq.cpp
...
...
56
    cout << "Cant turn to text:" << idoc.url << " | " << idoc.ipath << endl;
56
    cout << "Cant turn to text:" << idoc.url << " | " << idoc.ipath << endl;
57
    }
57
    }
58
    return true;
58
    return true;
59
}
59
}
60
60
61
void output_fields(const vector<string>fields, Rcl::Doc& doc,
61
void output_fields(vector<string> fields, Rcl::Doc& doc,
62
           Rcl::Query& query, Rcl::Db& rcldb)
62
           Rcl::Query& query, Rcl::Db& rcldb, bool printnames)
63
{
63
{
64
    if (fields.empty()) {
65
        map<string,string>::const_iterator it;
66
        for (it = doc.meta.begin();it != doc.meta.end(); it++) {
67
            fields.push_back(it->first);
68
        }
69
    }
64
    for (vector<string>::const_iterator it = fields.begin();
70
    for (vector<string>::const_iterator it = fields.begin();
65
     it != fields.end(); it++) {
71
     it != fields.end(); it++) {
66
    string out;
72
    string out;
67
    if (!it->compare("abstract")) {
73
    if (!it->compare("abstract")) {
68
        string abstract;
74
        string abstract;
69
        query.makeDocAbstract(doc, abstract);
75
        query.makeDocAbstract(doc, abstract);
70
        base64_encode(abstract, out);
76
        base64_encode(abstract, out);
71
    } else {
77
    } else {
72
        base64_encode(doc.meta[*it], out);
78
        base64_encode(doc.meta[*it], out);
73
    }
79
    }
80
        // Before printnames existed, recollq printed a single blank for empty
81
        // fields. This is a problem when printing names and using strtok, but
82
        // have to keep the old behaviour when printnames is not set.
83
        if (!(out.empty() && printnames)) {
84
            if (printnames)
85
                cout << *it << " ";
74
  cout << out << " ";
86
            cout << out << " ";
87
        }
75
    }
88
    }
76
    cout << endl;
89
    cout << endl;
77
}
90
}
78
91
79
static char *thisprog;
92
static char *thisprog;
80
static char usage [] =
93
static char usage [] =
81
" -P: Show the date span for all the documents present in the index\n"
94
" -P: Show the date span for all the documents present in the index\n"
82
" [-o|-a|-f] [-q] <query string>\n"
95
" [-o|-a|-f] [-q] <query string>\n"
83
" Runs a recoll query and displays result lines. \n"
96
" Runs a recoll query and displays result lines. \n"
84
"  Default: will interpret the argument(s) as a xesam query string\n"
97
"  Default: will interpret the argument(s) as a xesam query string\n"
85
"    query may be like: \n"
98
"  Query elements: \n"
86
"    implicit AND, Exclusion, field spec:    t1 -t2 title:t3\n"
99
"   * Implicit AND, exclusion, field spec:  t1 -t2 title:t3\n"
87
"    OR has priority: t1 OR t2 t3 OR t4 means (t1 OR t2) AND (t3 OR t4)\n"
100
"   * OR has priority: t1 OR t2 t3 OR t4 means (t1 OR t2) AND (t3 OR t4)\n"
88
"    Phrase: \"t1 t2\" (needs additional quoting on cmd line)\n"
101
"   * Phrase: \"t1 t2\" (needs additional quoting on cmd line)\n"
89
"  -o Emulate the GUI simple search in ANY TERM mode\n"
102
" -o Emulate the GUI simple search in ANY TERM mode\n"
90
"  -a Emulate the GUI simple search in ALL TERMS mode\n"
103
" -a Emulate the GUI simple search in ALL TERMS mode\n"
91
"  -f Emulate the GUI simple search in filename mode\n"
104
" -f Emulate the GUI simple search in filename mode\n"
92
"  -q is just ignored (compatibility with the recoll GUI command line)\n"
105
" -q is just ignored (compatibility with the recoll GUI command line)\n"
93
"Common options:\n"
106
"Common options:\n"
94
"    -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n"
107
" -c <configdir> : specify config directory, overriding $RECOLL_CONFDIR\n"
95
"    -d also dump file contents\n"
108
" -d also dump file contents\n"
96
"    -n [first-]<cnt> define the result slice. The default value for [first]\n"
109
" -n [first-]<cnt> define the result slice. The default value for [first]\n"
97
"       is 0. Without the option, the default max count is 2000.\n"
110
"    is 0. Without the option, the default max count is 2000.\n"
98
"       Use n=0 for no limit\n"
111
"    Use n=0 for no limit\n"
99
"    -b : basic. Just output urls, no mime types or titles\n"
112
" -b : basic. Just output urls, no mime types or titles\n"
100
"    -Q : no result lines, just the processed query and result count\n"
113
" -Q : no result lines, just the processed query and result count\n"
101
"    -m : dump the whole document meta[] array for each result\n"
114
" -m : dump the whole document meta[] array for each result\n"
102
"    -A : output the document abstracts\n"
115
" -A : output the document abstracts\n"
103
"    -S fld : sort by field <fld>\n"
116
" -S fld : sort by field <fld>\n"
104
"    -s stemlang : set stemming language to use (must exist in index...)\n"
105
"       Use -s \"\" to turn off stem expansion\n"
106
"    -D : sort descending\n"
117
"   -D : sort descending\n"
118
" -s stemlang : set stemming language to use (must exist in index...)\n"
119
"    Use -s \"\" to turn off stem expansion\n"
107
"    -i <dbdir> : additional index, several can be given\n"
120
" -i <dbdir> : additional index, several can be given\n"
108
"    -e use url encoding (%xx) for urls\n"
121
" -e use url encoding (%xx) for urls\n"
109
"    -F <field name list> : output exactly these fields for each result.\n"
122
" -F <field name list> : output exactly these fields for each result.\n"
110
"       The field values are encoded in base64, output in one line and \n"
123
"    The field values are encoded in base64, output in one line and \n"
111
"       separated by one space character. This is the recommended format \n"
124
"    separated by one space character. This is the recommended format \n"
112
"       for use by other programs. Use a normal query with option -m to \n"
125
"    for use by other programs. Use a normal query with option -m to \n"
113
"       see the field names.\n"
126
"    see the field names. Use -F '' to output all fields, but you probably\n"
127
"    also want option -N in this case\n"
128
"  -N : with -F, print the (plain text) field names before the field values\n"
114
;
129
;
115
static void
130
static void
116
Usage(void)
131
Usage(void)
117
{
132
{
118
    cerr << thisprog <<  ": usage:" << endl << usage;
133
    cerr << thisprog <<  ": usage:" << endl << usage;
...
...
143
#define OPT_S     0x8000
158
#define OPT_S     0x8000
144
#define OPT_s     0x10000
159
#define OPT_s     0x10000
145
#define OPT_t     0x20000
160
#define OPT_t     0x20000
146
#define OPT_e     0x40000
161
#define OPT_e     0x40000
147
#define OPT_F     0x80000
162
#define OPT_F     0x80000
163
#define OPT_N     0x100000
148
164
149
int recollq(RclConfig **cfp, int argc, char **argv)
165
int recollq(RclConfig **cfp, int argc, char **argv)
150
{
166
{
151
    string a_config;
167
    string a_config;
152
    string sortfield;
168
    string sortfield;
...
...
188
        case 'i':   op_flags |= OPT_i; if (argc < 2)  Usage();
204
        case 'i':   op_flags |= OPT_i; if (argc < 2)  Usage();
189
        extra_dbs.push_back(*(++argv));
205
        extra_dbs.push_back(*(++argv));
190
        argc--; goto b1;
206
        argc--; goto b1;
191
            case 'l':   op_flags |= OPT_l; break;
207
            case 'l':   op_flags |= OPT_l; break;
192
            case 'm':   op_flags |= OPT_m; break;
208
            case 'm':   op_flags |= OPT_m; break;
209
            case 'N':   op_flags |= OPT_N; break;
193
        case 'n':   op_flags |= OPT_n; if (argc < 2)  Usage();
210
        case 'n':   op_flags |= OPT_n; if (argc < 2)  Usage();
194
        {
211
        {
195
        string rescnt = *(++argv);
212
        string rescnt = *(++argv);
196
        string::size_type dash = rescnt.find("-");
213
        string::size_type dash = rescnt.find("-");
197
        if (dash != string::npos) {
214
        if (dash != string::npos) {
...
...
352
    Rcl::Doc doc;
369
    Rcl::Doc doc;
353
    if (!query.getDoc(i, doc))
370
    if (!query.getDoc(i, doc))
354
        break;
371
        break;
355
372
356
    if (op_flags & OPT_F) {
373
    if (op_flags & OPT_F) {
357
        output_fields(fields, doc, query, rcldb);
374
        output_fields(fields, doc, query, rcldb, op_flags & OPT_N);
358
        continue;
375
        continue;
359
    }
376
    }
360
377
361
    if (op_flags & OPT_e) 
378
    if (op_flags & OPT_e) 
362
        doc.url = url_encode(doc.url);
379
        doc.url = url_encode(doc.url);