1
0

codec_impl.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Tencent is pleased to support the open source community by making wwsearch
  3. * available.
  4. *
  5. * Copyright (C) 2018-present Tencent. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  8. * use this file except in compliance with the License. You may obtain a copy of
  9. * the License at
  10. *
  11. * https://opensource.org/licenses/Apache-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OF ANY KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations under the License.
  17. */
  18. #pragma once
  19. #include "codec.h"
  20. namespace wwsearch {
  21. /* Notice : This Codec staff aims to work for forward, inverted, docvalue table.
  22. *
  23. * 1. In forward table, the data looks like below :
  24. * key | value
  25. * table_id[bussiness_type, | document lsmstore pb
  26. * partition_set],document_id |(only including store flag field)
  27. *
  28. * 2. In inverted table, the data looks like :
  29. * key | value
  30. * table_id[bussiness_type, |
  31. * partition_set],field_id,term | doc_id3,doc_id2,doc_id1
  32. *
  33. * 3. In docvalue table, the data looks like :
  34. * key | value
  35. * table_id[bussiness_type, | document lsmstore pb
  36. * partition_set],document_id |(only including docvalue flag fields)
  37. *
  38. *
  39. * All key&value encode/decode depends on this class.
  40. *
  41. * Besides, inverted table 's dos_list support fix-length format and
  42. * compression format.
  43. *
  44. * 1. Fix-length format looks likes:
  45. * [header(1B)][doc_id(8B)][doc_state(1B)]...[doc_id(8B)][doc_state(1B)]
  46. * doc_id is uint64_t
  47. * doc_state is uint8_t which stands for Add/Delete
  48. *
  49. * 2. Compression format
  50. * [header(1B)][delete flag block][(doc_id,doc_state) variable length]
  51. * ...[(doc_id,doc_state) variable length]
  52. * Use delta compression at the same time.
  53. */
  54. class CodecImpl : public Codec {
  55. private:
  56. DocListCompressionType compression_type_;
  57. public:
  58. CodecImpl();
  59. virtual ~CodecImpl();
  60. virtual void EncodeStoredFieldKey(const TableID& table,
  61. const DocumentID& document_id,
  62. std::string& document_key) override;
  63. virtual std::string DebugStoredFieldKey(const std::string& key) override;
  64. virtual void EncodeMetaKey(const TableID& table,
  65. std::string& meta_key) override;
  66. virtual std::string DebugMetaKey(const std::string& key) override;
  67. virtual void EncodeInvertedKey(const TableID& table, const FieldID& field_id,
  68. const std::string& term,
  69. std::string& key) override;
  70. virtual bool DecodeInvertedKey(const Slice& inverted_key,
  71. uint8_t* business_type,
  72. uint64_t* partition_set /*corp_id*/,
  73. uint8_t* field_id, std::string* term) override;
  74. virtual std::string DebugInvertedKey(const std::string& key) override;
  75. virtual DocListWriterCodec* NewDocListWriterCodec() override;
  76. virtual void ReleaseDocListWriterCodec(DocListWriterCodec*) override;
  77. virtual DocListWriterCodec* NewOrderDocListWriterCodec() override;
  78. virtual void ReleaseOrderDocListWriterCodec(DocListWriterCodec*) override;
  79. virtual DocListReaderCodec* NewDocListReaderCodec(const char* data,
  80. size_t data_len,
  81. int field_id = -1) override;
  82. virtual void ReleaseDocListReaderCodec(DocListReaderCodec*) override;
  83. virtual DocListReaderCodecGreater GetGreaterComparator() override;
  84. virtual bool DecodeDocListToFixBytes(const char* data, size_t data_len,
  85. bool& use_buffer,
  86. std::string& buffer) override;
  87. virtual void SetDocListCompressionType(DocListCompressionType type) override;
  88. virtual void EncodeSequenceMetaKey(const TableID& table,
  89. std::string& meta_key) override;
  90. virtual void EncodeSequenceMappingKey(const TableID& table,
  91. std::string& user_id,
  92. std::string& meta_key) override;
  93. private:
  94. };
  95. } // namespace wwsearch