22#include <com/sun/star/ucb/Command.hpp>
23#include <com/sun/star/ucb/XCommandEnvironment.hpp>
24#include <com/sun/star/i18n/Transliteration.hpp>
25#include <com/sun/star/ucb/XCommandProcessor.hpp>
26#include <com/sun/star/lang/Locale.hpp>
32# pragma GCC visibility push (default)
36# pragma GCC visibility pop
39#include <rtl/ustring.hxx>
62 HitItem(OUString aURL,
float fScore)
66 bool operator < (
const HitItem& rHitItem )
const
68 return rHitItem.m_fScore < m_fScore;
74ResultSetForQuery::ResultSetForQuery(
const uno::Reference< uno::XComponentContext >& rxContext,
75 const uno::Reference< XContentProvider >& xProvider,
76 const uno::Sequence< beans::Property >& seq,
85 xTrans->loadModule(TransliterationModules_UPPERCASE_LOWERCASE,
88 std::vector< std::vector< OUString > > queryList;
92 while( !
query.isEmpty() )
98 std::vector< OUString > currentQuery;
101 OUString toliterate = xTrans->transliterate(
102 tmp,0,tmp.getLength(),
aSeq);
104 currentQuery.push_back( toliterate );
105 queryList.push_back( currentQuery );
108 if( nCpy >=
query.getLength() )
115 std::vector< OUString > aCompleteResultVector;
116 OUString scope = aURLParameter.
get_scope();
117 bool bCaptionsOnly = scope ==
"Heading";
122 bool bExtension =
false;
123 std::vector< std::vector<HitItem> > aIndexFolderResultVectorVector;
129 if( idxDir.isEmpty() )
131 std::vector<HitItem> aIndexFolderResultVector;
135 std::vector< std::vector<HitItem> > aQueryListResultVectorVector;
136 std::set< OUString > aSet,aCurrent,aResultSet;
138 int nQueryListSize = queryList.size();
139 if( nQueryListSize > 1 )
142 for(
int i = 0;
i < nQueryListSize; ++
i )
144 std::vector<HitItem>* pQueryResultVector;
145 if( nQueryListSize > 1 )
147 aQueryListResultVectorVector.emplace_back();
148 pQueryResultVector = &aQueryListResultVectorVector.back();
152 pQueryResultVector = &aIndexFolderResultVector;
154 pQueryResultVector->reserve( hitCount );
156 const std::vector< OUString >& aListItem = queryList[
i];
157 OUString aNewQueryStr = aListItem[0];
159 std::vector<float> aScoreVector;
160 std::vector<OUString> aPathVector;
165 searcher.
query(aNewQueryStr, bCaptionsOnly, aPathVector, aScoreVector);
167 catch (CLuceneError &e)
169 SAL_WARN(
"xmlhelp",
"CLuceneError: " << e.what());
172 if( nQueryListSize > 1 )
175 for (
size_t j = 0; j < aPathVector.size(); ++j) {
176 pQueryResultVector->push_back(HitItem(aPathVector[j], aScoreVector[j]));
177 if (nQueryListSize > 1)
178 aSet.insert(aPathVector[j]);
182 if( nQueryListSize > 1 )
190 aCurrent = aResultSet;
192 set_intersection( aSet.begin(),aSet.end(),
193 aCurrent.begin(),aCurrent.end(),
194 inserter(aResultSet,aResultSet.begin()));
200 if( nQueryListSize > 1 )
202 for(
int n = 0 ;
n < nQueryListSize ; ++
n )
204 std::vector<HitItem>& rQueryResultVector = aQueryListResultVectorVector[
n];
206 int nItemCount = rQueryResultVector.size();
207 for(
int i = 0 ;
i < nItemCount ; ++
i )
209 const HitItem& rItem = rQueryResultVector[
i ];
210 if( (aResultSet.find( rItem.m_aURL )) != aResultSet.end() )
212 HitItem aItemCopy( rItem );
213 aItemCopy.m_fScore /= nQueryListSize;
217 aIndexFolderResultVector.push_back( aItemCopy );
222 int nCount = aIndexFolderResultVector.size();
223 for(
int j = 0 ; j <
nCount ; ++j )
225 HitItem& rFindItem = aIndexFolderResultVector[ j ];
226 if( rFindItem.m_aURL == aItemCopy.m_aURL )
228 rFindItem.m_fScore += aItemCopy.m_fScore;
237 sort( aIndexFolderResultVector.begin(), aIndexFolderResultVector.end() );
240 aIndexFolderResultVectorVector.push_back( std::move(aIndexFolderResultVector) );
253 int nVectorCount = aIndexFolderResultVectorVector.size();
254 std::unique_ptr<std::vector<HitItem>::size_type[]> pCurrentVectorIndex(
new std::vector<HitItem>::size_type[nVectorCount]);
255 for(
int j = 0 ; j < nVectorCount ; ++j )
256 pCurrentVectorIndex[j] = 0;
258 sal_Int32 nTotalHitCount = aURLParameter.
get_hitCount();
259 sal_Int32 nHitCount = 0;
260 while( nHitCount < nTotalHitCount )
262 int iVectorWithBestScore = -1;
263 float fBestScore = 0.0;
264 for(
int k = 0 ; k < nVectorCount ; ++k )
266 std::vector<HitItem>& rIndexFolderVector = aIndexFolderResultVectorVector[k];
267 if( pCurrentVectorIndex[k] < rIndexFolderVector.size() )
269 const HitItem& rItem = rIndexFolderVector[ pCurrentVectorIndex[k] ];
271 if( fBestScore < rItem.m_fScore )
273 fBestScore = rItem.m_fScore;
274 iVectorWithBestScore = k;
279 if( iVectorWithBestScore == -1 )
282 std::vector<HitItem>& rIndexFolderVector = aIndexFolderResultVectorVector[iVectorWithBestScore];
283 const HitItem& rItem = rIndexFolderVector[ pCurrentVectorIndex[iVectorWithBestScore] ];
285 pCurrentVectorIndex[iVectorWithBestScore]++;
287 aCompleteResultVector.push_back( rItem.m_aURL );
291 pCurrentVectorIndex.reset();
292 aIndexFolderResultVectorVector.clear();
294 sal_Int32 replIdx = strlen(
"#HLP#" );
295 OUString replWith =
"vnd.sun.star.help://";
297 int nResultCount = aCompleteResultVector.size();
298 for(
int r = 0 ; r < nResultCount ; ++r )
300 OUString
aURL = aCompleteResultVector[r];
301 OUString aResultStr = replWith +
aURL.subView(replIdx);
302 m_aPath.push_back( aResultStr );
309 aCommand.Name =
"getPropertyValues";
324 uno::Reference< XCommandProcessor > cmd( content,uno::UNO_QUERY );
void query(OUString const &queryStr, bool captionOnly, std::vector< OUString > &rDocuments, std::vector< float > &rScores)
void deleteTempIndexFolder(std::u16string_view aIndexFolder)
OUString nextIndexFolder(bool &o_rbExtension, bool &o_rbTemporary)
std::vector< OUString > m_aPath
css::uno::Sequence< css::beans::Property > m_sProperty
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent() override
sal_Int32 get_hitCount() const
const OUString & get_module() const
const OUString & get_system() const
OUString const & get_language() const
const OUString & get_query() const
const OUString & get_scope() const
#define TOOLS_WARN_EXCEPTION(area, stream)
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
store_handle_type *SAL_CALL query(OStoreObject *pHandle, store_handle_type *)