~ubuntu-branches/ubuntu/oneiric/strigi/oneiric

« back to all changes in this revision

Viewing changes to libstreamanalyzer/plugins/indexers/cluceneindexer/indexdump/indexdump.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2011-09-20 08:50:25 UTC
  • mto: (1.1.20 upstream) (5.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20110920085025-wszfu6x8rshrjq0e
ImportĀ upstreamĀ versionĀ 0.7.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Strigi Desktop Search
 
2
 *
 
3
 * Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Library General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Library General Public License
 
16
 * along with this library; see the file COPYING.LIB.  If not, write to
 
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
 */
 
20
#include <CLucene.h>
 
21
#include <CLucene/search/QueryFilter.h>
 
22
#include "../cluceneindexmanager.h"
 
23
#include "../tcharutils.h"
 
24
#include <sstream>
 
25
#include <iostream>
 
26
#include <cassert>
 
27
 
 
28
using lucene::search::Hits;
 
29
using lucene::search::IndexSearcher;
 
30
using lucene::document::Document;
 
31
using lucene::document::Field;
 
32
using lucene::index::Term;
 
33
using lucene::index::TermEnum;
 
34
using lucene::search::TermQuery;
 
35
using lucene::search::WildcardQuery;
 
36
using lucene::search::BooleanQuery;
 
37
using lucene::search::RangeQuery;
 
38
using lucene::search::QueryFilter;
 
39
using lucene::search::HitCollector;
 
40
using lucene::util::BitSet;
 
41
using lucene::document::DocumentFieldEnumeration;
 
42
using lucene::index::IndexReader;
 
43
 
 
44
void
 
45
docdump(Document* doc) {
 
46
    DocumentFieldEnumeration* e = doc->fields();
 
47
    Field* f = e->nextElement();
 
48
    while (f) {
 
49
        f = e->nextElement();
 
50
    }
 
51
    delete e;
 
52
}
 
53
std::string
 
54
t2a(const TCHAR* t) {
 
55
    return wchartoutf8(t);
 
56
}
 
57
void
 
58
indexdump(const char* dir) {
 
59
    IndexReader* indexreader = IndexReader::open(dir);
 
60
    int32_t max = indexreader->maxDoc();
 
61
    for (int i=0; i<max; ++i) {
 
62
        Document* doc = indexreader->document(i);
 
63
        if (doc) {
 
64
            docdump(doc);
 
65
        }
 
66
    }
 
67
    TermEnum* terms = indexreader->terms();
 
68
    while (terms->next()) {
 
69
        Term* t = terms->term();
 
70
        printf("%s: %s\n", t2a(t->field()).c_str(), t2a(t->text()).c_str());
 
71
        _CLDECDELETE(t);
 
72
    }
 
73
}
 
74
int
 
75
main(int argc, char** argv) {
 
76
    try {
 
77
        for (int i=1; i<argc; ++i) {
 
78
            indexdump(argv[i]);
 
79
        }
 
80
    } catch (...) {
 
81
                fprintf(stderr,"error while dumping index\n");
 
82
    }
 
83
    return 0;
 
84
}