0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team.
|
|
4 |
** All rights reserved.
|
|
5 |
**
|
|
6 |
** Portion Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
7 |
** All rights reserved.
|
|
8 |
**
|
|
9 |
** This file may be used under the terms of the GNU Lesser General Public
|
|
10 |
** License version 2.1 as published by the Free Software Foundation and
|
|
11 |
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
12 |
** Please review the following information to ensure the GNU Lesser General
|
|
13 |
** Public License version 2.1 requirements will be met:
|
|
14 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
15 |
**
|
|
16 |
****************************************************************************/
|
|
17 |
|
|
18 |
#include "qtokenizer_p.h"
|
|
19 |
#include "qclucene_global_p.h"
|
|
20 |
|
|
21 |
#include <CLucene.h>
|
|
22 |
#include <CLucene/analysis/AnalysisHeader.h>
|
|
23 |
|
|
24 |
QT_BEGIN_NAMESPACE
|
|
25 |
|
|
26 |
QCLuceneTokenizer::QCLuceneTokenizer()
|
|
27 |
: QCLuceneTokenStream()
|
|
28 |
{
|
|
29 |
// nothing todo
|
|
30 |
}
|
|
31 |
|
|
32 |
QCLuceneTokenizer::QCLuceneTokenizer(const QCLuceneReader &reader)
|
|
33 |
: QCLuceneTokenStream()
|
|
34 |
, reader(reader)
|
|
35 |
{
|
|
36 |
// nothing todo
|
|
37 |
}
|
|
38 |
|
|
39 |
QCLuceneTokenizer::~QCLuceneTokenizer()
|
|
40 |
{
|
|
41 |
close();
|
|
42 |
}
|
|
43 |
|
|
44 |
void QCLuceneTokenizer::close()
|
|
45 |
{
|
|
46 |
d->tokenStream->close();
|
|
47 |
}
|
|
48 |
|
|
49 |
bool QCLuceneTokenizer::next(QCLuceneToken &token)
|
|
50 |
{
|
|
51 |
return d->tokenStream->next(token.d->token);
|
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
QCLuceneStandardTokenizer::QCLuceneStandardTokenizer(const QCLuceneReader &reader)
|
|
56 |
: QCLuceneTokenizer(reader)
|
|
57 |
{
|
|
58 |
d->tokenStream =
|
|
59 |
new lucene::analysis::standard::StandardTokenizer(reader.d->reader);
|
|
60 |
}
|
|
61 |
|
|
62 |
QCLuceneStandardTokenizer::~QCLuceneStandardTokenizer()
|
|
63 |
{
|
|
64 |
// nothing todo
|
|
65 |
}
|
|
66 |
|
|
67 |
bool QCLuceneStandardTokenizer::readApostrophe(const QString &string,
|
|
68 |
QCLuceneToken &token)
|
|
69 |
{
|
|
70 |
lucene::analysis::standard::StandardTokenizer *stdTokenizer =
|
|
71 |
static_cast<lucene::analysis::standard::StandardTokenizer*> (d->tokenStream);
|
|
72 |
|
|
73 |
if (stdTokenizer == 0)
|
|
74 |
return false;
|
|
75 |
|
|
76 |
TCHAR* value = QStringToTChar(string);
|
|
77 |
lucene::util::StringBuffer buffer(value);
|
|
78 |
bool retValue = stdTokenizer->ReadApostrophe(&buffer, token.d->token);
|
|
79 |
delete [] value;
|
|
80 |
|
|
81 |
return retValue;
|
|
82 |
}
|
|
83 |
|
|
84 |
bool QCLuceneStandardTokenizer::readAt(const QString &string, QCLuceneToken &token)
|
|
85 |
{
|
|
86 |
lucene::analysis::standard::StandardTokenizer *stdTokenizer =
|
|
87 |
static_cast<lucene::analysis::standard::StandardTokenizer*> (d->tokenStream);
|
|
88 |
|
|
89 |
if (stdTokenizer == 0)
|
|
90 |
return false;
|
|
91 |
|
|
92 |
TCHAR* value = QStringToTChar(string);
|
|
93 |
lucene::util::StringBuffer buffer(value);
|
|
94 |
bool retValue = stdTokenizer->ReadAt(&buffer, token.d->token);
|
|
95 |
delete [] value;
|
|
96 |
|
|
97 |
return retValue;
|
|
98 |
}
|
|
99 |
|
|
100 |
bool QCLuceneStandardTokenizer::readCompany(const QString &string,
|
|
101 |
QCLuceneToken &token)
|
|
102 |
{
|
|
103 |
lucene::analysis::standard::StandardTokenizer *stdTokenizer =
|
|
104 |
static_cast<lucene::analysis::standard::StandardTokenizer*> (d->tokenStream);
|
|
105 |
|
|
106 |
if (stdTokenizer == 0)
|
|
107 |
return false;
|
|
108 |
|
|
109 |
TCHAR* value = QStringToTChar(string);
|
|
110 |
lucene::util::StringBuffer buffer(value);
|
|
111 |
bool retValue = stdTokenizer->ReadCompany(&buffer, token.d->token);
|
|
112 |
delete [] value;
|
|
113 |
|
|
114 |
return retValue;
|
|
115 |
}
|
|
116 |
|
|
117 |
QT_END_NAMESPACE
|