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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2011-09-24 17:12:15 UTC
  • mfrom: (1.2.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20110924171215-zmbi1f77jntvz65h
Tags: upstream-0.7.6
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
std::string
 
45
t2a(const TCHAR* t) {
 
46
    return wchartoutf8(t);
 
47
}
 
48
void
 
49
docdump(Document* doc) {
 
50
    Document::FieldsType fields = doc->getFields();
 
51
    for ( Document::FieldsType::iterator itr = fields.begin();
 
52
          itr != fields.end();
 
53
          itr++ ){
 
54
        TCHAR* s = (*itr)->toString();
 
55
        printf("%s\n", t2a(s).c_str());
 
56
        _CLDELETE_CARRAY(s);
 
57
    }
 
58
}
 
59
void
 
60
indexdump(const char* dir) {
 
61
    IndexReader* indexreader = IndexReader::open(dir);
 
62
    int32_t max = indexreader->maxDoc();
 
63
    for (int i=0; i<max; ++i) {
 
64
        Document* doc = indexreader->document(i);
 
65
        if (doc) {
 
66
            docdump(doc);
 
67
        }
 
68
    }
 
69
    TermEnum* terms = indexreader->terms();
 
70
    Term* t = 0;
 
71
    while (terms->next()) {
 
72
        t = terms->term();
 
73
        printf("%s: %s\n", t2a(t->field()).c_str(), t2a(t->text()).c_str());
 
74
        _CLDECDELETE(t);
 
75
    }
 
76
}
 
77
int
 
78
main(int argc, char** argv) {
 
79
    try {
 
80
        for (int i=1; i<argc; ++i) {
 
81
            indexdump(argv[i]);
 
82
        }
 
83
    } catch (...) {
 
84
                fprintf(stderr,"error while dumping index\n");
 
85
    }
 
86
    return 0;
 
87
}