8
8
9
9
#include " CLucene/analysis/AnalysisHeader.h"
10
10
#include " CLucene/analysis/Analyzers.h"
11
+ #include " CLucene/config/repl_wchar.h"
11
12
#include " CLucene/document/Document.h"
12
13
#include " CLucene/search/Similarity.h"
13
14
#include " CLucene/store/Directory.h"
@@ -1327,22 +1328,27 @@ void IndexWriter::indexCompaction(std::vector<lucene::store::Directory *> &src_d
1327
1328
std::vector<lucene::index ::IndexWriter *> destIndexWriterList;
1328
1329
std::vector<lucene::store::IndexOutput *> nullBitmapIndexOutputList;
1329
1330
try {
1330
- // check hasProx
1331
+ // check hasProx, indexVersion
1331
1332
bool hasProx = false ;
1333
+ IndexVersion indexVersion = IndexVersion::kV1 ;
1332
1334
{
1333
1335
if (!readers.empty ()) {
1334
1336
IndexReader* reader = readers[0 ];
1335
1337
hasProx = reader->getFieldInfos ()->hasProx ();
1338
+ indexVersion = reader->getFieldInfos ()->getIndexVersion ();
1336
1339
for (int32_t i = 1 ; i < readers.size (); i++) {
1337
1340
if (hasProx != readers[i]->getFieldInfos ()->hasProx ()) {
1338
1341
_CLTHROWA (CL_ERR_IllegalArgument, " src_dirs hasProx inconformity" );
1339
1342
}
1343
+ if (indexVersion != readers[i]->getFieldInfos ()->getIndexVersion ()) {
1344
+ _CLTHROWA (CL_ERR_IllegalArgument, " src_dirs indexVersion inconformity" );
1345
+ }
1340
1346
}
1341
1347
}
1342
1348
}
1343
1349
1344
1350
// / merge fields
1345
- mergeFields (hasProx);
1351
+ mergeFields (hasProx, indexVersion );
1346
1352
1347
1353
// / write fields and create files writers
1348
1354
for (int j = 0 ; j < numDestIndexes; j++) {
@@ -1390,7 +1396,7 @@ void IndexWriter::indexCompaction(std::vector<lucene::store::Directory *> &src_d
1390
1396
}
1391
1397
1392
1398
// / merge terms
1393
- mergeTerms (hasProx);
1399
+ mergeTerms (hasProx, indexVersion );
1394
1400
1395
1401
// / merge null_bitmap
1396
1402
mergeNullBitmap (srcNullBitmapValues, nullBitmapIndexOutputList);
@@ -1555,7 +1561,7 @@ void IndexWriter::compareIndexes(lucene::store::Directory *other) {
1555
1561
}
1556
1562
}
1557
1563
1558
- void IndexWriter::mergeFields (bool hasProx) {
1564
+ void IndexWriter::mergeFields (bool hasProx, IndexVersion indexVersion ) {
1559
1565
// Create a new FieldInfos
1560
1566
fieldInfos = _CLNEW FieldInfos ();
1561
1567
// Condition check to see if fieldInfos points to a valid instance
@@ -1570,7 +1576,8 @@ void IndexWriter::mergeFields(bool hasProx) {
1570
1576
FieldInfo *fi = reader->getFieldInfos ()->fieldInfo (j);
1571
1577
fieldInfos->add (fi->name , fi->isIndexed , fi->storeTermVector ,
1572
1578
fi->storePositionWithTermVector , fi->storeOffsetWithTermVector ,
1573
- !reader->hasNorms (fi->name ), hasProx, fi->storePayloads );
1579
+ !reader->hasNorms (fi->name ), hasProx, fi->storePayloads ,
1580
+ fi->indexVersion_ );
1574
1581
}
1575
1582
}
1576
1583
@@ -1614,7 +1621,7 @@ class postingQueue : public CL_NS(util)::PriorityQueue<DestDoc*,CL_NS(util)::Del
1614
1621
1615
1622
};
1616
1623
1617
- void IndexWriter::mergeTerms (bool hasProx) {
1624
+ void IndexWriter::mergeTerms (bool hasProx, IndexVersion indexVersion ) {
1618
1625
auto queue = _CLNEW SegmentMergeQueue (readers.size ());
1619
1626
auto numSrcIndexes = readers.size ();
1620
1627
// std::vector<TermPositions *> postingsList(numSrcIndexes);
@@ -1667,6 +1674,7 @@ void IndexWriter::mergeTerms(bool hasProx) {
1667
1674
1668
1675
std::vector<std::vector<uint32_t >> docDeltaBuffers (numDestIndexes);
1669
1676
std::vector<std::vector<uint32_t >> freqBuffers (numDestIndexes);
1677
+ std::vector<std::vector<uint32_t >> posBuffers (numDestIndexes);
1670
1678
auto destPostingQueues = _CLNEW postingQueue (matchSize);
1671
1679
std::vector<DestDoc> destDocs (matchSize);
1672
1680
@@ -1758,6 +1766,7 @@ void IndexWriter::mergeTerms(bool hasProx) {
1758
1766
auto proxOut = proxOutputList[destIdx];
1759
1767
auto & docDeltaBuffer = docDeltaBuffers[destIdx];
1760
1768
auto & freqBuffer = freqBuffers[destIdx];
1769
+ auto & posBuffer = posBuffers[destIdx];
1761
1770
auto skipWriter = skipListWriterList[destIdx];
1762
1771
auto & df = dfs[destIdx];
1763
1772
auto & lastDoc = lastDocs[destIdx];
@@ -1776,6 +1785,9 @@ void IndexWriter::mergeTerms(bool hasProx) {
1776
1785
encode (freqOut, docDeltaBuffer, true );
1777
1786
if (hasProx) {
1778
1787
encode (freqOut, freqBuffer, false );
1788
+ if (indexVersion >= IndexVersion::kV2 ) {
1789
+ PforUtil::encodePos (proxOut, posBuffer);
1790
+ }
1779
1791
}
1780
1792
1781
1793
skipWriter->setSkipData (lastDoc, false , -1 );
@@ -1791,7 +1803,11 @@ void IndexWriter::mergeTerms(bool hasProx) {
1791
1803
for (int32_t i = 0 ; i < descPositions.size (); i++) {
1792
1804
int32_t position = descPositions[i];
1793
1805
int32_t delta = position - lastPosition;
1794
- proxOut->writeVInt (delta);
1806
+ if (indexVersion >= IndexVersion::kV2 ) {
1807
+ posBuffer.push_back (delta);
1808
+ } else {
1809
+ proxOut->writeVInt (delta);
1810
+ }
1795
1811
lastPosition = position;
1796
1812
}
1797
1813
freqBuffer.push_back (destFreq);
@@ -1828,6 +1844,7 @@ void IndexWriter::mergeTerms(bool hasProx) {
1828
1844
{
1829
1845
auto & docDeltaBuffer = docDeltaBuffers[i];
1830
1846
auto & freqBuffer = freqBuffers[i];
1847
+ auto & posBuffer = posBuffers[i];
1831
1848
1832
1849
freqOutput->writeByte ((char )CodeMode::kDefault );
1833
1850
freqOutput->writeVInt (docDeltaBuffer.size ());
@@ -1851,6 +1868,9 @@ void IndexWriter::mergeTerms(bool hasProx) {
1851
1868
}
1852
1869
docDeltaBuffer.resize (0 );
1853
1870
freqBuffer.resize (0 );
1871
+ if (indexVersion >= IndexVersion::kV2 ) {
1872
+ PforUtil::encodePos (proxOutput, posBuffer);
1873
+ }
1854
1874
}
1855
1875
1856
1876
int64_t skipPointer = skipListWriter->writeSkip (freqOutput);
0 commit comments