summaryrefslogtreecommitdiffstats
path: root/tools/assistant
diff options
context:
space:
mode:
authorck <qt-info@nokia.com>2009-11-03 09:55:44 (GMT)
committerck <qt-info@nokia.com>2009-11-03 09:55:44 (GMT)
commit187be1cdbac3ec9dd2b748f25a5d6198c7a7ed87 (patch)
tree6291de743e2182e2725ae52e8584e88e9a891a21 /tools/assistant
parente535343ee9502d48cdc282a6c91da9655d8205c6 (diff)
downloadQt-187be1cdbac3ec9dd2b748f25a5d6198c7a7ed87.zip
Qt-187be1cdbac3ec9dd2b748f25a5d6198c7a7ed87.tar.gz
Qt-187be1cdbac3ec9dd2b748f25a5d6198c7a7ed87.tar.bz2
Introduce symbolic constants for CLucene field names.
Reviewed-by: kh1
Diffstat (limited to 'tools/assistant')
-rw-r--r--tools/assistant/lib/lib.pro7
-rw-r--r--tools/assistant/lib/qclucenefieldnames.cpp59
-rw-r--r--tools/assistant/lib/qclucenefieldnames_p.h65
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_clucene.cpp43
-rw-r--r--tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp20
5 files changed, 158 insertions, 36 deletions
diff --git a/tools/assistant/lib/lib.pro b/tools/assistant/lib/lib.pro
index 011dec2..322320a 100644
--- a/tools/assistant/lib/lib.pro
+++ b/tools/assistant/lib/lib.pro
@@ -23,7 +23,6 @@ unix:QMAKE_PKGCONFIG_REQUIRES += QtNetwork \
QtSql \
QtXml
LIBS_PRIVATE += -l$$qclucene
-
RESOURCES += helpsystem.qrc
SOURCES += qhelpenginecore.cpp \
qhelpengine.cpp \
@@ -40,7 +39,8 @@ SOURCES += qhelpenginecore.cpp \
qhelpsearchindex_default.cpp \
qhelpsearchindexwriter_default.cpp \
qhelpsearchindexreader_default.cpp \
- qhelpsearchindexreader.cpp
+ qhelpsearchindexreader.cpp \
+ qclucenefieldnames.cpp
# access to clucene
SOURCES += qhelpsearchindexwriter_clucene.cpp \
@@ -62,7 +62,8 @@ HEADERS += qhelpenginecore.h \
qhelpsearchindex_default_p.h \
qhelpsearchindexwriter_default_p.h \
qhelpsearchindexreader_default_p.h \
- qhelpsearchindexreader_p.h
+ qhelpsearchindexreader_p.h \
+ qclucenefieldnames_p.h
# access to clucene
HEADERS += qhelpsearchindexwriter_clucene_p.h \
diff --git a/tools/assistant/lib/qclucenefieldnames.cpp b/tools/assistant/lib/qclucenefieldnames.cpp
new file mode 100644
index 0000000..df01d1a
--- /dev/null
+++ b/tools/assistant/lib/qclucenefieldnames.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Assistant.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qclucenefieldnames_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace qt {
+namespace fulltextsearch {
+namespace clucene {
+const QString AttributeField(QLatin1String("attribute"));
+const QString ContentField(QLatin1String("content"));
+const QString NamespaceField(QLatin1String("namespace"));
+const QString PathField(QLatin1String("path"));
+const QString TitleField(QLatin1String("title"));
+const QString TitleTokenizedField(QLatin1String("titleTokenized"));
+} // namespace clucene
+} // namespace fulltextsearch
+} // namespace qt
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/lib/qclucenefieldnames_p.h b/tools/assistant/lib/qclucenefieldnames_p.h
new file mode 100644
index 0000000..57b85f8
--- /dev/null
+++ b/tools/assistant/lib/qclucenefieldnames_p.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Assistant.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCLUCENEFIELDNAMES_P_H
+#define QCLUCENEFIELDNAMES_P_H
+
+#include <QtCore/QtGlobal>
+#include <QtCore/QString>
+
+QT_BEGIN_NAMESPACE
+
+namespace qt {
+namespace fulltextsearch {
+namespace clucene {
+ extern const QString AttributeField;
+ extern const QString ContentField;
+ extern const QString NamespaceField;
+ extern const QString PathField;
+ extern const QString TitleField;
+ extern const QString TitleTokenizedField;
+} // namespace clucene
+} // namespace fulltextsearch
+} // namespace qt
+
+QT_END_NAMESPACE
+
+#endif // QCLUCENEFIELDNAMES_P_H
diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
index 954f41f..0d46d8e 100644
--- a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
+++ b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
@@ -39,6 +39,7 @@
**
****************************************************************************/
+#include "qclucenefieldnames_p.h"
#include "qhelpenginecore.h"
#include "fulltextsearch/qsearchable_p.h"
#include "fulltextsearch/qqueryparser_p.h"
@@ -118,7 +119,7 @@ void QHelpSearchIndexReaderClucene::run()
const QStringList attribList = engine.filterAttributes(engine.currentFilter());
if (!attribList.isEmpty()) {
QCLuceneQuery* query = QCLuceneQueryParser::parse(QLatin1String("+")
- + attribList.join(QLatin1String(" +")), QLatin1String("attribute"), analyzer);
+ + attribList.join(QLatin1String(" +")), AttributeField, analyzer);
if (!query) {
emit searchingFinished(0);
@@ -136,7 +137,7 @@ void QHelpSearchIndexReaderClucene::run()
if (buildTryHarderQuery(tryHarderQuery, queryList, analyzer)) {
if (!attribList.isEmpty()) {
QCLuceneQuery* query = QCLuceneQueryParser::parse(QLatin1String("+")
- + attribList.join(QLatin1String(" +")), QLatin1String("attribute"),
+ + attribList.join(QLatin1String(" +")), AttributeField,
analyzer);
tryHarderQuery.add(query, true, true, false);
}
@@ -151,11 +152,11 @@ void QHelpSearchIndexReaderClucene::run()
for (qint32 i = 0; i < hits.length(); i++) {
document = hits.document(i);
- const QString path = document.get(QLatin1String("path"));
+ const QString path = document.get(PathField);
if (!pathSet.contains(path) && namespaceList.contains(
- document.get(QLatin1String("namespace")), Qt::CaseInsensitive)) {
+ document.get(NamespaceField), Qt::CaseInsensitive)) {
pathSet.insert(path);
- hitList.append(qMakePair(path, document.get(QLatin1String("title"))));
+ hitList.append(qMakePair(path, document.get(TitleField)));
}
document.clear();
@@ -188,11 +189,8 @@ void QHelpSearchIndexReaderClucene::run()
bool QHelpSearchIndexReaderClucene::defaultQuery(const QString &term, QCLuceneBooleanQuery &booleanQuery,
QCLuceneStandardAnalyzer &analyzer)
{
- const QLatin1String c("content");
- const QLatin1String t("titleTokenized");
-
- QCLuceneQuery *query = QCLuceneQueryParser::parse(term, c, analyzer);
- QCLuceneQuery *query2 = QCLuceneQueryParser::parse(term, t, analyzer);
+ QCLuceneQuery *query = QCLuceneQueryParser::parse(term, ContentField, analyzer);
+ QCLuceneQuery *query2 = QCLuceneQueryParser::parse(term, TitleTokenizedField, analyzer);
if (query && query2) {
booleanQuery.add(query, true, false, false);
booleanQuery.add(query2, true, false, false);
@@ -224,9 +222,9 @@ bool QHelpSearchIndexReaderClucene::buildQuery(QCLuceneBooleanQuery &booleanQuer
continue;
QCLuceneQuery *query = new QCLuceneTermQuery(QCLuceneTerm(
- QLatin1String("content"), term.toLower()));
+ ContentField, term.toLower()));
QCLuceneQuery *query2 = new QCLuceneTermQuery(QCLuceneTerm(
- QLatin1String("titleTokenized"), term.toLower()));
+ TitleTokenizedField, term.toLower()));
if (query && query2) {
booleanQuery.add(query, true, false, true);
@@ -245,14 +243,14 @@ bool QHelpSearchIndexReaderClucene::buildQuery(QCLuceneBooleanQuery &booleanQuer
QStringList stopWords = QCLuceneStopAnalyzer().englishStopWords();
foreach (const QString &term, termList) {
if (!stopWords.contains(term, Qt::CaseInsensitive))
- q->addTerm(QCLuceneTerm(QLatin1String("content"), term.toLower()));
+ q->addTerm(QCLuceneTerm(ContentField, term.toLower()));
}
booleanQuery.add(q, true, true, false);
} else {
QCLuceneQuery *query = new QCLuceneTermQuery(QCLuceneTerm(
- QLatin1String("content"), term.toLower()));
+ ContentField, term.toLower()));
QCLuceneQuery *query2 = new QCLuceneTermQuery(QCLuceneTerm(
- QLatin1String("titleTokenized"), term.toLower()));
+ TitleTokenizedField, term.toLower()));
if (query && query2) {
booleanQuery.add(query, true, true, false);
@@ -270,7 +268,7 @@ bool QHelpSearchIndexReaderClucene::buildQuery(QCLuceneBooleanQuery &booleanQuer
continue;
QCLuceneQuery *query = new QCLuceneTermQuery(QCLuceneTerm(
- QLatin1String("content"), term.toLower()));
+ ContentField, term.toLower()));
if (query) {
booleanQuery.add(query, true, true, false);
@@ -283,7 +281,7 @@ bool QHelpSearchIndexReaderClucene::buildQuery(QCLuceneBooleanQuery &booleanQuer
case QHelpSearchQuery::DEFAULT: {
foreach (const QString &term, query.wordList) {
QCLuceneQuery *query = QCLuceneQueryParser::parse(term.toLower(),
- QLatin1String("content"), analyzer);
+ ContentField, analyzer);
if (query)
booleanQuery.add(query, true, true, false);
@@ -312,7 +310,7 @@ bool QHelpSearchIndexReaderClucene::buildTryHarderQuery(QCLuceneBooleanQuery &bo
case QHelpSearchQuery::DEFAULT: {
foreach (const QString &term, query.wordList) {
QCLuceneQuery *query = QCLuceneQueryParser::parse(term.toLower(),
- QLatin1String("content"), analyzer);
+ ContentField, analyzer);
if (query) {
retVal = true;
@@ -336,21 +334,22 @@ void QHelpSearchIndexReaderClucene::boostSearchHits(const QHelpEngineCore &engin
QCLuceneStandardAnalyzer analyzer;
QCLuceneQuery *parsedQuery = QCLuceneQueryParser::parse(
- joinedQuery, QLatin1String("content"), analyzer);
+ joinedQuery, ContentField, analyzer);
if (parsedQuery) {
joinedQuery = parsedQuery->toString();
delete parsedQuery;
}
- int length = QString(QLatin1String("content:")).length();
- int index = joinedQuery.indexOf(QLatin1String("content:"));
+ const QString contentString(ContentField + QLatin1String(":"));
+ int length = contentString.length();
+ int index = joinedQuery.indexOf(contentString);
QString term;
int nextIndex = 0;
QStringList searchTerms;
while (index != -1) {
- nextIndex = joinedQuery.indexOf(QLatin1String("content:"), index + 1);
+ nextIndex = joinedQuery.indexOf(contentString, index + 1);
term = joinedQuery.mid(index + length, nextIndex - (length + index)).simplified();
if (term.startsWith(QLatin1String("\""))
&& term.endsWith(QLatin1String("\""))) {
diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
index 284cbd3..80ee933 100644
--- a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
+++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
@@ -39,6 +39,7 @@
**
****************************************************************************/
+#include "qclucenefieldnames_p.h"
#include "qhelpenginecore.h"
#include "qhelp_global.h"
#include "fulltextsearch/qhits_p.h"
@@ -407,17 +408,17 @@ public:
QString parsedTitle = QHelpGlobal::documentTitle(data);
if(!parsedData.isEmpty()) {
- document->add(new QCLuceneField(QLatin1String("content"),
+ document->add(new QCLuceneField(ContentField,
parsedData,QCLuceneField::INDEX_TOKENIZED));
- document->add(new QCLuceneField(QLatin1String("path"), fileName,
+ document->add(new QCLuceneField(PathField, fileName,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
- document->add(new QCLuceneField(QLatin1String("title"), parsedTitle,
+ document->add(new QCLuceneField(TitleField, parsedTitle,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
- document->add(new QCLuceneField(QLatin1String("titleTokenized"), parsedTitle,
+ document->add(new QCLuceneField(TitleTokenizedField, parsedTitle,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
- document->add(new QCLuceneField(QLatin1String("namespace"), namespaceName,
+ document->add(new QCLuceneField(NamespaceField, namespaceName,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
- document->add(new QCLuceneField(QLatin1String("attribute"), attributes,
+ document->add(new QCLuceneField(AttributeField, attributes,
QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
return true;
}
@@ -712,9 +713,7 @@ void QHelpSearchIndexWriter::run()
if (indexMap.contains(namespaceName)) {
// make sure we really have content indexed for namespace
- // NOTE: Extra variable just for GCC 3.3.5
- QLatin1String key("namespace");
- QCLuceneTermQuery query(QCLuceneTerm(key, namespaceName));
+ QCLuceneTermQuery query(QCLuceneTerm(NamespaceField, namespaceName));
QCLuceneIndexSearcher indexSearcher(indexPath);
QCLuceneHits hits = indexSearcher.search(query);
if (hits.length() <= 0)
@@ -857,8 +856,7 @@ void QHelpSearchIndexWriter::removeDocuments(const QString &indexPath,
return;
QCLuceneIndexReader reader = QCLuceneIndexReader::open(indexPath);
- reader.deleteDocuments(QCLuceneTerm(QLatin1String("namespace"),
- namespaceName));
+ reader.deleteDocuments(QCLuceneTerm(NamespaceField, namespaceName));
reader.close();
}