Full-test search: Use dictionary-specific articles sorting while search

This commit is contained in:
Abs62 2018-03-08 00:17:09 +03:00
parent 3deb5ee266
commit 1e85a18662
3 changed files with 28 additions and 5 deletions

View file

@ -189,6 +189,12 @@ public:
virtual uint32_t getFtsIndexVersion()
{ return 0; }
// Sort articles offsets for full-text search in dictionary-specific order
// to increase of articles retrieving speed
// Default - simple sorting in increase order
virtual void sortArticlesOffsetsForFTS( QVector< uint32_t > & offsets )
{ qSort( offsets ); }
/// Called before each matching operation to ensure that any child init
/// has completed. Mainly used for deferred init. The default implementation
/// does nothing.

View file

@ -340,7 +340,7 @@ void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancell
if( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
throw exUserAbort();
qSort( offsets );
dict->sortArticlesOffsetsForFTS( offsets );
QMap< QString, QVector< uint32_t > > ftsWords;
@ -851,7 +851,7 @@ void FTSResultsRequest::indexSearch( BtreeIndexing::BtreeIndex & ftsIndex,
setOfOffsets.clear();
qSort( offsets );
dict.sortArticlesOffsetsForFTS( offsets );
checkArticles( offsets, searchWords );
}
@ -1002,7 +1002,7 @@ void FTSResultsRequest::combinedIndexSearch( BtreeIndexing::BtreeIndex & ftsInde
setOfOffsets.clear();
qSort( offsets );
dict.sortArticlesOffsetsForFTS( offsets );
checkArticles( offsets, searchWords, regexp );
}
@ -1086,7 +1086,7 @@ void FTSResultsRequest::fullIndexSearch( BtreeIndexing::BtreeIndex & ftsIndex,
setOfOffsets.clear();
qSort( offsets );
dict.sortArticlesOffsetsForFTS( offsets );
checkArticles( offsets, searchWords, regexp );
}
@ -1121,7 +1121,7 @@ void FTSResultsRequest::fullSearch( QStringList & searchWords, QRegExp & regexp
setOfOffsets.clear();
qSort( offsets );
dict.sortArticlesOffsetsForFTS( offsets );
if( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
return;

17
zim.cc
View file

@ -584,6 +584,8 @@ class ZimDictionary: public BtreeIndexing::BtreeDictionary
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}
virtual void sortArticlesOffsetsForFTS( QVector< uint32_t > & offsets );
protected:
virtual void loadIcon() throw();
@ -1083,6 +1085,21 @@ void ZimDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration
}
}
void ZimDictionary::sortArticlesOffsetsForFTS( QVector< uint32_t > & offsets )
{
QVector< QPair< quint32, uint32_t > > offsetsWithClusters;
offsetsWithClusters.reserve( offsets.size() );
for( QVector< uint32_t >::ConstIterator it = offsets.constBegin();
it != offsets.constEnd(); ++it )
offsetsWithClusters.append( QPair< uint32_t, quint32 >( getArticleCluster( df, *it ), *it ) );
qSort( offsetsWithClusters );
for( int i = 0; i < offsetsWithClusters.size(); i++ )
offsets[ i ] = offsetsWithClusters.at( i ).second;
}
void ZimDictionary::getArticleText( uint32_t articleAddress, QString & headword, QString & text )
{
try