summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-07-09 13:41:34 +0100
committerMichael Stahl <mstahl@redhat.com>2012-07-25 15:13:27 +0200
commite906bcc0c976a8565d05fbf6ef5cdda01642e611 (patch)
tree4c4eca0adb036318f0c67141daafe8e155ba9b8b
parentb1ca38aa592fa8b5adebb8832681babbf95e1eff (diff)
Resolves: fdo#51572 catch CLuceneError throws and extract the error message
I can't reproduce fdo#51572, but catching the exception in HelpIndexer::indexDocuments should resolve it anyway and make it non-fatal. Collect the error message for retrieval via HelpIndexer::getErrorMessage Change-Id: Id557b9f5ff968c398f76969591f5ee765e56aa5a (cherry picked from commit 4c912d3d8bd1ae01131e90fb4a2d8371a53ee888) Signed-off-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r--l10ntools/source/help/HelpIndexer.cxx77
-rw-r--r--l10ntools/source/help/HelpIndexer_main.cxx12
2 files changed, 44 insertions, 45 deletions
diff --git a/l10ntools/source/help/HelpIndexer.cxx b/l10ntools/source/help/HelpIndexer.cxx
index 3c595b4b3bd6..72a0d045229e 100644
--- a/l10ntools/source/help/HelpIndexer.cxx
+++ b/l10ntools/source/help/HelpIndexer.cxx
@@ -34,7 +34,7 @@
#include <rtl/ustrbuf.hxx>
#include <osl/file.hxx>
#include <osl/thread.h>
-
+#include <boost/scoped_ptr.hpp>
#include <algorithm>
#include "LuceneHelper.hxx"
@@ -51,44 +51,51 @@ HelpIndexer::HelpIndexer(rtl::OUString const &lang, rtl::OUString const &module,
d_contentDir = srcDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/content"));
}
-bool HelpIndexer::indexDocuments() {
- if (!scanForFiles()) {
+bool HelpIndexer::indexDocuments()
+{
+ if (!scanForFiles())
return false;
- }
- rtl::OUString sLang = d_lang.getToken(0, '-');
- bool bUseCJK = sLang == "ja" || sLang == "ko" || sLang == "zh";
-
- // Construct the analyzer appropriate for the given language
- lucene::analysis::Analyzer *analyzer;
- if (bUseCJK)
- analyzer = new lucene::analysis::LanguageBasedAnalyzer(L"cjk");
- else
- analyzer = new lucene::analysis::standard::StandardAnalyzer();
-
- rtl::OUString ustrSystemPath;
- osl::File::getSystemPathFromFileURL(d_indexDir, ustrSystemPath);
-
- rtl::OString indexDirStr = rtl::OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding());
- lucene::index::IndexWriter writer(indexDirStr.getStr(), analyzer, true);
- //Double limit of tokens allowed, otherwise we'll get a too-many-tokens
- //exception for ja help. Could alternative ignore the exception and get
- //truncated results as per java-Lucene apparently
- writer.setMaxFieldLength(lucene::index::IndexWriter::DEFAULT_MAX_FIELD_LENGTH*2);
-
- // Index the identified help files
- Document doc;
- for (std::set<rtl::OUString>::iterator i = d_files.begin(); i != d_files.end(); ++i) {
- helpDocument(*i, &doc);
- writer.addDocument(&doc);
- doc.clear();
- }
- writer.optimize();
+ try
+ {
+ rtl::OUString sLang = d_lang.getToken(0, '-');
+ bool bUseCJK = sLang == "ja" || sLang == "ko" || sLang == "zh";
+
+ // Construct the analyzer appropriate for the given language
+ boost::scoped_ptr<lucene::analysis::Analyzer> analyzer;
+ if (bUseCJK)
+ analyzer.reset(new lucene::analysis::LanguageBasedAnalyzer(L"cjk"));
+ else
+ analyzer.reset(new lucene::analysis::standard::StandardAnalyzer());
- // Optimize the index
- writer.optimize();
+ rtl::OUString ustrSystemPath;
+ osl::File::getSystemPathFromFileURL(d_indexDir, ustrSystemPath);
+
+ rtl::OString indexDirStr = rtl::OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding());
+ lucene::index::IndexWriter writer(indexDirStr.getStr(), analyzer.get(), true);
+ //Double limit of tokens allowed, otherwise we'll get a too-many-tokens
+ //exception for ja help. Could alternative ignore the exception and get
+ //truncated results as per java-Lucene apparently
+ writer.setMaxFieldLength(lucene::index::IndexWriter::DEFAULT_MAX_FIELD_LENGTH*2);
+
+ // Index the identified help files
+ Document doc;
+ for (std::set<rtl::OUString>::iterator i = d_files.begin(); i != d_files.end(); ++i) {
+ helpDocument(*i, &doc);
+ writer.addDocument(&doc);
+ doc.clear();
+ }
+ writer.optimize();
+
+ // Optimize the index
+ writer.optimize();
+ }
+ catch (CLuceneError &e)
+ {
+ d_error = rtl::OUString::createFromAscii(e.what());
+ return false;
+ }
- delete analyzer;
return true;
}
diff --git a/l10ntools/source/help/HelpIndexer_main.cxx b/l10ntools/source/help/HelpIndexer_main.cxx
index bf42a4cdd84d..48e0f3eecdda 100644
--- a/l10ntools/source/help/HelpIndexer_main.cxx
+++ b/l10ntools/source/help/HelpIndexer_main.cxx
@@ -99,16 +99,8 @@ int main(int argc, char **argv) {
rtl::OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()),
sDir, sDir);
- try
- {
- if (!indexer.indexDocuments()) {
- std::cerr << rtl::OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl;
- return 2;
- }
- }
- catch (CLuceneError &e)
- {
- std::cerr << e.what() << std::endl;
+ if (!indexer.indexDocuments()) {
+ std::cerr << rtl::OUStringToOString(indexer.getErrorMessage(), osl_getThreadTextEncoding()).getStr() << std::endl;
return 2;
}
return 0;