diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2019-05-09 15:13:48 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2019-05-09 15:13:48 +0200 |
commit | d9cd0943c4d2b71319b1bf2ddba114026b2e2ce6 (patch) | |
tree | da189c985fb05a97a4ad0a8332b6dffdc23f015d /searchlib | |
parent | 54e9c858d1aa62dbcb97dcb2743e79d03d784334 (diff) |
Simplify factories for posocc files.
Diffstat (limited to 'searchlib')
4 files changed, 27 insertions, 66 deletions
diff --git a/searchlib/src/vespa/searchlib/diskindex/extposocc.cpp b/searchlib/src/vespa/searchlib/diskindex/extposocc.cpp index 34e64a9b558..d03f7ca4149 100644 --- a/searchlib/src/vespa/searchlib/diskindex/extposocc.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/extposocc.cpp @@ -51,47 +51,20 @@ setupDefaultPosOccParameters(PostingListParams *countParams, } -PostingListFileSeqWrite * -makePosOccWrite(const vespalib::string &name, - PostingListCountFileSeqWrite *const posOccCountWrite, +std::unique_ptr<PostingListFileSeqWrite> +makePosOccWrite(PostingListCountFileSeqWrite *const posOccCountWrite, bool dynamicK, const PostingListParams ¶ms, const PostingListParams &featureParams, const Schema &schema, - uint32_t indexId, - const TuneFileSeqWrite &tuneFileWrite) + uint32_t indexId) { - PostingListFileSeqWrite *posOccWrite = nullptr; + std::unique_ptr<PostingListFileSeqWrite> posOccWrite; - FileHeader fileHeader; - if (fileHeader.taste(name, tuneFileWrite)) { - if (fileHeader.getVersion() == 1 && - fileHeader.getBigEndian() && - fileHeader.getFormats().size() == 2 && - fileHeader.getFormats()[0] == - Zc4PosOccSeqRead::getIdentifier(true) && - fileHeader.getFormats()[1] == - ZcPosOccSeqRead::getSubIdentifier()) { - dynamicK = true; - } else if (fileHeader.getVersion() == 1 && - fileHeader.getBigEndian() && - fileHeader.getFormats().size() == 2 && - fileHeader.getFormats()[0] == - Zc4PosOccSeqRead::getIdentifier(false) && - fileHeader.getFormats()[1] == - Zc4PosOccSeqRead::getSubIdentifier()) { - dynamicK = false; - } else { - LOG(warning, - "Could not detect format for posocc file write %s", - name.c_str()); - } - } if (dynamicK) { - posOccWrite = new ZcPosOccSeqWrite(schema, indexId, posOccCountWrite); + posOccWrite = std::make_unique<ZcPosOccSeqWrite>(schema, indexId, posOccCountWrite); } else { - posOccWrite = - new Zc4PosOccSeqWrite(schema, indexId, posOccCountWrite); + posOccWrite = std::make_unique<Zc4PosOccSeqWrite>(schema, indexId, posOccCountWrite); } posOccWrite->setFeatureParams(featureParams); @@ -100,14 +73,13 @@ makePosOccWrite(const vespalib::string &name, } -PostingListFileSeqRead * +std::unique_ptr<PostingListFileSeqRead> makePosOccRead(const vespalib::string &name, PostingListCountFileSeqRead *const posOccCountRead, - bool dynamicK, const PostingListParams &featureParams, const TuneFileSeqRead &tuneFileRead) { - PostingListFileSeqRead *posOccRead = nullptr; + std::unique_ptr<PostingListFileSeqRead> posOccRead; FileHeader fileHeader; if (fileHeader.taste(name, tuneFileRead)) { @@ -118,7 +90,7 @@ makePosOccRead(const vespalib::string &name, Zc4PosOccSeqRead::getIdentifier(true) && fileHeader.getFormats()[1] == ZcPosOccSeqRead::getSubIdentifier()) { - dynamicK = true; + posOccRead = std::make_unique<ZcPosOccSeqRead>(posOccCountRead); } else if (fileHeader.getVersion() == 1 && fileHeader.getBigEndian() && fileHeader.getFormats().size() == 2 && @@ -126,20 +98,16 @@ makePosOccRead(const vespalib::string &name, Zc4PosOccSeqRead::getIdentifier(false) && fileHeader.getFormats()[1] == Zc4PosOccSeqRead::getSubIdentifier()) { - dynamicK = false; + posOccRead = std::make_unique<Zc4PosOccSeqRead>(posOccCountRead); } else { LOG(warning, "Could not detect format for posocc file read %s", name.c_str()); } } - if (dynamicK) { - posOccRead = new ZcPosOccSeqRead(posOccCountRead); - } else { - posOccRead = new Zc4PosOccSeqRead(posOccCountRead); + if (posOccRead) { + posOccRead->setFeatureParams(featureParams); } - - posOccRead->setFeatureParams(featureParams); return posOccRead; } diff --git a/searchlib/src/vespa/searchlib/diskindex/extposocc.h b/searchlib/src/vespa/searchlib/diskindex/extposocc.h index df4e98abe35..285715849db 100644 --- a/searchlib/src/vespa/searchlib/diskindex/extposocc.h +++ b/searchlib/src/vespa/searchlib/diskindex/extposocc.h @@ -27,20 +27,17 @@ setupDefaultPosOccParameters(index::PostingListParams *countParams, uint64_t numWordIds, uint32_t docIdLimit); -index::PostingListFileSeqWrite * -makePosOccWrite(const vespalib::string &name, - index::PostingListCountFileSeqWrite *const posOccCountWrite, +std::unique_ptr<index::PostingListFileSeqWrite> +makePosOccWrite(index::PostingListCountFileSeqWrite *const posOccCountWrite, bool dynamicK, const index::PostingListParams ¶ms, const index::PostingListParams &featureParams, const index::Schema &schema, - uint32_t indexId, - const TuneFileSeqWrite &tuneFileWrite); + uint32_t indexId); -index::PostingListFileSeqRead * +std::unique_ptr<index::PostingListFileSeqRead> makePosOccRead(const vespalib::string &name, index::PostingListCountFileSeqRead *const posOccCountRead, - bool dynamicK, const index::PostingListParams &featureParams, const TuneFileSeqRead &tuneFileRead); diff --git a/searchlib/src/vespa/searchlib/diskindex/fieldreader.cpp b/searchlib/src/vespa/searchlib/diskindex/fieldreader.cpp index 8da590654da..04af3a18026 100644 --- a/searchlib/src/vespa/searchlib/diskindex/fieldreader.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/fieldreader.cpp @@ -112,7 +112,6 @@ FieldReader::open(const vespalib::string &prefix, FastOS_StatInfo statInfo; bool statres; - bool dynamicKPosOccFormat = false; // Will autodetect anyway statres = FastOS_File::Stat(name.c_str(), &statInfo); if (!statres) { LOG(error, @@ -123,11 +122,10 @@ FieldReader::open(const vespalib::string &prefix, _dictFile = std::make_unique<PageDict4FileSeqRead>(); PostingListParams featureParams; - _oldposoccfile.reset(makePosOccRead(name, - _dictFile.get(), - dynamicKPosOccFormat, - featureParams, - tuneFileRead)); + _oldposoccfile = makePosOccRead(name, + _dictFile.get(), + featureParams, + tuneFileRead); vespalib::string cname = prefix + "dictionary"; if (!_dictFile->open(cname, tuneFileRead)) { @@ -138,7 +136,7 @@ FieldReader::open(const vespalib::string &prefix, } // open posocc.dat - if (!_oldposoccfile->open(name, tuneFileRead)) { + if (!_oldposoccfile || !_oldposoccfile->open(name, tuneFileRead)) { LOG(error, "Could not open posocc file %s for read", name.c_str()); diff --git a/searchlib/src/vespa/searchlib/diskindex/fieldwriter.cpp b/searchlib/src/vespa/searchlib/diskindex/fieldwriter.cpp index 8c2b33a933e..7c52727f90e 100644 --- a/searchlib/src/vespa/searchlib/diskindex/fieldwriter.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/fieldwriter.cpp @@ -66,14 +66,12 @@ FieldWriter::open(const vespalib::string &prefix, _dictFile = std::make_unique<PageDict4FileSeqWrite>(); _dictFile->setParams(countParams); - _posoccfile.reset(diskindex::makePosOccWrite(name, - _dictFile.get(), - dynamicKPosOccFormat, - params, - featureParams, - schema, - indexId, - tuneFileWrite)); + _posoccfile = diskindex::makePosOccWrite(_dictFile.get(), + dynamicKPosOccFormat, + params, + featureParams, + schema, + indexId); vespalib::string cname = _prefix + "dictionary"; // Open output dictionary file |