1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
---|
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 "qterm_p.h"
|
---|
12 | #include "qclucene_global_p.h"
|
---|
13 |
|
---|
14 | #include <CLucene.h>
|
---|
15 | #include <CLucene/index/IndexReader.h>
|
---|
16 |
|
---|
17 | QT_BEGIN_NAMESPACE
|
---|
18 |
|
---|
19 | QCLuceneTermPrivate::QCLuceneTermPrivate()
|
---|
20 | : QSharedData()
|
---|
21 | {
|
---|
22 | term = 0;
|
---|
23 | deleteCLuceneTerm = true;
|
---|
24 | }
|
---|
25 |
|
---|
26 | QCLuceneTermPrivate::QCLuceneTermPrivate(const QCLuceneTermPrivate &other)
|
---|
27 | : QSharedData()
|
---|
28 | {
|
---|
29 | term = _CL_POINTER(other.term);
|
---|
30 | }
|
---|
31 |
|
---|
32 | QCLuceneTermPrivate::~QCLuceneTermPrivate()
|
---|
33 | {
|
---|
34 | if (deleteCLuceneTerm)
|
---|
35 | _CLDECDELETE(term);
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | QCLuceneTerm::QCLuceneTerm()
|
---|
40 | : d(new QCLuceneTermPrivate())
|
---|
41 | {
|
---|
42 | d->term = new lucene::index::Term();
|
---|
43 | }
|
---|
44 |
|
---|
45 | QCLuceneTerm::QCLuceneTerm(const QString &field, const QString &text)
|
---|
46 | : d(new QCLuceneTermPrivate())
|
---|
47 | {
|
---|
48 | TCHAR *fieldName = QStringToTChar(field);
|
---|
49 | TCHAR *termText = QStringToTChar(text);
|
---|
50 |
|
---|
51 | d->term = new lucene::index::Term(fieldName, termText);
|
---|
52 |
|
---|
53 | delete [] fieldName;
|
---|
54 | delete [] termText;
|
---|
55 | }
|
---|
56 |
|
---|
57 | QCLuceneTerm::QCLuceneTerm(const QCLuceneTerm &fieldTerm, const QString &text)
|
---|
58 | : d(new QCLuceneTermPrivate())
|
---|
59 | {
|
---|
60 | TCHAR *termText = QStringToTChar(text);
|
---|
61 | d->term = new lucene::index::Term(fieldTerm.d->term, termText);
|
---|
62 | delete [] termText;
|
---|
63 | }
|
---|
64 |
|
---|
65 | QCLuceneTerm::~QCLuceneTerm()
|
---|
66 | {
|
---|
67 | // nothing todo
|
---|
68 | }
|
---|
69 |
|
---|
70 | QString QCLuceneTerm::field() const
|
---|
71 | {
|
---|
72 | return TCharToQString(d->term->field());
|
---|
73 | }
|
---|
74 |
|
---|
75 | QString QCLuceneTerm::text() const
|
---|
76 | {
|
---|
77 | return TCharToQString(d->term->text());
|
---|
78 | }
|
---|
79 |
|
---|
80 | void QCLuceneTerm::set(const QString &field, const QString &text)
|
---|
81 | {
|
---|
82 | set(field, text, true);
|
---|
83 | }
|
---|
84 |
|
---|
85 | void QCLuceneTerm::set(const QCLuceneTerm &fieldTerm, const QString &text)
|
---|
86 | {
|
---|
87 | set(fieldTerm.field(), text, false);
|
---|
88 | }
|
---|
89 |
|
---|
90 | void QCLuceneTerm::set(const QString &field, const QString &text, bool internField)
|
---|
91 | {
|
---|
92 | TCHAR *fieldName = QStringToTChar(field);
|
---|
93 | TCHAR *termText = QStringToTChar(text);
|
---|
94 |
|
---|
95 | d->term->set(fieldName, termText, internField);
|
---|
96 |
|
---|
97 | delete [] fieldName;
|
---|
98 | delete [] termText;
|
---|
99 | }
|
---|
100 |
|
---|
101 | bool QCLuceneTerm::equals(const QCLuceneTerm &other) const
|
---|
102 | {
|
---|
103 | return d->term->equals(other.d->term);
|
---|
104 | }
|
---|
105 |
|
---|
106 | qint32 QCLuceneTerm::compareTo(const QCLuceneTerm &other) const
|
---|
107 | {
|
---|
108 | return quint32(d->term->compareTo(other.d->term));
|
---|
109 | }
|
---|
110 |
|
---|
111 | QString QCLuceneTerm::toString() const
|
---|
112 | {
|
---|
113 | return TCharToQString(d->term->toString());
|
---|
114 | }
|
---|
115 |
|
---|
116 | quint32 QCLuceneTerm::hashCode() const
|
---|
117 | {
|
---|
118 | return quint32(d->term->hashCode());
|
---|
119 | }
|
---|
120 |
|
---|
121 | quint32 QCLuceneTerm::textLength() const
|
---|
122 | {
|
---|
123 | return quint32(d->term->textLength());
|
---|
124 | }
|
---|
125 |
|
---|
126 | QT_END_NAMESPACE
|
---|