[PATCH 6/9] Add C++ HelpSearch and call from XMLHelp. Fix string conversion bug.

Gert van Valkenhoef g.h.m.van.valkenhoef at rug.nl
Sun Feb 19 04:49:08 PST 2012


---
 l10ntools/inc/l10ntools/HelpSearch.hxx             |   36 +++
 l10ntools/prj/d.lst                                |    1 +
 l10ntools/source/help/HelpIndexer.cxx              |   17 +-
 l10ntools/source/help/HelpSearch.cxx               |   40 +++
 l10ntools/source/help/LuceneHelper.cxx             |   33 ++
 l10ntools/source/help/LuceneHelper.hxx             |   13 +
 l10ntools/source/help/makefile.mk                  |    9 +-
 xmlhelp/source/cxxhelp/provider/databases.cxx      |   10 -
 .../source/cxxhelp/provider/resultsetforquery.cxx  |  315 +++++++++-----------
 .../source/helpcomponent/CLuceneHelpWrapper.cxx    |    2 +
 10 files changed, 270 insertions(+), 206 deletions(-)
 create mode 100644 l10ntools/inc/l10ntools/HelpSearch.hxx
 create mode 100644 l10ntools/source/help/HelpSearch.cxx
 create mode 100644 l10ntools/source/help/LuceneHelper.cxx
 create mode 100644 l10ntools/source/help/LuceneHelper.hxx

diff --git a/l10ntools/inc/l10ntools/HelpSearch.hxx b/l10ntools/inc/l10ntools/HelpSearch.hxx
new file mode 100644
index 0000000..4885b56
--- /dev/null
+++ b/l10ntools/inc/l10ntools/HelpSearch.hxx
@@ -0,0 +1,36 @@
+#ifndef HELPSEARCH_HXX
+#define HELPSEARCH_HXX
+
+#include <l10ntools/dllapi.h>
+
+#include <CLucene/StdHeader.h>
+#include <CLucene.h>
+
+#include <rtl/ustring.hxx>
+#include <vector>
+
+class L10N_DLLPUBLIC HelpSearch {
+	private:
+		rtl::OUString d_lang;
+		rtl::OUString d_indexDir;
+
+	public:
+
+	/**
+	 * @param lang Help files language.
+	 * @param indexDir The directory where the index files are stored.
+	 */
+	HelpSearch(rtl::OUString const &lang, rtl::OUString const &indexDir);
+
+	/**
+	 * Query the index for a certain query string.
+	 * @param queryStr The query.
+	 * @param captionOnly Set to true to search in the caption, not the content.
+	 * @param rDocuments Vector to write the paths of the found documents.
+	 * @param rScores Vector to write the scores to.
+	 */
+	bool query(rtl::OUString const &queryStr, bool captionOnly,
+		std::vector<rtl::OUString> &rDocuments, std::vector<float> &rScores);
+};
+
+#endif
diff --git a/l10ntools/prj/d.lst b/l10ntools/prj/d.lst
index 44cf5f0..e9329dc 100644
--- a/l10ntools/prj/d.lst
+++ b/l10ntools/prj/d.lst
@@ -48,6 +48,7 @@ mkdir: %_DEST%\bin\help\com\sun\star\help
 ..\inc\l10ntools\directory.hxx %_DEST%\inc\l10ntools\directory.hxx
 ..\inc\l10ntools\file.hxx %_DEST%\inc\l10ntools\file.hxx
 ..\inc\l10ntools\HelpIndexer.hxx %_DEST%\inc\l10ntools\HelpIndexer.hxx
+..\inc\l10ntools\HelpSearch.hxx %_DEST%\inc\l10ntools\HelpSearch.hxx
 ..\source\filter\merge\FCFGMerge.cfg  %_DEST%\inc\l10ntools\FCFGMerge.cfg
 
 ..\%__SRC%\lib\transex.lib %_DEST%\lib\transex.lib
diff --git a/l10ntools/source/help/HelpIndexer.cxx b/l10ntools/source/help/HelpIndexer.cxx
index b54814a..793348b 100644
--- a/l10ntools/source/help/HelpIndexer.cxx
+++ b/l10ntools/source/help/HelpIndexer.cxx
@@ -1,4 +1,5 @@
 #include <l10ntools/HelpIndexer.hxx>
+#include "LuceneHelper.hxx"
 
 #define TODO
 
@@ -100,22 +101,6 @@ bool HelpIndexer::scanForFiles(rtl::OUString const & path) {
 	return true;
 }
 
-std::vector<TCHAR> OUStringToTCHARVec(rtl::OUString const &rStr)
-{
-    //UTF-16
-    if (sizeof(wchar_t) == sizeof(sal_Unicode))
-        return std::vector<TCHAR>(rStr.getStr(), rStr.getStr() + rStr.getLength());
-
-    //UTF-32
-    std::vector<TCHAR> aRet;
-    for (sal_Int32 nStrIndex = 0; nStrIndex < rStr.getLength();)
-    {
-        const sal_uInt32 nCode = rStr.iterateCodePoints(&nStrIndex);
-        aRet.push_back(nCode);
-    }
-    return aRet;
-}
-
 bool HelpIndexer::helpDocument(rtl::OUString const & fileName, Document *doc) {
 	// 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;
diff --git a/l10ntools/source/help/HelpSearch.cxx b/l10ntools/source/help/HelpSearch.cxx
new file mode 100644
index 0000000..f50c44e
--- /dev/null
+++ b/l10ntools/source/help/HelpSearch.cxx
@@ -0,0 +1,40 @@
+#include <l10ntools/HelpSearch.hxx>
+#include "LuceneHelper.hxx"
+
+#include <iostream>
+
+HelpSearch::HelpSearch(rtl::OUString const &lang, rtl::OUString const &indexDir) :
+d_lang(lang), d_indexDir(indexDir) {}
+
+bool HelpSearch::query(rtl::OUString const &queryStr, bool captionOnly,
+		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(pathStr.getStr());
+	lucene::search::IndexSearcher searcher(reader);
+
+	TCHAR captionField[] = L"caption";
+	TCHAR contentField[] = L"content";
+	TCHAR *field = captionOnly ? captionField : contentField;
+
+	bool isWildcard = queryStr[queryStr.getLength() - 1] == L'*';
+	std::vector<TCHAR> aQueryStr(OUStringToTCHARVec(queryStr));
+	lucene::search::Query *aQuery = (isWildcard ?
+		(lucene::search::Query*)new lucene::search::WildcardQuery(new lucene::index::Term(field, &aQueryStr[0])) :
+		(lucene::search::Query*)new lucene::search::TermQuery(new lucene::index::Term(field, &aQueryStr[0])));
+	// FIXME: who is responsible for the Term*?
+
+	lucene::search::Hits *hits = searcher.search(aQuery);
+	for (unsigned i = 0; i < hits->length(); ++i) {
+		lucene::document::Document &doc = hits->doc(i); // Document* belongs to Hits.
+		wchar_t const *path = doc.get(L"path");
+		rDocuments.push_back(TCHARArrayToOUString(path != 0 ? path : L""));
+		rScores.push_back(hits->score(i));
+	}
+
+	delete hits;
+	delete aQuery;
+
+	reader->close();
+	return true;
+}
diff --git a/l10ntools/source/help/LuceneHelper.cxx b/l10ntools/source/help/LuceneHelper.cxx
new file mode 100644
index 0000000..a88542f
--- /dev/null
+++ b/l10ntools/source/help/LuceneHelper.cxx
@@ -0,0 +1,33 @@
+#include "LuceneHelper.hxx"
+
+std::vector<TCHAR> OUStringToTCHARVec(rtl::OUString const &rStr)
+{
+    //UTF-16
+    if (sizeof(TCHAR) == sizeof(sal_Unicode))
+        return std::vector<TCHAR>(rStr.getStr(), rStr.getStr() + rStr.getLength() + 1);
+
+    //UTF-32
+    std::vector<TCHAR> aRet;
+    for (sal_Int32 nStrIndex = 0; nStrIndex < rStr.getLength() + 1; )
+    {
+        const sal_uInt32 nCode = rStr.iterateCodePoints(&nStrIndex);
+        aRet.push_back(nCode);
+    }
+    return aRet;
+}
+
+inline unsigned tstrlen(TCHAR const *str) {
+	unsigned i;
+	for (i = 0; str[i] != 0; ++i) {}
+	return i;
+}
+
+rtl::OUString TCHARArrayToOUString(TCHAR const *str)
+{
+	// UTF-16
+	if (sizeof(TCHAR) == sizeof(sal_Unicode))
+		return rtl::OUString((sal_Unicode*) str);
+
+	// UTF-32
+	return rtl::OUString((char*) str, tstrlen(str), RTL_TEXTENCODING_UCS4);
+}
diff --git a/l10ntools/source/help/LuceneHelper.hxx b/l10ntools/source/help/LuceneHelper.hxx
new file mode 100644
index 0000000..7591b8c
--- /dev/null
+++ b/l10ntools/source/help/LuceneHelper.hxx
@@ -0,0 +1,13 @@
+#ifndef LUCENEHELPER_HXX
+#define LUCENEHELPER_HXX
+
+#include <CLucene/StdHeader.h>
+#include <CLucene.h>
+
+#include <rtl/ustring.hxx>
+#include <vector>
+
+std::vector<TCHAR> OUStringToTCHARVec(rtl::OUString const &rStr);
+rtl::OUString TCHARArrayToOUString(TCHAR const *str);
+
+#endif
diff --git a/l10ntools/source/help/makefile.mk b/l10ntools/source/help/makefile.mk
index 2ae3232..a466e2c 100644
--- a/l10ntools/source/help/makefile.mk
+++ b/l10ntools/source/help/makefile.mk
@@ -56,12 +56,16 @@ OBJFILES=\
         $(OBJ)$/HelpLinker.obj \
         $(OBJ)$/HelpCompiler.obj \
         $(OBJ)$/HelpIndexer.obj \
-        $(OBJ)$/HelpIndexer_main.obj
+        $(OBJ)$/HelpIndexer_main.obj \
+	$(OBJ)$/HelpSearch.obj \
+	$(OBJ)$/LuceneHelper.obj
 
 SLOFILES=\
         $(SLO)$/HelpLinker.obj \
         $(SLO)$/HelpCompiler.obj \
-        $(SLO)$/HelpIndexer.obj
+	$(SLO)$/LuceneHelper.obj \
+        $(SLO)$/HelpIndexer.obj \
+	$(SLO)$/HelpSearch.obj
 
 .IF "$(OS)" == "MACOSX" && "$(CPU)" == "P" && "$(COM)" == "GCC"
 # There appears to be a GCC 4.0.1 optimization error causing _file:good() to
@@ -85,6 +89,7 @@ APP1STDLIBS+=$(SALLIB) $(BERKELEYLIB) $(XSLTLIB) $(EXPATASCII3RDLIB)
 
 APP2TARGET=HelpIndexer
 APP2OBJS=\
+      $(OBJ)$/LuceneHelper.obj \
       $(OBJ)$/HelpIndexer.obj \
       $(OBJ)$/HelpIndexer_main.obj
 APP2RPATH = NONE
diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx
index bef8ae5..ca090e5 100644
--- a/xmlhelp/source/cxxhelp/provider/databases.cxx
+++ b/xmlhelp/source/cxxhelp/provider/databases.cxx
@@ -39,12 +39,8 @@
 #include <algorithm>
 #include <string.h>
 
-// EDIT FROM HERE
-
 #include <l10ntools/HelpIndexer.hxx>
 
-// EDIT ENDS HERE
-
 // Extensible help
 #include "com/sun/star/deployment/ExtensionManager.hpp"
 #include "com/sun/star/deployment/thePackageManagerFactory.hpp"
@@ -2092,8 +2088,6 @@ rtl::OUString IndexFolderIterator::nextIndexFolder( bool& o_rbExtension, bool& o
 
 rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemporary, Reference< deployment::XPackage > xPackage )
 {
-    fprintf(stderr, "IndexFolderIterator::implGetIndexFolderFromPackage\n");
-
     rtl::OUString aIndexFolder =
         implGetFileFromPackage( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ".idxl" )), xPackage );
 
@@ -2121,7 +2115,6 @@ rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemp
             // TEST
             //bIsWriteAccess = false;
 
-// EDIT FROM HERE
             try
             {
                 rtl::OUString aLang;
@@ -2172,9 +2165,6 @@ rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemp
             }
             catch (Exception &)
             {}
-
-// EDIT UNTIL HERE
-
         }
     }
 
diff --git a/xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx b/xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx
index 767ce89..d0dea28 100644
--- a/xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx
+++ b/xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx
@@ -33,6 +33,8 @@
 #include <com/sun/star/lang/Locale.hpp>
 #include <com/sun/star/script/XInvocation.hpp>
 
+#include <l10ntools/HelpSearch.hxx>
+
 #ifndef INCLUDED_STL_ALGORITHM
 #include <algorithm>
 #define INCLUDED_STL_ALGORITHM
@@ -96,10 +98,7 @@ ResultSetForQuery::ResultSetForQuery( const uno::Reference< lang::XMultiServiceF
         xTrans->loadModule(TransliterationModules_UPPERCASE_LOWERCASE,
                            aLocale );
 
-    // Access CLucene via XInvocation
-    Reference< script::XInvocation > xInvocation(
-        xMSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.help.HelpSearch" )) ),
-        UNO_QUERY );
+    // EDIT FROM HERE
 
     vector< vector< rtl::OUString > > queryList;
     {
@@ -132,228 +131,188 @@ ResultSetForQuery::ResultSetForQuery( const uno::Reference< lang::XMultiServiceF
     }
 
     vector< rtl::OUString > aCompleteResultVector;
-    if( xInvocation.is() )
+    rtl::OUString scope = m_aURLParameter.get_scope();
+    bool bCaptionsOnly = ( scope.compareToAscii( "Heading" ) == 0 );
+    sal_Int32 hitCount = m_aURLParameter.get_hitCount();
+
+    IndexFolderIterator aIndexFolderIt( *pDatabases, m_aURLParameter.get_module(), m_aURLParameter.get_language() );
+    rtl::OUString idxDir;
+    bool bExtension = false;
+    int iDir = 0;
+    vector< vector<HitItem>* > aIndexFolderResultVectorVector;
+
+    bool bTemporary;
+    while( !(idxDir = aIndexFolderIt.nextIndexFolder( bExtension, bTemporary )).isEmpty() )
     {
-        rtl::OUString scope = m_aURLParameter.get_scope();
-        bool bCaptionsOnly = ( scope.compareToAscii( "Heading" ) == 0 );
-        sal_Int32 hitCount = m_aURLParameter.get_hitCount();
-
-        IndexFolderIterator aIndexFolderIt( *pDatabases, m_aURLParameter.get_module(), m_aURLParameter.get_language() );
-        rtl::OUString idxDir;
-        bool bExtension = false;
-        int iDir = 0;
-        vector< vector<HitItem>* > aIndexFolderResultVectorVector;
-
-        bool bTemporary;
-        while( !(idxDir = aIndexFolderIt.nextIndexFolder( bExtension, bTemporary )).isEmpty() )
+        vector<HitItem> aIndexFolderResultVector;
+
+        try
         {
-            vector<HitItem> aIndexFolderResultVector;
+            vector< vector<HitItem>* > aQueryListResultVectorVector;
+            set< rtl::OUString > aSet,aCurrent,aResultSet;
 
-            try
-            {
-                vector< vector<HitItem>* > aQueryListResultVectorVector;
-                set< rtl::OUString > aSet,aCurrent,aResultSet;
+            int nQueryListSize = queryList.size();
+            if( nQueryListSize > 1 )
+                hitCount = 2000;
 
-                int nQueryListSize = queryList.size();
+            for( int i = 0; i < nQueryListSize; ++i )
+            {
+                vector<HitItem>* pQueryResultVector;
                 if( nQueryListSize > 1 )
-                    hitCount = 2000;
-
-                for( int i = 0; i < nQueryListSize; ++i )
                 {
-                    vector<HitItem>* pQueryResultVector;
-                    if( nQueryListSize > 1 )
-                    {
-                        pQueryResultVector = new vector<HitItem>();
-                        aQueryListResultVectorVector.push_back( pQueryResultVector );
-                    }
-                    else
-                    {
-                        pQueryResultVector = &aIndexFolderResultVector;
-                    }
-                    pQueryResultVector->reserve( hitCount );
-
-                    int nParamCount = bCaptionsOnly ? 7 : 6;
-                    Sequence<uno::Any> aParamsSeq( nParamCount );
-
-                    aParamsSeq[0] = uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "-lang" )) );
-                    aParamsSeq[1] = uno::makeAny( m_aURLParameter.get_language() );
-
-                    aParamsSeq[2] = uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "-index" )) );
-                    rtl::OUString aSystemPath;
-                    osl::FileBase::getSystemPathFromFileURL( idxDir, aSystemPath );
-                    aParamsSeq[3] = uno::makeAny( aSystemPath );
-
-                    aParamsSeq[4] = uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "-query" )) );
-
-                    const std::vector< rtl::OUString >& aListItem = queryList[i];
-                    ::rtl::OUString aNewQueryStr = aListItem[0];
-                    aParamsSeq[5] = uno::makeAny( aNewQueryStr );
+                    pQueryResultVector = new vector<HitItem>();
+                    aQueryListResultVectorVector.push_back( pQueryResultVector );
+                }
+                else
+                {
+                    pQueryResultVector = &aIndexFolderResultVector;
+                }
+                pQueryResultVector->reserve( hitCount );
 
-                    if( bCaptionsOnly )
-                        aParamsSeq[6] = uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "-caption" )) );
+// INVOCATION HERE
+                rtl::OUString aLang = m_aURLParameter.get_language();
+                rtl::OUString aSystemPath;
+                osl::FileBase::getSystemPathFromFileURL( idxDir, aSystemPath );
+                const std::vector< rtl::OUString >& aListItem = queryList[i];
+                ::rtl::OUString aNewQueryStr = aListItem[0];
 
-                    Sequence< sal_Int16 > aOutParamIndex;
-                    Sequence< uno::Any > aOutParam;
+                vector<float> aScoreVector;
+                vector<rtl::OUString> aPathVector;
 
-                    uno::Any aRet = xInvocation->invoke( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "search" )),
-                        aParamsSeq, aOutParamIndex, aOutParam );
+                HelpSearch searcher(aLang, aSystemPath);
+                searcher.query(aNewQueryStr, bCaptionsOnly, aPathVector, aScoreVector);
 
-                    Sequence< float > aScoreSeq;
-                    int nScoreCount = 0;
-                    int nOutParamCount = aOutParam.getLength();
-                    if( nOutParamCount == 1 )
-                    {
-                        const uno::Any* pScoreAnySeq = aOutParam.getConstArray();
-                        if( pScoreAnySeq[0] >>= aScoreSeq )
-                            nScoreCount = aScoreSeq.getLength();
-                    }
+                if( nQueryListSize > 1 )
+                    aSet.clear();
 
-                    Sequence<rtl::OUString> aRetSeq;
-                    if( aRet >>= aRetSeq )
+                for (unsigned j = 0; j < aPathVector.size(); ++i) {
+                    pQueryResultVector->push_back(HitItem(aPathVector[j], aScoreVector[j]));
+                    if (nQueryListSize > 1)
+                        aSet.insert(aPathVector[j]);
+                }
+// INVOCATION END
+                // intersect
+                if( nQueryListSize > 1 )
+                {
+                    if( i == 0 )
                     {
-                        if( nQueryListSize > 1 )
-                            aSet.clear();
-
-                        const rtl::OUString* pRetSeq = aRetSeq.getConstArray();
-                        int nCount = aRetSeq.getLength();
-                        if( nCount > hitCount )
-                            nCount = hitCount;
-                        for( int j = 0 ; j < nCount ; ++j )
-                        {
-                            float fScore = 0.0;
-                            if( j < nScoreCount )
-                                fScore = aScoreSeq[j];
-
-                            rtl::OUString aURL = pRetSeq[j];
-                            pQueryResultVector->push_back( HitItem( aURL, fScore ) );
-                            if( nQueryListSize > 1 )
-                                aSet.insert( aURL );
-                        }
+                        aResultSet = aSet;
                     }
-
-                    // intersect
-                    if( nQueryListSize > 1 )
+                    else
                     {
-                        if( i == 0 )
-                        {
-                            aResultSet = aSet;
-                        }
-                        else
-                        {
-                            aCurrent = aResultSet;
-                            aResultSet.clear();
-                            set_intersection( aSet.begin(),aSet.end(),
-                                              aCurrent.begin(),aCurrent.end(),
-                                              inserter(aResultSet,aResultSet.begin()));
-                        }
+                        aCurrent = aResultSet;
+                        aResultSet.clear();
+                        set_intersection( aSet.begin(),aSet.end(),
+                                          aCurrent.begin(),aCurrent.end(),
+                                          inserter(aResultSet,aResultSet.begin()));
                     }
                 }
+            }
 
-                // Combine results in aIndexFolderResultVector
-                if( nQueryListSize > 1 )
+            // Combine results in aIndexFolderResultVector
+            if( nQueryListSize > 1 )
+            {
+                for( int n = 0 ; n < nQueryListSize ; ++n )
                 {
-                    for( int n = 0 ; n < nQueryListSize ; ++n )
-                    {
-                        vector<HitItem>* pQueryResultVector = aQueryListResultVectorVector[n];
-                        vector<HitItem>& rQueryResultVector = *pQueryResultVector;
+                    vector<HitItem>* pQueryResultVector = aQueryListResultVectorVector[n];
+                    vector<HitItem>& rQueryResultVector = *pQueryResultVector;
 
-                        int nItemCount = rQueryResultVector.size();
-                        for( int i = 0 ; i < nItemCount ; ++i )
+                    int nItemCount = rQueryResultVector.size();
+                    for( int i = 0 ; i < nItemCount ; ++i )
+                    {
+                        const HitItem& rItem = rQueryResultVector[ i ];
+                        set< rtl::OUString >::iterator it;
+                        if( (it = aResultSet.find( rItem.m_aURL )) != aResultSet.end() )
                         {
-                            const HitItem& rItem = rQueryResultVector[ i ];
-                            set< rtl::OUString >::iterator it;
-                            if( (it = aResultSet.find( rItem.m_aURL )) != aResultSet.end() )
+                            HitItem aItemCopy( rItem );
+                            aItemCopy.m_fScore /= nQueryListSize;   // To get average score
+                            if( n == 0 )
                             {
-                                HitItem aItemCopy( rItem );
-                                aItemCopy.m_fScore /= nQueryListSize;   // To get average score
-                                if( n == 0 )
-                                {
-                                    // Use first pass to create entry
-                                    aIndexFolderResultVector.push_back( aItemCopy );
-                                }
-                                else
+                                // Use first pass to create entry
+                                aIndexFolderResultVector.push_back( aItemCopy );
+                            }
+                            else
+                            {
+                                // Find entry in vector
+                                int nCount = aIndexFolderResultVector.size();
+                                for( int j = 0 ; j < nCount ; ++j )
                                 {
-                                    // Find entry in vector
-                                    int nCount = aIndexFolderResultVector.size();
-                                    for( int j = 0 ; j < nCount ; ++j )
+                                    HitItem& rFindItem = aIndexFolderResultVector[ j ];
+                                    if( rFindItem.m_aURL.equals( aItemCopy.m_aURL ) )
                                     {
-                                        HitItem& rFindItem = aIndexFolderResultVector[ j ];
-                                        if( rFindItem.m_aURL.equals( aItemCopy.m_aURL ) )
-                                        {
-                                            rFindItem.m_fScore += aItemCopy.m_fScore;
-                                            break;
-                                        }
+                                        rFindItem.m_fScore += aItemCopy.m_fScore;
+                                        break;
                                     }
                                 }
                             }
                         }
-
-                        delete pQueryResultVector;
                     }
 
-                    sort( aIndexFolderResultVector.begin(), aIndexFolderResultVector.end() );
+                    delete pQueryResultVector;
                 }
 
-                vector<HitItem>* pIndexFolderHitItemVector = new vector<HitItem>( aIndexFolderResultVector );
-                aIndexFolderResultVectorVector.push_back( pIndexFolderHitItemVector );
-                aIndexFolderResultVector.clear();
-            }
-            catch( const Exception& )
-            {
+                sort( aIndexFolderResultVector.begin(), aIndexFolderResultVector.end() );
             }
 
-            ++iDir;
+            vector<HitItem>* pIndexFolderHitItemVector = new vector<HitItem>( aIndexFolderResultVector );
+            aIndexFolderResultVectorVector.push_back( pIndexFolderHitItemVector );
+            aIndexFolderResultVector.clear();
+        }
+        catch( const Exception& )
+        {
+        }
+
+        ++iDir;
 
-            if( bTemporary )
-                aIndexFolderIt.deleteTempIndexFolder( idxDir );
+        if( bTemporary )
+            aIndexFolderIt.deleteTempIndexFolder( idxDir );
 
-        }   // Iterator
+    }   // Iterator
 
 
-        int nVectorCount = aIndexFolderResultVectorVector.size();
-        vector<HitItem>::size_type* pCurrentVectorIndex = new vector<HitItem>::size_type[nVectorCount];
-        for( int j = 0 ; j < nVectorCount ; ++j )
-            pCurrentVectorIndex[j] = 0;
+    int nVectorCount = aIndexFolderResultVectorVector.size();
+    vector<HitItem>::size_type* pCurrentVectorIndex = new vector<HitItem>::size_type[nVectorCount];
+    for( int j = 0 ; j < nVectorCount ; ++j )
+        pCurrentVectorIndex[j] = 0;
 
-        sal_Int32 nTotalHitCount = m_aURLParameter.get_hitCount();
-        sal_Int32 nHitCount = 0;
-        while( nHitCount < nTotalHitCount )
+    sal_Int32 nTotalHitCount = m_aURLParameter.get_hitCount();
+    sal_Int32 nHitCount = 0;
+    while( nHitCount < nTotalHitCount )
+    {
+        int iVectorWithBestScore = -1;
+        float fBestScore = 0.0;
+        for( int k = 0 ; k < nVectorCount ; ++k )
         {
-            int iVectorWithBestScore = -1;
-            float fBestScore = 0.0;
-            for( int k = 0 ; k < nVectorCount ; ++k )
+            vector<HitItem>& rIndexFolderVector = *aIndexFolderResultVectorVector[k];
+            if( pCurrentVectorIndex[k] < rIndexFolderVector.size() )
             {
-                vector<HitItem>& rIndexFolderVector = *aIndexFolderResultVectorVector[k];
-                if( pCurrentVectorIndex[k] < rIndexFolderVector.size() )
-                {
-                    const HitItem& rItem = rIndexFolderVector[ pCurrentVectorIndex[k] ];
+                const HitItem& rItem = rIndexFolderVector[ pCurrentVectorIndex[k] ];
 
-                    if( fBestScore < rItem.m_fScore )
-                    {
-                        fBestScore = rItem.m_fScore;
-                        iVectorWithBestScore = k;
-                    }
+                if( fBestScore < rItem.m_fScore )
+                {
+                    fBestScore = rItem.m_fScore;
+                    iVectorWithBestScore = k;
                 }
             }
+        }
 
-            if( iVectorWithBestScore == -1 )    // No item left at all
-                break;
+        if( iVectorWithBestScore == -1 )    // No item left at all
+            break;
 
-            vector<HitItem>& rIndexFolderVector = *aIndexFolderResultVectorVector[iVectorWithBestScore];
-            const HitItem& rItem = rIndexFolderVector[ pCurrentVectorIndex[iVectorWithBestScore] ];
+        vector<HitItem>& rIndexFolderVector = *aIndexFolderResultVectorVector[iVectorWithBestScore];
+        const HitItem& rItem = rIndexFolderVector[ pCurrentVectorIndex[iVectorWithBestScore] ];
 
-            pCurrentVectorIndex[iVectorWithBestScore]++;
+        pCurrentVectorIndex[iVectorWithBestScore]++;
 
-            aCompleteResultVector.push_back( rItem.m_aURL );
-            ++nHitCount;
-        }
+        aCompleteResultVector.push_back( rItem.m_aURL );
+        ++nHitCount;
+    }
 
-        delete[] pCurrentVectorIndex;
-        for( int n = 0 ; n < nVectorCount ; ++n )
-        {
-            vector<HitItem>* pIndexFolderVector = aIndexFolderResultVectorVector[n];
-            delete pIndexFolderVector;
-        }
+    delete[] pCurrentVectorIndex;
+    for( int n = 0 ; n < nVectorCount ; ++n )
+    {
+        vector<HitItem>* pIndexFolderVector = aIndexFolderResultVectorVector[n];
+        delete pIndexFolderVector;
     }
 
     sal_Int32 replIdx = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "#HLP#" )).getLength();
diff --git a/xmlhelp/source/helpcomponent/CLuceneHelpWrapper.cxx b/xmlhelp/source/helpcomponent/CLuceneHelpWrapper.cxx
index 6e800f8..fb53fab 100644
--- a/xmlhelp/source/helpcomponent/CLuceneHelpWrapper.cxx
+++ b/xmlhelp/source/helpcomponent/CLuceneHelpWrapper.cxx
@@ -81,6 +81,8 @@ public:
     }
 };
 
+#include <stdio.h> // FIXME: remove once the fprintf() calls below are gone
+
 Any CLuceneHelpWrapper::invoke(const OUString& rFunctionName, const Sequence< Any >& Params, Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam)
         throw( IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException )
 {
-- 
1.7.0.4


--------------010002010906020500040707
Content-Type: text/x-patch;
 name="0007-HelpIndexer-use-OSL-for-directory-access.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0007-HelpIndexer-use-OSL-for-directory-access.patch"



More information about the LibreOffice mailing list