Beispiel #1
0
QCLuceneToken::QCLuceneToken(const QString &text, qint32 startOffset, 
                             qint32 endOffset, const QString &defaultTyp)
    : d(new QCLuceneTokenPrivate())
    , tokenText(QStringToTChar(text))
    , tokenType(QStringToTChar(defaultTyp))
{
    d->token = new lucene::analysis::Token(tokenText, int32_t(startOffset), 
        int32_t(endOffset), tokenType);
}
void QCLuceneTerm::set(const QString &field, const QString &text, bool internField)
{
    TCHAR *fieldName = QStringToTChar(field);
    TCHAR *termText = QStringToTChar(text);

    d->term->set(fieldName, termText, internField);

    delete [] fieldName;
    delete [] termText;
}
QCLuceneTerm::QCLuceneTerm(const QString &field, const QString &text)
    : d(new QCLuceneTermPrivate())
{
    TCHAR *fieldName = QStringToTChar(field);
    TCHAR *termText = QStringToTChar(text);

    d->term = new lucene::index::Term(fieldName, termText);

    delete [] fieldName;
    delete [] termText;
}
Beispiel #4
0
QCLuceneField::QCLuceneField(const QString &name, const QString &value, int configs)
    : d(new QCLuceneFieldPrivate())
    , reader(0)
{
    TCHAR* fieldName = QStringToTChar(name);
    TCHAR* fieldValue = QStringToTChar(value);
    
    d->field = new lucene::document::Field(fieldName, fieldValue, configs);

    delete [] fieldName;
    delete [] fieldValue;
}
Beispiel #5
0
QCLuceneField* QCLuceneDocument::getField(const QString &name) const
{
    QCLuceneField* field = 0;
    foreach (field, fieldList) {
        if (field->name() == name && field->d->field != 0)
            return field;
    }

    field = 0;
    TCHAR *fieldName = QStringToTChar(name);
    lucene::document::Field *f = d->document->getField(fieldName);
    if (f) {
        field = new QCLuceneField();
        field->d->field = f;
        fieldList.append(field);
        field->d->deleteCLuceneField = false;

        lucene::util::Reader *r = f->readerValue();
        if (r) {
            field->reader->d->reader = r;
            field->reader->d->deleteCLuceneReader = false;
        }
    }
    delete [] fieldName;
    
    return field;
}
Beispiel #6
0
QCLuceneStringReader::QCLuceneStringReader(const QString &value, qint32 length,
                                           bool copyData)
    : QCLuceneReader()
    , string(QStringToTChar(value))
{
    d->reader = new lucene::util::StringReader(string, int32_t(length), copyData);
}
QCLuceneTerm::QCLuceneTerm(const QCLuceneTerm &fieldTerm, const QString &text)
    : d(new QCLuceneTermPrivate())
{
    TCHAR *termText = QStringToTChar(text);
    d->term = new lucene::index::Term(fieldTerm.d->term, termText);
    delete [] termText;
}
Beispiel #8
0
QCLuceneTokenStream QCLuceneAnalyzer::tokenStream(const QString &fieldName,
                                                  const QCLuceneReader &reader) const
{
    TCHAR *fName = QStringToTChar(fieldName);
    QCLuceneTokenStream tokenStream;
    tokenStream.d->tokenStream = d->analyzer->tokenStream(fName, reader.d->reader);
    delete [] fName;

    return tokenStream;
}
Beispiel #9
0
void QCLuceneDocument::removeFields(const QString &name)
{
    for (qint32 i = fieldList.count() -1; i >= 0; --i) {
        QCLuceneField* field = fieldList.at(i);
        if (field->name() == name)
            delete fieldList.takeAt(i);
    }

    TCHAR *fieldName = QStringToTChar(name);
    d->document->removeFields(fieldName);
    delete [] fieldName;
}
Beispiel #10
0
QCLuceneField::QCLuceneField(const QString &name, QCLuceneReader *reader, 
                             int configs)
    : d(new QCLuceneFieldPrivate())
    , reader(reader)
{
    TCHAR* fieldName = QStringToTChar(name);

    reader->d->deleteCLuceneReader = false; // clucene takes ownership
    d->field = new lucene::document::Field(fieldName, reader->d->reader, configs);
    
    delete [] fieldName;
}
Beispiel #11
0
void QCLuceneSort::setSort(const QStringList &fieldNames)
{
    TCHAR **nameArray = new TCHAR*[fieldNames.count()];
    for (int i = 0; i < fieldNames.count(); ++i)
        nameArray[i] = QStringToTChar(fieldNames.at(i));

    d->sort->setSort((const TCHAR**)nameArray);

    for (int i = 0; i < fieldNames.count(); ++i)
        delete [] nameArray[i];
    delete [] nameArray;
}
QCLuceneQueryParser::QCLuceneQueryParser(const QString &field,
                                         QCLuceneAnalyzer &analyzer)
    : d(new QCLuceneQueryParserPrivate())
    , field(field)
    , analyzer(analyzer)
{
    TCHAR *fieldName = QStringToTChar(field);

    d->queryParser = new lucene::queryParser::QueryParser(fieldName,
        analyzer.d->analyzer);

    delete [] fieldName;
}
QCLuceneStandardAnalyzer::QCLuceneStandardAnalyzer(const QStringList &stopWords)
{
    const TCHAR **tArray = new const TCHAR*[stopWords.count() +1];

    for(int i = 0; i < stopWords.count(); ++i) {
        TCHAR *stopWord = QStringToTChar(stopWords.at(i));
        tArray[i] = STRDUP_TtoT(stopWord);
        delete [] stopWord;
    }
    tArray[stopWords.count()] = 0;

    d->analyzer = new lucene::analysis::standard::StandardAnalyzer(tArray);
}
QCLuceneQuery* QCLuceneQueryParser::parse(const QString &query)
{
    TCHAR *string = QStringToTChar(query);

    QCLuceneQuery *retValue = 0;
    lucene::search::Query* q = d->queryParser->parse(string);
    if (q) {
        retValue = new QCLuceneQuery();
        retValue->d->query = q;
    }

    delete [] string;
    return retValue;
}
Beispiel #15
0
bool QCLuceneStandardTokenizer::readAt(const QString &string, QCLuceneToken &token)
{
    lucene::analysis::standard::StandardTokenizer *stdTokenizer = 
        static_cast<lucene::analysis::standard::StandardTokenizer*> (d->tokenStream);

    if (stdTokenizer == 0)
        return false;

    TCHAR* value = QStringToTChar(string);
    lucene::util::StringBuffer buffer(value);
    bool retValue = stdTokenizer->ReadAt(&buffer, token.d->token);
    delete [] value;
    
    return retValue;
}
Beispiel #16
0
void QCLucenePerFieldAnalyzerWrapper::addAnalyzer(const QString &fieldName, 
                                                  QCLuceneAnalyzer *analyzer)
{
    lucene::analysis::PerFieldAnalyzerWrapper *analyzerWrapper = 
        static_cast<lucene::analysis::PerFieldAnalyzerWrapper*> (d->analyzer);

    if (analyzerWrapper == 0)
        return;

    analyzers.append(analyzer);
    analyzer->d->deleteCLuceneAnalyzer = false;

    TCHAR *fName = QStringToTChar(fieldName);
    analyzerWrapper->addAnalyzer(fName, analyzer->d->analyzer);
    delete [] fName;
}
Beispiel #17
0
QStringList QCLuceneDocument::getValues(const QString &name) const
{
    TCHAR *fieldName = QStringToTChar(name);
    TCHAR **values = d->document->getValues(fieldName);

    QStringList retValue;
    if (values) {
        for (qint32 i = 0; 0 != values[i]; ++i) {
            retValue.append(TCharToQString((const TCHAR*)values[i]));
            delete [] values[i]; values[i] = 0;
        }
        delete values;
    }

    delete [] fieldName;
    return retValue;
}
Beispiel #18
0
void QCLuceneDocument::removeField(const QString &name)
{
    TCHAR *fieldName = QStringToTChar(name);
    d->document->removeField(fieldName);
    delete [] fieldName;

    QList<QCLuceneField*> tmp;
    lucene::document::DocumentFieldEnumeration *dfe = d->document->fields();
    while (dfe->hasMoreElements()) {
        const lucene::document::Field* f = dfe->nextElement();
        foreach (QCLuceneField* field, fieldList) {
            if (f == field->d->field) {
                tmp.append(field);
                break;
            }
        }
    }
    _CLDELETE(dfe);
    fieldList = tmp;
}
Beispiel #19
0
QCLuceneStringReader::QCLuceneStringReader(const QString &value)
    : QCLuceneReader()
    , string(QStringToTChar(value))
{
    d->reader = new lucene::util::StringReader(string);
}
Beispiel #20
0
void QCLuceneToken::setTermText(const QString &text)
{
    delete [] tokenText;
    tokenText = QStringToTChar(text);
    d->token->setText(tokenText);
}
Beispiel #21
0
void QCLuceneToken::setType(const QString &type)
{
    delete [] tokenType;
    tokenType = QStringToTChar(type);
    d->token->setType(tokenType);
}
Beispiel #22
0
void QCLuceneSort::setSort(const QString &field, bool reverse)
{
    TCHAR *name = QStringToTChar(field);
    d->sort->setSort(name, reverse);
    delete [] name;
}