Kaydet (Commit) 170b9551 authored tarafından Caolán McNamara's avatar Caolán McNamara

tweak for cross-platformity

üst 561cbe2b
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
class L10N_DLLPUBLIC HelpSearch { class L10N_DLLPUBLIC HelpSearch {
private: private:
rtl::OUString d_lang; rtl::OUString d_lang;
rtl::OUString d_indexDir; rtl::OString d_indexDir;
public: public:
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2012 Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
* (initial developer)
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#include <l10ntools/HelpIndexer.hxx> #include <l10ntools/HelpIndexer.hxx>
#include "LuceneHelper.hxx" #include "LuceneHelper.hxx"
#include <CLucene/analysis/LanguageBasedAnalyzer.h> #include <CLucene/analysis/LanguageBasedAnalyzer.h>
#include <rtl/string.hxx> #include <rtl/string.hxx>
#include <rtl/uri.hxx>
#include <rtl/ustrbuf.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <osl/thread.h>
#include <algorithm> #include <algorithm>
using namespace lucene::document; using namespace lucene::document;
HelpIndexer::HelpIndexer(rtl::OUString const &lang, rtl::OUString const &module, HelpIndexer::HelpIndexer(rtl::OUString const &lang, rtl::OUString const &module,
rtl::OUString const &captionDir, rtl::OUString const &contentDir, rtl::OUString const &indexDir) : rtl::OUString const &captionDir, rtl::OUString const &contentDir, rtl::OUString const &indexDir) :
d_lang(lang), d_module(module), d_captionDir(captionDir), d_contentDir(contentDir), d_indexDir(indexDir), d_lang(lang), d_module(module), d_captionDir(captionDir), d_contentDir(contentDir), d_indexDir(indexDir),
d_error(), d_files() {} d_error(), d_files()
{
}
bool HelpIndexer::indexDocuments() { bool HelpIndexer::indexDocuments() {
if (!scanForFiles()) { if (!scanForFiles()) {
return false; return false;
} }
rtl::OUString sLang = d_lang.getToken(0, '-'); rtl::OUString sLang = d_lang.getToken(0, '-');
bool bUseCJK = bool bUseCJK =
sLang.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ja")) || sLang.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ja")) ||
sLang.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ko")) || sLang.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ko")) ||
sLang.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("zh")); sLang.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("zh"));
// Construct the analyzer appropriate for the given language // Construct the analyzer appropriate for the given language
lucene::analysis::Analyzer *analyzer = ( lucene::analysis::Analyzer *analyzer;
bUseCJK ? if (bUseCJK)
(lucene::analysis::Analyzer*)new lucene::analysis::LanguageBasedAnalyzer(L"cjk") : analyzer = new lucene::analysis::LanguageBasedAnalyzer(L"cjk");
(lucene::analysis::Analyzer*)new lucene::analysis::standard::StandardAnalyzer()); else
analyzer = new lucene::analysis::standard::StandardAnalyzer();
rtl::OString indexDirStr;
d_indexDir.convertToString(&indexDirStr, RTL_TEXTENCODING_ASCII_US, 0); rtl::OUString ustrSystemPath;
lucene::index::IndexWriter writer(indexDirStr.getStr(), analyzer, true); osl::File::getSystemPathFromFileURL(d_indexDir, ustrSystemPath);
// Index the identified help files rtl::OString indexDirStr = rtl::OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding());
Document doc; lucene::index::IndexWriter writer(indexDirStr.getStr(), analyzer, true);
for (std::set<rtl::OUString>::iterator i = d_files.begin(); i != d_files.end(); ++i) {
doc.clear(); // Index the identified help files
if (!helpDocument(*i, &doc)) { Document doc;
delete analyzer; for (std::set<rtl::OUString>::iterator i = d_files.begin(); i != d_files.end(); ++i) {
return false; helpDocument(*i, &doc);
} writer.addDocument(&doc);
writer.addDocument(&doc); doc.clear();
} }
writer.optimize();
// Optimize the index
writer.optimize(); // Optimize the index
writer.optimize();
delete analyzer;
return true; delete analyzer;
return true;
} }
rtl::OUString const & HelpIndexer::getErrorMessage() { rtl::OUString const & HelpIndexer::getErrorMessage() {
return d_error; return d_error;
} }
bool HelpIndexer::scanForFiles() { bool HelpIndexer::scanForFiles() {
if (!scanForFiles(d_contentDir)) { if (!scanForFiles(d_contentDir)) {
return false; return false;
} }
if (!scanForFiles(d_captionDir)) { if (!scanForFiles(d_captionDir)) {
return false; return false;
} }
return true; return true;
} }
bool HelpIndexer::scanForFiles(rtl::OUString const & path) { bool HelpIndexer::scanForFiles(rtl::OUString const & path) {
osl::Directory dir(path);
if (osl::FileBase::E_None != dir.open()) { osl::Directory dir(path);
d_error = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Error reading directory ")) + path; if (osl::FileBase::E_None != dir.open()) {
return true; d_error = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Error reading directory ")) + path;
} return true;
}
osl::DirectoryItem item;
osl::FileStatus fileStatus(osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Type); osl::DirectoryItem item;
while (dir.getNextItem(item) == osl::FileBase::E_None) { osl::FileStatus fileStatus(osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_Type);
if (fileStatus.getFileType() == osl::FileStatus::Regular) { while (dir.getNextItem(item) == osl::FileBase::E_None) {
d_files.insert(fileStatus.getFileName()); item.getFileStatus(fileStatus);
} if (fileStatus.getFileType() == osl::FileStatus::Regular) {
} d_files.insert(fileStatus.getFileName());
}
return true; }
return true;
} }
bool HelpIndexer::helpDocument(rtl::OUString const & fileName, Document *doc) { bool HelpIndexer::helpDocument(rtl::OUString const & fileName, Document *doc) {
// Add the help path as an indexed, untokenized field. // Add the help path as an indexed, untokenized field.
rtl::OUString path = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#HLP#")) + d_module + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + fileName;
std::vector<TCHAR> aPath(OUStringToTCHARVec(path)); rtl::OUString path = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#HLP#")) +
doc->add(*new Field(_T("path"), &aPath[0], Field::STORE_YES | Field::INDEX_UNTOKENIZED)); d_module + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + fileName;
std::vector<TCHAR> aPath(OUStringToTCHARVec(path));
// Add the caption as a field. doc->add(*_CLNEW Field(_T("path"), &aPath[0], Field::STORE_YES | Field::INDEX_UNTOKENIZED));
rtl::OUString captionPath = d_captionDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + fileName;
doc->add(*new Field(_T("caption"), helpFileReader(captionPath), Field::STORE_NO | Field::INDEX_TOKENIZED)); rtl::OUString sEscapedFileName =
// FIXME: does the Document take responsibility for the FileReader or should I free it somewhere? rtl::Uri::encode(fileName,
rtl_UriCharClassUric, rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8);
// Add the content as a field.
rtl::OUString contentPath = d_contentDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + fileName; // Add the caption as a field.
doc->add(*new Field(_T("content"), helpFileReader(contentPath), Field::STORE_NO | Field::INDEX_TOKENIZED)); rtl::OUString captionPath = d_captionDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sEscapedFileName;
// FIXME: does the Document take responsibility for the FileReader or should I free it somewhere? doc->add(*_CLNEW Field(_T("caption"), helpFileReader(captionPath), Field::STORE_NO | Field::INDEX_TOKENIZED));
return true; // Add the content as a field.
rtl::OUString contentPath = d_contentDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sEscapedFileName;
doc->add(*_CLNEW Field(_T("content"), helpFileReader(contentPath), Field::STORE_NO | Field::INDEX_TOKENIZED));
return true;
} }
lucene::util::Reader *HelpIndexer::helpFileReader(rtl::OUString const & path) { lucene::util::Reader *HelpIndexer::helpFileReader(rtl::OUString const & path) {
osl::File file(path); osl::File file(path);
if (osl::FileBase::E_None == file.open(osl_File_OpenFlag_Read)) { if (osl::FileBase::E_None == file.open(osl_File_OpenFlag_Read)) {
file.close(); file.close();
rtl::OString pathStr; rtl::OUString ustrSystemPath;
path.convertToString(&pathStr, RTL_TEXTENCODING_ASCII_US, 0); // FIXME: path encoding? osl::File::getSystemPathFromFileURL(path, ustrSystemPath);
return new lucene::util::FileReader(pathStr.getStr(), "UTF-8"); rtl::OString pathStr = rtl::OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding());
} else { return _CLNEW lucene::util::FileReader(pathStr.getStr(), "UTF-8");
return new lucene::util::StringReader(L""); } else {
} return _CLNEW lucene::util::StringReader(L"");
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#include <l10ntools/HelpIndexer.hxx> /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2012 Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
* (initial developer)
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#include <l10ntools/HelpIndexer.hxx>
#include <osl/file.hxx>
#include <osl/process.h>
#include <osl/thread.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
int main(int argc, char **argv) { int main(int argc, char **argv) {
const std::string pLang("-lang"); const std::string pLang("-lang");
const std::string pModule("-mod"); const std::string pModule("-mod");
const std::string pOutDir("-zipdir"); const std::string pOutDir("-zipdir");
const std::string pSrcDir("-srcdir"); const std::string pSrcDir("-srcdir");
std::string lang; std::string lang;
std::string module; std::string module;
std::string srcDir; std::string srcDir;
std::string outDir; std::string outDir;
bool error = false; bool error = false;
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
if (pLang.compare(argv[i]) == 0) { if (pLang.compare(argv[i]) == 0) {
if (i + 1 < argc) { if (i + 1 < argc) {
lang = argv[++i]; lang = argv[++i];
} else { } else {
error = true; error = true;
} }
} else if (pModule.compare(argv[i]) == 0) { } else if (pModule.compare(argv[i]) == 0) {
if (i + 1 < argc) { if (i + 1 < argc) {
module = argv[++i]; module = argv[++i];
} else { } else {
error = true; error = true;
} }
} else if (pOutDir.compare(argv[i]) == 0) { } else if (pOutDir.compare(argv[i]) == 0) {
if (i + 1 < argc) { if (i + 1 < argc) {
outDir = argv[++i]; outDir = argv[++i];
} else { } else {
error = true; error = true;
} }
} else if (pSrcDir.compare(argv[i]) == 0) { } else if (pSrcDir.compare(argv[i]) == 0) {
if (i + 1 < argc) { if (i + 1 < argc) {
srcDir = argv[++i]; srcDir = argv[++i];
} else { } else {
error = true; error = true;
} }
} else { } else {
error = true; error = true;
} }
} }
if (error) { if (error) {
std::cerr << "Error parsing command-line arguments" << std::endl; std::cerr << "Error parsing command-line arguments" << std::endl;
} }
if (error || lang.empty() || module.empty() || srcDir.empty() || outDir.empty()) { if (error || lang.empty() || module.empty() || srcDir.empty() || outDir.empty()) {
std::cerr << "Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -srcdir SourceDir -zipdir OutputDir" << std::endl; std::cerr << "Usage: HelpIndexer -lang ISOLangCode -mod HelpModule -srcdir SourceDir -zipdir OutputDir" << std::endl;
return 1; return 1;
} }
std::string captionDir(srcDir + "/caption"); std::string captionDir(srcDir + SAL_PATHDELIMITER + "caption");
std::string contentDir(srcDir + "/content"); std::string contentDir(srcDir + SAL_PATHDELIMITER + "content");
std::string indexDir(outDir + "/" + module + ".idxl"); std::string indexDir(outDir + SAL_PATHDELIMITER + module + ".idxl");
HelpIndexer indexer(
rtl::OUString::createFromAscii(lang.c_str()), rtl::OUString sCaptionDir, sContentDir, sIndexDir;
rtl::OUString::createFromAscii(module.c_str()),
rtl::OUString::createFromAscii(captionDir.c_str()), osl::File::getFileURLFromSystemPath(
rtl::OUString::createFromAscii(contentDir.c_str()), rtl::OUString(captionDir.c_str(), captionDir.size(), osl_getThreadTextEncoding()),
rtl::OUString::createFromAscii(indexDir.c_str())); sCaptionDir);
if (!indexer.indexDocuments()) {
std::wcerr << indexer.getErrorMessage().getStr() << std::endl; osl::File::getFileURLFromSystemPath(
return 2; rtl::OUString(contentDir.c_str(), contentDir.size(), osl_getThreadTextEncoding()),
} sContentDir);
return 0;
osl::File::getFileURLFromSystemPath(
rtl::OUString(indexDir.c_str(), indexDir.size(), osl_getThreadTextEncoding()),
sIndexDir);
rtl::OUString cwd;
osl_getProcessWorkingDir(&cwd.pData);
osl::File::getAbsoluteFileURL(cwd, sCaptionDir, sCaptionDir);
osl::File::getAbsoluteFileURL(cwd, sContentDir, sContentDir);
osl::File::getAbsoluteFileURL(cwd, sIndexDir, sIndexDir);
HelpIndexer indexer(
rtl::OUString(lang.c_str(), lang.size(), osl_getThreadTextEncoding()),
rtl::OUString(module.c_str(), module.size(), osl_getThreadTextEncoding()),
sCaptionDir, sContentDir, sIndexDir);
if (!indexer.indexDocuments()) {
std::wcerr << indexer.getErrorMessage().getStr() << std::endl;
return 2;
}
return 0;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2012 Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
* (initial developer)
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#include <l10ntools/HelpSearch.hxx> #include <l10ntools/HelpSearch.hxx>
#include <osl/file.hxx>
#include <osl/thread.hxx>
#include "LuceneHelper.hxx" #include "LuceneHelper.hxx"
#include <iostream> #include <iostream>
HelpSearch::HelpSearch(rtl::OUString const &lang, rtl::OUString const &indexDir) : HelpSearch::HelpSearch(rtl::OUString const &lang, rtl::OUString const &indexDir)
d_lang(lang), d_indexDir(indexDir) {} : d_lang(lang)
{
rtl::OUString ustrSystemPath;
osl::File::getSystemPathFromFileURL(indexDir, ustrSystemPath);
d_indexDir = rtl::OUStringToOString(ustrSystemPath, osl_getThreadTextEncoding());
}
bool HelpSearch::query(rtl::OUString const &queryStr, bool captionOnly, bool HelpSearch::query(rtl::OUString const &queryStr, bool captionOnly,
std::vector<rtl::OUString> &rDocuments, std::vector<float> &rScores) { std::vector<rtl::OUString> &rDocuments, std::vector<float> &rScores) {
rtl::OString pathStr;
d_indexDir.convertToString(&pathStr, RTL_TEXTENCODING_ASCII_US, 0); lucene::index::IndexReader *reader = lucene::index::IndexReader::open(d_indexDir.getStr());
lucene::index::IndexReader *reader = lucene::index::IndexReader::open(pathStr.getStr()); lucene::search::IndexSearcher searcher(reader);
lucene::search::IndexSearcher searcher(reader);
TCHAR captionField[] = L"caption";
TCHAR captionField[] = L"caption"; TCHAR contentField[] = L"content";
TCHAR contentField[] = L"content"; TCHAR *field = captionOnly ? captionField : contentField;
TCHAR *field = captionOnly ? captionField : contentField;
bool isWildcard = queryStr[queryStr.getLength() - 1] == L'*';
bool isWildcard = queryStr[queryStr.getLength() - 1] == L'*'; std::vector<TCHAR> aQueryStr(OUStringToTCHARVec(queryStr));
std::vector<TCHAR> aQueryStr(OUStringToTCHARVec(queryStr)); lucene::search::Query *pQuery;
lucene::search::Query *aQuery = (isWildcard ? if (isWildcard)
(lucene::search::Query*)new lucene::search::WildcardQuery(new lucene::index::Term(field, &aQueryStr[0])) : pQuery = _CLNEW lucene::search::WildcardQuery(_CLNEW lucene::index::Term(field, &aQueryStr[0]));
(lucene::search::Query*)new lucene::search::TermQuery(new lucene::index::Term(field, &aQueryStr[0]))); else
// FIXME: who is responsible for the Term*? pQuery = _CLNEW lucene::search::TermQuery(_CLNEW lucene::index::Term(field, &aQueryStr[0]));
lucene::search::Hits *hits = searcher.search(aQuery); lucene::search::Hits *hits = searcher.search(pQuery);
for (unsigned i = 0; i < hits->length(); ++i) { for (unsigned i = 0; i < hits->length(); ++i) {
lucene::document::Document &doc = hits->doc(i); // Document* belongs to Hits. lucene::document::Document &doc = hits->doc(i); // Document* belongs to Hits.
wchar_t const *path = doc.get(L"path"); wchar_t const *path = doc.get(L"path");
rDocuments.push_back(TCHARArrayToOUString(path != 0 ? path : L"")); rDocuments.push_back(TCHARArrayToOUString(path != 0 ? path : L""));
rScores.push_back(hits->score(i)); rScores.push_back(hits->score(i));
} }
delete hits; _CLDELETE(hits);
delete aQuery; _CLDELETE(pQuery);
reader->close(); reader->close();
return true; _CLDELETE(reader);
return true;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2012 Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
* (initial developer)
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#include "LuceneHelper.hxx" #include "LuceneHelper.hxx"
std::vector<TCHAR> OUStringToTCHARVec(rtl::OUString const &rStr) std::vector<TCHAR> OUStringToTCHARVec(rtl::OUString const &rStr)
...@@ -26,3 +55,5 @@ rtl::OUString TCHARArrayToOUString(TCHAR const *str) ...@@ -26,3 +55,5 @@ rtl::OUString TCHARArrayToOUString(TCHAR const *str)
// UTF-32 // UTF-32
return rtl::OUString((const sal_uInt32*)str, wcslen(str)); return rtl::OUString((const sal_uInt32*)str, wcslen(str));
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2012 Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
* (initial developer)
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#ifndef LUCENEHELPER_HXX #ifndef LUCENEHELPER_HXX
#define LUCENEHELPER_HXX #define LUCENEHELPER_HXX
...@@ -11,3 +40,5 @@ std::vector<TCHAR> OUStringToTCHARVec(rtl::OUString const &rStr); ...@@ -11,3 +40,5 @@ std::vector<TCHAR> OUStringToTCHARVec(rtl::OUString const &rStr);
rtl::OUString TCHARArrayToOUString(TCHAR const *str); rtl::OUString TCHARArrayToOUString(TCHAR const *str);
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -2109,8 +2109,9 @@ rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemp ...@@ -2109,8 +2109,9 @@ rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemp
m_xSFA->kill( aCreateTestFolder ); m_xSFA->kill( aCreateTestFolder );
} }
catch (Exception &) catch (const Exception &)
{} {
}
// TEST // TEST
//bIsWriteAccess = false; //bIsWriteAccess = false;
...@@ -2138,8 +2139,9 @@ rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemp ...@@ -2138,8 +2139,9 @@ rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemp
{ {
m_xSFA->kill( aTempDirURL ); m_xSFA->kill( aTempDirURL );
} }
catch (Exception &) catch (const Exception &)
{} {
}
m_xSFA->createFolder( aTempDirURL ); m_xSFA->createFolder( aTempDirURL );
aZipDir = aTempDirURL; aZipDir = aTempDirURL;
...@@ -2147,24 +2149,21 @@ rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemp ...@@ -2147,24 +2149,21 @@ rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemp
} }
} }
rtl::OUString aTargetDir; rtl::OUString aCaption = aLangURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/caption"));
osl::FileBase::getSystemPathFromFileURL( aZipDir, aTargetDir ); rtl::OUString aContent = aLangURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/content"));
rtl::OUString aSourceDir;
osl::FileBase::getSystemPathFromFileURL( aLangURL, aSourceDir );
rtl::OUString aCaption(RTL_CONSTASCII_USTRINGPARAM("/caption")); HelpIndexer aIndexer(aLang, aMod, aCaption, aContent, aZipDir);
rtl::OUString aContent(RTL_CONSTASCII_USTRINGPARAM("/content"));
HelpIndexer aIndexer(aLang, aMod, aSourceDir + aCaption, aSourceDir + aContent, aTargetDir); aIndexer.indexDocuments();
if( bIsWriteAccess ) if( bIsWriteAccess )
aIndexFolder = implGetFileFromPackage( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ".idxl" )), xPackage ); aIndexFolder = implGetFileFromPackage( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ".idxl" )), xPackage );
else else
aIndexFolder = aZipDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/help.idxl" )); aIndexFolder = aZipDir + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/help.idxl" ));
} }
catch (Exception &) catch (const Exception &)
{} {
}
} }
} }
...@@ -2181,8 +2180,9 @@ void IndexFolderIterator::deleteTempIndexFolder( const rtl::OUString& aIndexFold ...@@ -2181,8 +2180,9 @@ void IndexFolderIterator::deleteTempIndexFolder( const rtl::OUString& aIndexFold
{ {
m_xSFA->kill( aTmpFolder ); m_xSFA->kill( aTmpFolder );
} }
catch (Exception &) catch (const Exception &)
{} {
}
} }
} }
......
...@@ -169,15 +169,13 @@ ResultSetForQuery::ResultSetForQuery( const uno::Reference< lang::XMultiServiceF ...@@ -169,15 +169,13 @@ ResultSetForQuery::ResultSetForQuery( const uno::Reference< lang::XMultiServiceF
// START Invoke CLucene HelpSearch // START Invoke CLucene HelpSearch
rtl::OUString aLang = m_aURLParameter.get_language(); rtl::OUString aLang = m_aURLParameter.get_language();
rtl::OUString aSystemPath;
osl::FileBase::getSystemPathFromFileURL( idxDir, aSystemPath );
const std::vector< rtl::OUString >& aListItem = queryList[i]; const std::vector< rtl::OUString >& aListItem = queryList[i];
::rtl::OUString aNewQueryStr = aListItem[0]; ::rtl::OUString aNewQueryStr = aListItem[0];
vector<float> aScoreVector; vector<float> aScoreVector;
vector<rtl::OUString> aPathVector; vector<rtl::OUString> aPathVector;
HelpSearch searcher(aLang, aSystemPath); HelpSearch searcher(aLang, idxDir);
searcher.query(aNewQueryStr, bCaptionsOnly, aPathVector, aScoreVector); searcher.query(aNewQueryStr, bCaptionsOnly, aPathVector, aScoreVector);
if( nQueryListSize > 1 ) if( nQueryListSize > 1 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment