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.3 2005-01-25 14:37:21 dockes Exp $ (C) 2004 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: xadump.cpp,v 1.4 2005-02-08 09:34:47 dockes Exp $ (C) 2004 J.F.Dockes";
3
#endif
3
#endif
4
4
5
#include <strings.h>
5
#include <strings.h>
6
6
7
#include <iostream>
7
#include <iostream>
...
...
43
#define OPT_t     0x20
43
#define OPT_t     0x20
44
#define OPT_P     0x40
44
#define OPT_P     0x40
45
#define OPT_F     0x80
45
#define OPT_F     0x80
46
#define OPT_E     0x100
46
#define OPT_E     0x100
47
47
48
Xapian::Database db;
48
Xapian::Database *db;
49
50
static void cleanup()
51
{
52
    delete db;
53
}
54
55
static void sigcleanup(int sig)
56
{
57
    fprintf(stderr, "sigcleanup\n");
58
    cleanup();
59
    exit(1);
60
}
49
61
50
int main(int argc, char **argv)
62
int main(int argc, char **argv)
51
{
63
{
52
    string dbdir = "/home/dockes/tmp/xapiandb";
64
    string dbdir = "/home/dockes/.recoll/xapiandb";
53
    string outencoding = "ISO8859-1";
65
    string outencoding = "ISO8859-1";
54
    int docid = 1;
66
    int docid = 1;
55
    string aterm;
67
    string aterm;
56
68
57
    thisprog = argv[0];
69
    thisprog = argv[0];
...
...
90
    b1: argc--; argv++;
102
    b1: argc--; argv++;
91
    }
103
    }
92
104
93
    if (argc != 0)
105
    if (argc != 0)
94
    Usage();
106
    Usage();
107
    atexit(cleanup);
108
    if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
109
  signal(SIGHUP, sigcleanup);
110
    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
111
  signal(SIGINT, sigcleanup);
112
    if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
113
  signal(SIGQUIT, sigcleanup);
114
    if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
115
  signal(SIGTERM, sigcleanup);
95
116
96
    try {
117
    try {
97
  db = Xapian::Auto::open(dbdir, Xapian::DB_OPEN);
118
  db = new Xapian::Database(dbdir);
98
119
99
    cout << "DB: ndocs " << db.get_doccount() << " lastdocid " <<
120
    cout << "DB: ndocs " << db->get_doccount() << " lastdocid " <<
100
        db.get_lastdocid() << " avglength " << db.get_avlength() << endl;
121
        db->get_lastdocid() << " avglength " << db->get_avlength() << endl;
101
        
122
        
102
    if (op_flags & OPT_T) {
123
    if (op_flags & OPT_T) {
103
        Xapian::TermIterator term;
124
        Xapian::TermIterator term;
104
        string printable;
125
        string printable;
105
        if (op_flags & OPT_i) {
126
        if (op_flags & OPT_i) {
106
        for (term = db.termlist_begin(docid);
127
        for (term = db->termlist_begin(docid);
107
             term != db.termlist_end(docid);term++) {
128
             term != db->termlist_end(docid);term++) {
108
            transcode(*term, printable, "UTF-8", outencoding);
129
            transcode(*term, printable, "UTF-8", outencoding);
109
            cout << printable << endl;
130
            cout << "[" << printable << "]" << endl;
110
        }
131
        }
111
        } else {
132
        } else {
112
        for (term = db.allterms_begin(); 
133
        for (term = db->allterms_begin(); 
113
             term != db.allterms_end();term++) {
134
             term != db->allterms_end();term++) {
114
            transcode(*term, printable, "UTF-8", outencoding);
135
            if (transcode(*term, printable, "UTF-8", outencoding))
115
            cout << printable << endl;
136
          cout << "[" << printable << "]" << endl;
137
          else
138
          cout << "utf8[" << *term << "]" << endl;
116
        }
139
        }
117
        }
140
        }
118
    } else if (op_flags & OPT_D) {
141
    } else if (op_flags & OPT_D) {
119
        Xapian::Document doc = db.get_document(docid);
142
        Xapian::Document doc = db->get_document(docid);
120
        string data = doc.get_data();
143
        string data = doc.get_data();
121
        cout << data << endl;
144
        cout << data << endl;
122
    } else if (op_flags & OPT_P) {
145
    } else if (op_flags & OPT_P) {
123
        Xapian::PostingIterator doc;
146
        Xapian::PostingIterator doc;
124
        for (doc = db.postlist_begin(aterm);
147
        for (doc = db->postlist_begin(aterm);
125
         doc != db.postlist_end(aterm);doc++) {
148
         doc != db->postlist_end(aterm);doc++) {
126
        cout << *doc << endl;
149
        cout << *doc << endl;
127
        }
150
        }
128
        
151
        
129
    } else if (op_flags & OPT_F) {
152
    } else if (op_flags & OPT_F) {
130
        cout << "FreqFor " << aterm << " : " <<
153
        cout << "FreqFor " << aterm << " : " <<
131
        db.get_termfreq(aterm) << endl;
154
        db->get_termfreq(aterm) << endl;
132
    } else if (op_flags & OPT_E) {
155
    } else if (op_flags & OPT_E) {
133
        cout << "Exists " << aterm << " : " <<
156
        cout << "Exists " << aterm << " : " <<
134
        db.term_exists(aterm) << endl;
157
        db->term_exists(aterm) << endl;
135
    } 
158
    } 
136
159
137
160
138
161
139
    } catch (const Xapian::Error &e) {
162
    } catch (const Xapian::Error &e) {