|
a/src/query/xadump.cpp |
|
b/src/query/xadump.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: xadump.cpp,v 1.13 2006-12-07 16:38:24 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: xadump.cpp,v 1.14 2007-01-13 14:41:40 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
42 |
" -t term -F : retrieve term frequency data for given term\n"
|
42 |
" -t term -F : retrieve term frequency data for given term\n"
|
43 |
" -t term -P : retrieve postings for term\n"
|
43 |
" -t term -P : retrieve postings for term\n"
|
44 |
" -i docid -T : term list for doc docid\n"
|
44 |
" -i docid -T : term list for doc docid\n"
|
45 |
" -T : list all terms\n"
|
45 |
" -T : list all terms\n"
|
46 |
" -f : precede each term in the list with its occurrence count\n"
|
46 |
" -f : precede each term in the list with its occurrence count\n"
|
|
|
47 |
" -n : raw data (no [])\n"
|
47 |
" -s : special mode to dump recoll stem db\n"
|
48 |
" -s : special mode to dump recoll stem db\n"
|
48 |
" -q term [term ...] : perform AND query\n"
|
49 |
" -q term [term ...] : perform AND query\n"
|
49 |
" \n\n"
|
50 |
" \n\n"
|
50 |
;
|
51 |
;
|
51 |
|
52 |
|
|
... |
|
... |
68 |
#define OPT_E 0x100
|
69 |
#define OPT_E 0x100
|
69 |
#define OPT_b 0x200
|
70 |
#define OPT_b 0x200
|
70 |
#define OPT_s 0x400
|
71 |
#define OPT_s 0x400
|
71 |
#define OPT_f 0x800
|
72 |
#define OPT_f 0x800
|
72 |
#define OPT_q 0x1000
|
73 |
#define OPT_q 0x1000
|
|
|
74 |
#define OPT_n 0x2000
|
73 |
|
75 |
|
74 |
Xapian::Database *db;
|
76 |
Xapian::Database *db;
|
75 |
|
77 |
|
76 |
static void cleanup()
|
78 |
static void cleanup()
|
77 |
{
|
79 |
{
|
|
... |
|
... |
117 |
case 'f': op_flags |= OPT_f; break;
|
119 |
case 'f': op_flags |= OPT_f; break;
|
118 |
case 'i': op_flags |= OPT_i; if (argc < 2) Usage();
|
120 |
case 'i': op_flags |= OPT_i; if (argc < 2) Usage();
|
119 |
if (sscanf(*(++argv), "%d", &docid) != 1) Usage();
|
121 |
if (sscanf(*(++argv), "%d", &docid) != 1) Usage();
|
120 |
argc--;
|
122 |
argc--;
|
121 |
goto b1;
|
123 |
goto b1;
|
|
|
124 |
case 'n': op_flags |= OPT_n; break;
|
122 |
case 'P': op_flags |= OPT_P; break;
|
125 |
case 'P': op_flags |= OPT_P; break;
|
123 |
case 'q': op_flags |= OPT_q; break;
|
126 |
case 'q': op_flags |= OPT_q; break;
|
124 |
case 's': op_flags |= OPT_s; break;
|
127 |
case 's': op_flags |= OPT_s; break;
|
125 |
case 'T': op_flags |= OPT_T; break;
|
128 |
case 'T': op_flags |= OPT_T; break;
|
126 |
case 't': op_flags |= OPT_t; if (argc < 2) Usage();
|
129 |
case 't': op_flags |= OPT_t; if (argc < 2) Usage();
|
|
... |
|
... |
140 |
while (argc > 0) {
|
143 |
while (argc > 0) {
|
141 |
qterms.push_back(*argv++); argc--;
|
144 |
qterms.push_back(*argv++); argc--;
|
142 |
}
|
145 |
}
|
143 |
}
|
146 |
}
|
144 |
|
147 |
|
145 |
fprintf(stderr, "argc %d\n", argc);
|
|
|
146 |
if (argc != 0)
|
148 |
if (argc != 0)
|
147 |
Usage();
|
149 |
Usage();
|
148 |
|
150 |
|
149 |
atexit(cleanup);
|
151 |
atexit(cleanup);
|
150 |
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
|
152 |
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
|
|
... |
|
... |
163 |
db->get_lastdocid() << " avglength " << db->get_avlength() << endl;
|
165 |
db->get_lastdocid() << " avglength " << db->get_avlength() << endl;
|
164 |
|
166 |
|
165 |
if (op_flags & OPT_T) {
|
167 |
if (op_flags & OPT_T) {
|
166 |
Xapian::TermIterator term;
|
168 |
Xapian::TermIterator term;
|
167 |
string printable;
|
169 |
string printable;
|
|
|
170 |
string op = (op_flags & OPT_n) ? "": "[";
|
|
|
171 |
string cl = (op_flags & OPT_n) ? "": "]";
|
168 |
if (op_flags & OPT_i) {
|
172 |
if (op_flags & OPT_i) {
|
169 |
for (term = db->termlist_begin(docid);
|
173 |
for (term = db->termlist_begin(docid);
|
170 |
term != db->termlist_end(docid);term++) {
|
174 |
term != db->termlist_end(docid);term++) {
|
171 |
cout << "[" << *term << "]" << endl;
|
175 |
cout << op << *term << cl << endl;
|
172 |
}
|
176 |
}
|
173 |
} else {
|
177 |
} else {
|
174 |
for (term = db->allterms_begin();
|
178 |
for (term = db->allterms_begin();
|
175 |
term != db->allterms_end();term++) {
|
179 |
term != db->allterms_end();term++) {
|
176 |
if (op_flags & OPT_f)
|
180 |
if (op_flags & OPT_f)
|
177 |
cout << term.get_termfreq() << " ";
|
181 |
cout << term.get_termfreq() << " ";
|
178 |
cout << "[" << *term << "]" << endl;
|
182 |
cout << op << *term << cl << endl;
|
179 |
}
|
183 |
}
|
180 |
}
|
184 |
}
|
181 |
} else if (op_flags & OPT_s) {
|
185 |
} else if (op_flags & OPT_s) {
|
182 |
for (unsigned int docid = 1;
|
186 |
for (unsigned int docid = 1;
|
183 |
docid < db->get_lastdocid(); docid++) {
|
187 |
docid < db->get_lastdocid(); docid++) {
|