1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QCLucene library and is distributable under
|
---|
7 | ** the terms of the LGPL license as specified in the license.txt file.
|
---|
8 | **
|
---|
9 | ****************************************************************************/
|
---|
10 |
|
---|
11 | #include "qanalyzer_p.h"
|
---|
12 | #include "qclucene_global_p.h"
|
---|
13 |
|
---|
14 | #include <CLucene.h>
|
---|
15 | #include <CLucene/analysis/AnalysisHeader.h>
|
---|
16 |
|
---|
17 | QT_BEGIN_NAMESPACE
|
---|
18 |
|
---|
19 | QCLuceneAnalyzerPrivate::QCLuceneAnalyzerPrivate()
|
---|
20 | : QSharedData()
|
---|
21 | {
|
---|
22 | analyzer = 0;
|
---|
23 | deleteCLuceneAnalyzer = true;
|
---|
24 | }
|
---|
25 |
|
---|
26 | QCLuceneAnalyzerPrivate::QCLuceneAnalyzerPrivate(const QCLuceneAnalyzerPrivate &other)
|
---|
27 | : QSharedData()
|
---|
28 | {
|
---|
29 | analyzer = _CL_POINTER(other.analyzer);
|
---|
30 | }
|
---|
31 |
|
---|
32 | QCLuceneAnalyzerPrivate::~QCLuceneAnalyzerPrivate()
|
---|
33 | {
|
---|
34 | if (deleteCLuceneAnalyzer)
|
---|
35 | _CLDECDELETE(analyzer);
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | QCLuceneAnalyzer::QCLuceneAnalyzer()
|
---|
40 | : d(new QCLuceneAnalyzerPrivate())
|
---|
41 | {
|
---|
42 | //nothing todo, private
|
---|
43 | }
|
---|
44 |
|
---|
45 | QCLuceneAnalyzer::~QCLuceneAnalyzer()
|
---|
46 | {
|
---|
47 | // nothing todo
|
---|
48 | }
|
---|
49 |
|
---|
50 | qint32 QCLuceneAnalyzer::positionIncrementGap(const QString &fieldName) const
|
---|
51 | {
|
---|
52 | Q_UNUSED(fieldName);
|
---|
53 | return 0;
|
---|
54 | }
|
---|
55 |
|
---|
56 | QCLuceneTokenStream QCLuceneAnalyzer::tokenStream(const QString &fieldName,
|
---|
57 | const QCLuceneReader &reader) const
|
---|
58 | {
|
---|
59 | TCHAR *fName = QStringToTChar(fieldName);
|
---|
60 | QCLuceneTokenStream tokenStream;
|
---|
61 | tokenStream.d->tokenStream = d->analyzer->tokenStream(fName, reader.d->reader);
|
---|
62 | delete [] fName;
|
---|
63 |
|
---|
64 | return tokenStream;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | QCLuceneStandardAnalyzer::QCLuceneStandardAnalyzer()
|
---|
69 | : QCLuceneAnalyzer()
|
---|
70 | {
|
---|
71 | d->analyzer = new lucene::analysis::standard::StandardAnalyzer();
|
---|
72 | }
|
---|
73 |
|
---|
74 | QCLuceneStandardAnalyzer::~QCLuceneStandardAnalyzer()
|
---|
75 | {
|
---|
76 | // nothing todo
|
---|
77 | }
|
---|
78 |
|
---|
79 | QCLuceneStandardAnalyzer::QCLuceneStandardAnalyzer(const QStringList &stopWords)
|
---|
80 | {
|
---|
81 | const TCHAR **tArray = new const TCHAR*[stopWords.count() +1];
|
---|
82 |
|
---|
83 | for(int i = 0; i < stopWords.count(); ++i) {
|
---|
84 | TCHAR *stopWord = QStringToTChar(stopWords.at(i));
|
---|
85 | tArray[i] = STRDUP_TtoT(stopWord);
|
---|
86 | delete [] stopWord;
|
---|
87 | }
|
---|
88 | tArray[stopWords.count()] = 0;
|
---|
89 |
|
---|
90 | d->analyzer = new lucene::analysis::standard::StandardAnalyzer(tArray);
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | QCLuceneWhitespaceAnalyzer::QCLuceneWhitespaceAnalyzer()
|
---|
95 | : QCLuceneAnalyzer()
|
---|
96 | {
|
---|
97 | d->analyzer = new lucene::analysis::WhitespaceAnalyzer();
|
---|
98 | }
|
---|
99 |
|
---|
100 | QCLuceneWhitespaceAnalyzer::~QCLuceneWhitespaceAnalyzer()
|
---|
101 | {
|
---|
102 | // nothing todo
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | QCLuceneSimpleAnalyzer::QCLuceneSimpleAnalyzer()
|
---|
107 | : QCLuceneAnalyzer()
|
---|
108 | {
|
---|
109 | d->analyzer = new lucene::analysis::SimpleAnalyzer();
|
---|
110 | }
|
---|
111 |
|
---|
112 | QCLuceneSimpleAnalyzer::~QCLuceneSimpleAnalyzer()
|
---|
113 | {
|
---|
114 | // nothing todo
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | QCLuceneStopAnalyzer::QCLuceneStopAnalyzer()
|
---|
|
---|