/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifdefined _WIN32 namespace
{ template <class Constructor> auto TryWithUnicodePathWorkaround(const OUString& ustrPath, const Constructor& constructor)
{ const rtl_TextEncoding eThreadEncoding = osl_getThreadTextEncoding();
OString sPath = OUStringToOString(ustrPath, eThreadEncoding); try
{ // First try path in thread encoding (ACP in case of Windows). return constructor(sPath);
} catch (const CLuceneError&)
{ // Maybe the path contains characters not representable in ACP. There's no API in lucene // that takes Unicode strings (they take 8-bit strings, and pass them to CRT library // functions without conversion).
// For a workaround, try short name, which should only contain ASCII characters. Would // not help (i.e., would return original long name) if short (8.3) file name creation is // disabled in OS or volume settings. wchar_t buf[EXTENDED_MAX_PATH]; if (GetShortPathNameW(o3tl::toW(ustrPath.getStr()), buf, std::size(buf)) == 0) throw;
sPath = OUStringToOString(o3tl::toU(buf), eThreadEncoding); return constructor(sPath);
}
}
} #endif
bool HelpIndexer::indexDocuments()
{ if (!scanForFiles()) returnfalse;
// Construct the analyzer appropriate for the given language
std::unique_ptr<lucene::analysis::Analyzer> analyzer; if (bUseCJK)
analyzer.reset(new lucene::analysis::LanguageBasedAnalyzer(L"cjk")); else
analyzer.reset(new lucene::analysis::standard::StandardAnalyzer());
#ifdefined _WIN32 // Make sure the path exists, or GetShortPathNameW (if attempted) will fail.
osl::Directory::createPath(d_indexDir); auto writer = TryWithUnicodePathWorkaround(ustrSystemPath, [&analyzer](const OString& s) { return std::make_unique<lucene::index::IndexWriter>(s.getStr(), analyzer.get(), true);
}); #else
OString indexDirStr = OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding()); auto writer = std::make_unique<lucene::index::IndexWriter>(indexDirStr.getStr(),
analyzer.get(), true); #endif
#ifndef SYSTEM_CLUCENE // avoid random values in index file, making help indices reproducible
writer->setSegmentInfoStartVersion(0); #endif
//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 (autoconst& elem : d_files)
{
helpDocument(elem, &doc);
writer->addDocument(&doc);
doc.clear();
}
// Optimize the index
writer->optimize();
} catch (CLuceneError &e)
{
d_error = o3tl::runtimeToOUString(e.what()); returnfalse;
}
returntrue;
}
bool HelpIndexer::scanForFiles() { if (!scanForFiles(d_contentDir)) { returnfalse;
} if (!scanForFiles(d_captionDir)) { returnfalse;
} returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.