codec.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_doclist.h"
  20. #include "coding.h"
  21. #include "doclist_compression.h"
  22. #include "header.h"
  23. #include "search_slice.h"
  24. #include "storage_type.h"
  25. namespace wwsearch {
  26. /* Notice : This Codec staff aims to work for forward,inverted table.
  27. * All key&value encode/decode depends on this class.
  28. * Besides, inverted table 's dos_list support fix-length format and
  29. * compression format.
  30. * You could find more information in codec_impl.h
  31. */
  32. class Codec {
  33. private:
  34. public:
  35. virtual ~Codec();
  36. // Stored field
  37. virtual void EncodeStoredFieldKey(const TableID& table,
  38. const DocumentID& document_id,
  39. std::string& document_key) = 0;
  40. virtual std::string DebugStoredFieldKey(const std::string& key) = 0;
  41. // Invert index
  42. virtual void EncodeInvertedKey(const TableID& table, const FieldID& field_id,
  43. const std::string& term, std::string& key) = 0;
  44. virtual bool DecodeInvertedKey(const Slice& inverted_key,
  45. uint8_t* business_type,
  46. uint64_t* partition_set /*corp_id*/,
  47. uint8_t* field_id, std::string* term) = 0;
  48. virtual std::string DebugInvertedKey(const std::string& key) = 0;
  49. // write
  50. virtual DocListWriterCodec* NewDocListWriterCodec() = 0;
  51. virtual void ReleaseDocListWriterCodec(DocListWriterCodec*) = 0;
  52. virtual DocListWriterCodec* NewOrderDocListWriterCodec() = 0;
  53. virtual void ReleaseOrderDocListWriterCodec(DocListWriterCodec*) = 0;
  54. // read
  55. virtual DocListReaderCodec* NewDocListReaderCodec(const char* data,
  56. size_t data_len,
  57. int field_id = -1) = 0;
  58. virtual void ReleaseDocListReaderCodec(DocListReaderCodec*) = 0;
  59. virtual DocListReaderCodecGreater GetGreaterComparator() = 0;
  60. // Try to decode doclist to fix array
  61. // If success,return true
  62. // If input data is fix array,use_buffer will set to false and will not
  63. // set buffer. if input data is varint encoding,use_buffer will set to
  64. // true and will set to buffer.
  65. virtual bool DecodeDocListToFixBytes(const char* data, size_t data_len,
  66. bool& use_buffer,
  67. std::string& buffer) = 0;
  68. // Doc value
  69. // Meta
  70. virtual void EncodeMetaKey(const TableID& table, std::string& meta_key) = 0;
  71. virtual std::string DebugMetaKey(const std::string& key) = 0;
  72. virtual void EncodeSequenceMetaKey(
  73. const TableID& table, std::string& meta_key) = 0; // store max sequence
  74. virtual void EncodeSequenceMappingKey(
  75. const TableID& table, std::string& user_id,
  76. std::string& meta_key) = 0; // store user's key mapping to docid
  77. // Dictionary
  78. // DocListCompression
  79. virtual void SetDocListCompressionType(DocListCompressionType type) = 0;
  80. private:
  81. };
  82. } // namespace wwsearch