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 "qqueryparser_p.h"
|
---|
19 | #include "qquery_p.h"
|
---|
20 | #include "qclucene_global_p.h"
|
---|
21 |
|
---|
22 | #include <CLucene.h>
|
---|
23 | #include <CLucene/queryParser/QueryParser.h>
|
---|
24 |
|
---|
25 | QT_BEGIN_NAMESPACE
|
---|
26 |
|
---|
27 | QCLuceneQueryParserPrivate::QCLuceneQueryParserPrivate()
|
---|
28 | : QSharedData()
|
---|
29 | {
|
---|
30 | queryParser = 0;
|
---|
31 | deleteCLuceneQueryParser = true;
|
---|
32 | }
|
---|
33 |
|
---|
34 | QCLuceneQueryParserPrivate::QCLuceneQueryParserPrivate(const QCLuceneQueryParserPrivate &other)
|
---|
35 | : QSharedData()
|
---|
36 | {
|
---|
37 | queryParser = _CL_POINTER(other.queryParser);
|
---|
38 | deleteCLuceneQueryParser = other.deleteCLuceneQueryParser;
|
---|
39 | }
|
---|
40 |
|
---|
41 | QCLuceneQueryParserPrivate::~QCLuceneQueryParserPrivate()
|
---|
42 | {
|
---|
43 | if (deleteCLuceneQueryParser)
|
---|
44 | _CLDECDELETE(queryParser);
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | QCLuceneQueryParser::QCLuceneQueryParser(const QString &field,
|
---|
49 | QCLuceneAnalyzer &analyzer)
|
---|
50 | : d(new QCLuceneQueryParserPrivate())
|
---|
51 | , field(field)
|
---|
52 | , analyzer(analyzer)
|
---|
53 | {
|
---|
54 | TCHAR *fieldName = QStringToTChar(field);
|
---|
55 |
|
---|
56 | d->queryParser = new lucene::queryParser::QueryParser(fieldName,
|
---|
57 | analyzer.d->analyzer);
|
---|
58 |
|
---|
59 | delete [] fieldName;
|
---|
60 | }
|
---|
61 |
|
---|
62 | QCLuceneQueryParser::~QCLuceneQueryParser()
|
---|
63 | {
|
---|
64 | // nothing todo
|
---|
65 | }
|
---|
66 |
|
---|
67 | QCLuceneQuery* QCLuceneQueryParser::parse(const QString &query)
|
---|
68 | {
|
---|
69 | TCHAR *string = QStringToTChar(query);
|
---|
70 |
|
---|
71 | QCLuceneQuery *retValue = 0;
|
---|
72 | lucene::search::Query* q = d->queryParser->parse(string);
|
---|
73 | if (q) {
|
---|
74 | retValue = new QCLuceneQuery();
|
---|
75 | retValue->d->query = q;
|
---|
76 | }
|
---|
77 |
|
---|
78 | delete [] string;
|
---|
79 | return retValue;
|
---|
80 | }
|
---|
81 |
|
---|
82 | QCLuceneQuery* QCLuceneQueryParser::parse(QCLuceneReader &reader)
|
---|
83 | {
|
---|
84 | QCLuceneQuery *retValue = 0;
|
---|
85 | lucene::search::Query* q = d->queryParser->parse(reader.d->reader);
|
---|
86 | if (q) {
|
---|
87 | retValue = new QCLuceneQuery();
|
---|
88 | retValue->d->query = q;
|
---|
89 | }
|
---|
90 |
|
---|
91 | return retValue;
|
---|
92 | }
|
---|
93 |
|
---|
94 | QCLuceneQuery* QCLuceneQueryParser::parse(const QString &query, const QString &field,
|
---|
95 | QCLuceneAnalyzer &analyzer)
|
---|
96 | {
|
---|
97 | QCLuceneQueryParser parser(field, analyzer);
|
---|
98 | return parser.parse(query);
|
---|
99 | }
|
---|
100 |
|
---|
101 | QCLuceneAnalyzer QCLuceneQueryParser::getAnalyzer()
|
---|
102 | {
|
---|
103 | return analyzer;
|
---|
104 | }
|
---|
105 |
|
---|
106 | QString QCLuceneQueryParser::getField()
|
---|
107 | {
|
---|
108 | return field;
|
---|
|
---|