This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 4fb22bec Add a noindex flag to search metadata (#2094)
4fb22bec is described below

commit 4fb22bec34560a6f1776763684e70bb8943d2f14
Author: Twice <[email protected]>
AuthorDate: Sat Feb 10 10:45:55 2024 +0900

    Add a noindex flag to search metadata (#2094)
---
 src/search/search_encoding.h | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/search/search_encoding.h b/src/search/search_encoding.h
index a0517902..deea106b 100644
--- a/src/search/search_encoding.h
+++ b/src/search/search_encoding.h
@@ -65,22 +65,48 @@ struct SearchPrefixesMetadata {
   }
 };
 
+struct SearchFieldMetadata {
+  bool noindex = false;
+
+  // flag: <noindex: 1 bit> <reserved: 7 bit>
+  uint8_t MakeFlag() const { return noindex; }
+
+  void DecodeFlag(uint8_t flag) { noindex = flag & 1; }
+
+  void Encode(std::string *dst) const { PutFixed8(dst, MakeFlag()); }
+
+  rocksdb::Status Decode(Slice *input) {
+    uint8_t flag = 0;
+    if (!GetFixed8(input, &flag)) {
+      return rocksdb::Status::Corruption(kErrorInsufficientLength);
+    }
+
+    DecodeFlag(flag);
+    return rocksdb::Status::OK();
+  }
+};
+
 inline std::string ConstructTagFieldMetadataSubkey(std::string_view 
field_name) {
   std::string res = {(char)SearchSubkeyType::TAG_FIELD_META};
   res.append(field_name);
   return res;
 }
 
-struct SearchTagFieldMetadata {
+struct SearchTagFieldMetadata : SearchFieldMetadata {
   char separator = ',';
   bool case_sensitive = false;
 
   void Encode(std::string *dst) const {
+    SearchFieldMetadata::Encode(dst);
     PutFixed8(dst, separator);
     PutFixed8(dst, case_sensitive);
   }
 
   rocksdb::Status Decode(Slice *input) {
+    if (auto s = SearchFieldMetadata::Decode(input); !s.ok()) {
+      return s;
+    }
+
     if (input->size() < 8 + 8) {
       return rocksdb::Status::Corruption(kErrorInsufficientLength);
     }
@@ -97,6 +123,8 @@ inline std::string 
ConstructNumericFieldMetadataSubkey(std::string_view field_na
   return res;
 }
 
+struct SearchNumericFieldMetadata : SearchFieldMetadata {};
+
 inline std::string ConstructTagFieldSubkey(std::string_view field_name, 
std::string_view tag, std::string_view key) {
   std::string res = {(char)SearchSubkeyType::TAG_FIELD};
   PutFixed32(&res, field_name.size());

Reply via email to