PDA

View Full Version : QtCLucene indexing



superpacko
24th November 2011, 14:32
Hey there, i've seen that theres a libQtCLucene4.a library in the lib folder and there's also a CLucene folder inside /src/3rdparty/clucene/src/

Since i wasnt able to compile clucene on windows, i thought about giving this a try. I made a simple main that indexes to files, adding the necesary includepaths and defining _BUILD_FOR_QT_ to avoid looking for the clucene-config.h file.

It compiled fine, but when trying to link it throws undefined references to every CLucene class, and also inside clucene classes it throws an error "vtable for lucene::analysis::WhitespaceAnalyzer". Has Any one used this libraries and headers?

heres my pro file, and my simple main.cpp

testQtLucene.pro:


QT += core

QT -= gui

TARGET = testQtLucene
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

INCLUDEPATH += C:\Qt\4.7.4\src\3rdparty\clucene\src C:\Qt\4.7.4\src\3rdparty\clucene\src\CLucene C:\Qt\4.7.4\tools\assistant\lib

SOURCES += main.cpp

LIBS += -lQtCLucene4

DEFINES += _BUILD_FOR_QT_


main.cpp:


#include <QtCore/QCoreApplication>
#include "CLucene.h"
#include "CLucene/CLConfig.h"
#include <QFileInfo>

using namespace lucene::index;
using namespace lucene::analysis;
using namespace lucene::util;
using namespace lucene::store;
using namespace lucene::document;

int main(int argc, char *argv[])
{
WhitespaceAnalyzer an;
IndexWriter *writer = new IndexWriter("luceneIndex", &an, true);

QFile file("test1.txt");
file.open(QIODevice::ReadWrite);
QString content(file.readAll());
file.close();

Document doc;
doc.add(*new Field(_T("path"), QFileInfo("test1.txt").absolutePath().toStdWString().c_str(), Field::STORE_YES | Field::INDEX_UNTOKENIZED));
doc.add(*new Field(_T("contents"), content.toStdWString().c_str() , Field::STORE_YES | Field::INDEX_TOKENIZED));

writer->addDocument( &doc );

file.setFileName("test2.txt");
file.open(QIODevice::ReadWrite);
content = QString(file.readAll());
file.close();

doc.clear();
doc.add(*new Field(_T("path"), QFileInfo("test2.txt").absolutePath().toStdWString().c_str(), Field::STORE_YES | Field::INDEX_UNTOKENIZED));
doc.add(*new Field(_T("contents"), content.toStdWString().c_str() , Field::STORE_YES | Field::INDEX_TOKENIZED));

writer->addDocument( &doc );

return 0;
}