diff options
author | Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl> | 2012-02-19 13:49:08 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-02-23 10:31:17 +0000 |
commit | 70a7cd0923795ee5c8210b476e2897d12988ad95 (patch) | |
tree | e385d49216d229ce6428148e7ec6bdfdda2216df /xmlhelp/source | |
parent | tweak build (diff) | |
download | core-70a7cd0923795ee5c8210b476e2897d12988ad95.tar.gz core-70a7cd0923795ee5c8210b476e2897d12988ad95.zip |
Add C++ HelpSearch and call from XMLHelp. Fix string conversion bug.
Diffstat (limited to 'xmlhelp/source')
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/databases.cxx | 10 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/resultsetforquery.cxx | 315 | ||||
-rw-r--r-- | xmlhelp/source/helpcomponent/CLuceneHelpWrapper.cxx | 2 |
3 files changed, 139 insertions, 188 deletions
diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx index bef8ae5e07c7..ca090e5dc25e 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 767ce89173b0..d0dea2860206 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 6e800f8ac9c6..fb53fabd1010 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 ) { |