Switch to unified view

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.8 2006-01-23 13:32:28 dockes Exp $ (C) 2004 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: xadump.cpp,v 1.9 2006-01-25 08:09:41 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
...
...
35
static string thisprog;
35
static string thisprog;
36
36
37
static string usage =
37
static string usage =
38
    " -d <dbdir> -e <output encoding>\n"
38
    " -d <dbdir> -e <output encoding>\n"
39
    " -i docid -D : get document data for docid\n"
39
    " -i docid -D : get document data for docid\n"
40
    " -i docid -b : 'rebuild' document from term positions\n"
40
    " -t term -E  : term existence test\n"
41
    " -t term -E  : term existence test\n"
41
    " -t term -F  : retrieve term frequency data\n"
42
    " -t term -F  : retrieve term frequency data\n"
42
    " -t term -P  : retrieve postings for term\n"
43
    " -t term -P  : retrieve postings for term\n"
43
    " -i docid -T : term list for doc docid\n"
44
    " -i docid -T : term list for doc docid\n"
44
    " -T          : list all terms\n"
45
    " -T          : list all terms\n"
...
...
60
#define OPT_D     0x10
61
#define OPT_D     0x10
61
#define OPT_t     0x20
62
#define OPT_t     0x20
62
#define OPT_P     0x40
63
#define OPT_P     0x40
63
#define OPT_F     0x80
64
#define OPT_F     0x80
64
#define OPT_E     0x100
65
#define OPT_E     0x100
66
#define OPT_b     0x200
65
67
66
Xapian::Database *db;
68
Xapian::Database *db;
67
69
68
static void cleanup()
70
static void cleanup()
69
{
71
{
...
...
97
        case 'D':   op_flags |= OPT_D; break;
99
        case 'D':   op_flags |= OPT_D; break;
98
        case 'E':   op_flags |= OPT_E; break;
100
        case 'E':   op_flags |= OPT_E; break;
99
        case 'F':   op_flags |= OPT_F; break;
101
        case 'F':   op_flags |= OPT_F; break;
100
        case 'P':   op_flags |= OPT_P; break;
102
        case 'P':   op_flags |= OPT_P; break;
101
        case 'T':   op_flags |= OPT_T; break;
103
        case 'T':   op_flags |= OPT_T; break;
104
      case 'b':   op_flags |= OPT_b; break;
102
        case 'd':   op_flags |= OPT_d; if (argc < 2)  Usage();
105
        case 'd':   op_flags |= OPT_d; if (argc < 2)  Usage();
103
        dbdir = *(++argv);
106
        dbdir = *(++argv);
104
        argc--; 
107
        argc--; 
105
        goto b1;
108
        goto b1;
106
        case 'e':   op_flags |= OPT_d; if (argc < 2)  Usage();
109
        case 'e':   op_flags |= OPT_d; if (argc < 2)  Usage();
...
...
158
        }
161
        }
159
    } else if (op_flags & OPT_D) {
162
    } else if (op_flags & OPT_D) {
160
        Xapian::Document doc = db->get_document(docid);
163
        Xapian::Document doc = db->get_document(docid);
161
        string data = doc.get_data();
164
        string data = doc.get_data();
162
        cout << data << endl;
165
        cout << data << endl;
166
  } else if (op_flags & OPT_b) {
167
      if (!(op_flags & OPT_i))
168
      Usage();
169
      vector<string> buf;
170
      Xapian::TermIterator term;
171
      for (term = db->termlist_begin(docid);
172
       term != db->termlist_end(docid); term++) {
173
      Xapian::PositionIterator pos;
174
      for (pos = db->positionlist_begin(docid, *term); 
175
           pos != db->positionlist_end(docid, *term); pos++) {
176
          if (buf.size() < *pos)
177
          buf.resize((*pos)+1);
178
          buf[(*pos)] = *term;
179
      }
180
      }
181
      for (vector<string>::iterator it = buf.begin(); it != buf.end();
182
       it++) {
183
      cout << *it << " ";
184
      }
163
    } else if (op_flags & OPT_P) {
185
    } else if (op_flags & OPT_P) {
164
        Xapian::PostingIterator doc;
186
        Xapian::PostingIterator doc;
165
        for (doc = db->postlist_begin(aterm);
187
        for (doc = db->postlist_begin(aterm);
166
         doc != db->postlist_end(aterm);doc++) {
188
         doc != db->postlist_end(aterm); doc++) {
167
        cout << *doc << endl;
189
        cout << *doc << " : " ;
190
      Xapian::PositionIterator pos;
191
      for (pos = doc.positionlist_begin(); 
192
           pos != doc.positionlist_end(); pos++) {
193
          cout << *pos << " " ;
194
      }
195
      cout << endl;
168
        }
196
        }
169
        
197
        
170
    } else if (op_flags & OPT_F) {
198
    } else if (op_flags & OPT_F) {
171
        cout << "FreqFor " << aterm << " : " <<
199
        cout << "FreqFor " << aterm << " : " <<
172
        db->get_termfreq(aterm) << endl;
200
        db->get_termfreq(aterm) << endl;