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"
@@ -1308,21 +1309,6 @@ void IndexWriter::indexCompaction(std::vector<lucene::store::Directory *> &src_d
1308
1309
}
1309
1310
assert (readers.size () == numIndices);
1310
1311
1311
- // check hasProx
1312
- bool hasProx = false ;
1313
- {
1314
- if (!readers.empty ()) {
1315
- IndexReader* reader = readers[0 ];
1316
- hasProx = reader->getFieldInfos ()->hasProx ();
1317
- for (int32_t i = 1 ; i < readers.size (); i++) {
1318
- if (hasProx != readers[i]->getFieldInfos ()->hasProx ()) {
1319
- _CLTHROWA (CL_ERR_IllegalArgument, " src_dirs hasProx inconformity" );
1320
- }
1321
- }
1322
- }
1323
- }
1324
- // std::cout << "hasProx: " << hasProx << std::endl;
1325
-
1326
1312
numDestIndexes = dest_dirs.size ();
1327
1313
1328
1314
// print dest index files
@@ -1342,8 +1328,27 @@ void IndexWriter::indexCompaction(std::vector<lucene::store::Directory *> &src_d
1342
1328
std::vector<lucene::index ::IndexWriter *> destIndexWriterList;
1343
1329
std::vector<lucene::store::IndexOutput *> nullBitmapIndexOutputList;
1344
1330
try {
1331
+ // check hasProx, indexVersion
1332
+ bool hasProx = false ;
1333
+ IndexVersion indexVersion = IndexVersion::kV1 ;
1334
+ {
1335
+ if (!readers.empty ()) {
1336
+ IndexReader* reader = readers[0 ];
1337
+ hasProx = reader->getFieldInfos ()->hasProx ();
1338
+ indexVersion = reader->getFieldInfos ()->getIndexVersion ();
1339
+ for (int32_t i = 1 ; i < readers.size (); i++) {
1340
+ if (hasProx != readers[i]->getFieldInfos ()->hasProx ()) {
1341
+ _CLTHROWA (CL_ERR_IllegalArgument, " src_dirs hasProx inconformity" );
1342
+ }
1343
+ if (indexVersion != readers[i]->getFieldInfos ()->getIndexVersion ()) {
1344
+ _CLTHROWA (CL_ERR_IllegalArgument, " src_dirs indexVersion inconformity" );
1345
+ }
1346
+ }
1347
+ }
1348
+ }
1349
+
1345
1350
// / merge fields
1346
- mergeFields (hasProx);
1351
+ mergeFields (hasProx, indexVersion );
1347
1352
1348
1353
// / write fields and create files writers
1349
1354
for (int j = 0 ; j < numDestIndexes; j++) {
@@ -1391,12 +1396,10 @@ void IndexWriter::indexCompaction(std::vector<lucene::store::Directory *> &src_d
1391
1396
}
1392
1397
1393
1398
// / merge terms
1394
- mergeTerms (hasProx);
1399
+ mergeTerms (hasProx, indexVersion );
1395
1400
1396
1401
// / merge null_bitmap
1397
1402
mergeNullBitmap (srcNullBitmapValues, nullBitmapIndexOutputList);
1398
- } catch (CLuceneError &e) {
1399
- throw e;
1400
1403
}
1401
1404
_CLFINALLY (
1402
1405
for (auto freqOutput
@@ -1558,7 +1561,7 @@ void IndexWriter::compareIndexes(lucene::store::Directory *other) {
1558
1561
}
1559
1562
}
1560
1563
1561
- void IndexWriter::mergeFields (bool hasProx) {
1564
+ void IndexWriter::mergeFields (bool hasProx, IndexVersion indexVersion ) {
1562
1565
// Create a new FieldInfos
1563
1566
fieldInfos = _CLNEW FieldInfos ();
1564
1567
// Condition check to see if fieldInfos points to a valid instance
@@ -1573,7 +1576,8 @@ void IndexWriter::mergeFields(bool hasProx) {
1573
1576
FieldInfo *fi = reader->getFieldInfos ()->fieldInfo (j);
1574
1577
fieldInfos->add (fi->name , fi->isIndexed , fi->storeTermVector ,
1575
1578
fi->storePositionWithTermVector , fi->storeOffsetWithTermVector ,
1576
- !reader->hasNorms (fi->name ), hasProx, fi->storePayloads );
1579
+ !reader->hasNorms (fi->name ), hasProx, fi->storePayloads ,
1580
+ fi->indexVersion_ );
1577
1581
}
1578
1582
}
1579
1583
@@ -1617,7 +1621,7 @@ class postingQueue : public CL_NS(util)::PriorityQueue<DestDoc*,CL_NS(util)::Del
1617
1621
1618
1622
};
1619
1623
1620
- void IndexWriter::mergeTerms (bool hasProx) {
1624
+ void IndexWriter::mergeTerms (bool hasProx, IndexVersion indexVersion ) {
1621
1625
auto queue = _CLNEW SegmentMergeQueue (readers.size ());
1622
1626
auto numSrcIndexes = readers.size ();
1623
1627
// std::vector<TermPositions *> postingsList(numSrcIndexes);
@@ -1670,6 +1674,7 @@ void IndexWriter::mergeTerms(bool hasProx) {
1670
1674
1671
1675
std::vector<std::vector<uint32_t >> docDeltaBuffers (numDestIndexes);
1672
1676
std::vector<std::vector<uint32_t >> freqBuffers (numDestIndexes);
1677
+ std::vector<std::vector<uint32_t >> posBuffers (numDestIndexes);
1673
1678
auto destPostingQueues = _CLNEW postingQueue (matchSize);
1674
1679
std::vector<DestDoc> destDocs (matchSize);
1675
1680
@@ -1761,6 +1766,7 @@ void IndexWriter::mergeTerms(bool hasProx) {
1761
1766
auto proxOut = proxOutputList[destIdx];
1762
1767
auto & docDeltaBuffer = docDeltaBuffers[destIdx];
1763
1768
auto & freqBuffer = freqBuffers[destIdx];
1769
+ auto & posBuffer = posBuffers[destIdx];
1764
1770
auto skipWriter = skipListWriterList[destIdx];
1765
1771
auto & df = dfs[destIdx];
1766
1772
auto & lastDoc = lastDocs[destIdx];
@@ -1779,6 +1785,9 @@ void IndexWriter::mergeTerms(bool hasProx) {
1779
1785
encode (freqOut, docDeltaBuffer, true );
1780
1786
if (hasProx) {
1781
1787
encode (freqOut, freqBuffer, false );
1788
+ if (indexVersion >= IndexVersion::kV2 ) {
1789
+ PforUtil::encodePos (proxOut, posBuffer);
1790
+ }
1782
1791
}
1783
1792
1784
1793
skipWriter->setSkipData (lastDoc, false , -1 );
@@ -1794,7 +1803,11 @@ void IndexWriter::mergeTerms(bool hasProx) {
1794
1803
for (int32_t i = 0 ; i < descPositions.size (); i++) {
1795
1804
int32_t position = descPositions[i];
1796
1805
int32_t delta = position - lastPosition;
1797
- proxOut->writeVInt (delta);
1806
+ if (indexVersion >= IndexVersion::kV2 ) {
1807
+ posBuffer.push_back (delta);
1808
+ } else {
1809
+ proxOut->writeVInt (delta);
1810
+ }
1798
1811
lastPosition = position;
1799
1812
}
1800
1813
freqBuffer.push_back (destFreq);
@@ -1831,6 +1844,7 @@ void IndexWriter::mergeTerms(bool hasProx) {
1831
1844
{
1832
1845
auto & docDeltaBuffer = docDeltaBuffers[i];
1833
1846
auto & freqBuffer = freqBuffers[i];
1847
+ auto & posBuffer = posBuffers[i];
1834
1848
1835
1849
freqOutput->writeByte ((char )CodeMode::kDefault );
1836
1850
freqOutput->writeVInt (docDeltaBuffer.size ());
@@ -1854,6 +1868,9 @@ void IndexWriter::mergeTerms(bool hasProx) {
1854
1868
}
1855
1869
docDeltaBuffer.resize (0 );
1856
1870
freqBuffer.resize (0 );
1871
+ if (indexVersion >= IndexVersion::kV2 ) {
1872
+ PforUtil::encodePos (proxOutput, posBuffer);
1873
+ }
1857
1874
}
1858
1875
1859
1876
int64_t skipPointer = skipListWriter->writeSkip (freqOutput);
0 commit comments