From d2cf4b02019e93251856f0e1df6c0cdefb06850d Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Sat, 5 Aug 2023 12:10:03 +0530 Subject: [PATCH 1/5] Fix nested field with regex name in schema. --- src/field.cpp | 2 +- test/collection_nested_fields_test.cpp | 36 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/field.cpp b/src/field.cpp index ca7d5149..bccd8da5 100644 --- a/src/field.cpp +++ b/src/field.cpp @@ -852,7 +852,7 @@ bool field::flatten_obj(nlohmann::json& doc, nlohmann::json& value, bool has_arr continue; } - if(std::regex_match(flat_name, std::regex(flat_name))) { + if(std::regex_match(flat_name, std::regex(dynamic_field.name))) { detected_type = dynamic_field.type; found_dynamic_field = true; break; diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cpp index 20490d4a..a2eef13d 100644 --- a/test/collection_nested_fields_test.cpp +++ b/test/collection_nested_fields_test.cpp @@ -2867,6 +2867,42 @@ TEST_F(CollectionNestedFieldsTest, FloatInsideNestedObject) { ASSERT_TRUE(add_op.ok()); } +TEST_F(CollectionNestedFieldsTest, NestedFieldWithRegexName) { + nlohmann::json schema = R"({ + "name": "coll1", + "enable_nested_fields": true, + "fields": [ + {"name":"titles", "type":"object"}, + {"name": "titles\\..*", "type":"string"}, + {"name":"start_date", "type":"object"}, + {"name":"start_date\\..*", "type":"int32", "facet":true, "optional":true} + ] + })"_json; + + auto op = collectionManager.create_collection(schema); + ASSERT_TRUE(op.ok()); + Collection *coll1 = op.get(); + + auto doc1 = R"({ + "titles": { + "en": "Foobar baz" + }, + "start_date": { + "year": 2020, + "month": 2, + "day": 3 + } + })"_json; + + auto add_op = coll1->add(doc1.dump(), CREATE); + ASSERT_TRUE(add_op.ok()); + + auto results = coll1->search("foobar", {"titles.en"}, "start_date.year: 2020", {}, {}, {2}, 10, + 1, FREQUENCY, {true}).get(); + + ASSERT_EQ(1, results["found"].get()); +} + TEST_F(CollectionNestedFieldsTest, HighlightOnFlatFieldWithSnippeting) { std::vector fields = {field("title", field_types::STRING, false), field("body", field_types::STRING, false)}; From cf592caf3c332255ffeaf904bc26546241a64ec5 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Sat, 5 Aug 2023 15:14:30 +0530 Subject: [PATCH 2/5] Sentencepiece: use build tmp dir instead of install dir. --- bazel/sentencepiece.BUILD | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bazel/sentencepiece.BUILD b/bazel/sentencepiece.BUILD index 6958221c..05967725 100644 --- a/bazel/sentencepiece.BUILD +++ b/bazel/sentencepiece.BUILD @@ -30,9 +30,9 @@ cmake( install = False, cache_entries = { 'SPM_USE_BUILTIN_PROTOBUF': 'OFF', - 'Protobuf_LIBRARY': '$INSTALLDIR/../../com_google_protobuf/libprotobuf.a', - 'Protobuf_LITE_LIBRARY': '$INSTALLDIR/../../com_google_protobuf/libprotobuf-lite.a', - 'Protobuf_PROTOC_EXECUTABLE': '$INSTALLDIR/../../com_google_protobuf/protoc', + 'Protobuf_LIBRARY': '$$BUILD_TMPDIR$$/../../com_google_protobuf/libprotobuf.a', + 'Protobuf_LITE_LIBRARY': '$$BUILD_TMPDIR$$/../../com_google_protobuf/libprotobuf-lite.a', + 'Protobuf_PROTOC_EXECUTABLE': '$$BUILD_TMPDIR$$/../../com_google_protobuf/protoc', 'Protobuf_INCLUDE_DIR': '$EXT_BUILD_ROOT/external/com_google_protobuf/src', 'CMAKE_POLICY_DEFAULT_CMP0111':'OLD' }, @@ -44,7 +44,7 @@ cmake( ], tags = ["no-sandbox"], postfix_script= """ -echo "Intstalling sentencepiece" -cp $BUILD_TMPDIR/src/libsentencepiece.a $INSTALLDIR/lib/libsentencepiece.a -""" + echo "Installing sentencepiece" + cp $BUILD_TMPDIR/src/libsentencepiece.a $INSTALLDIR/lib/libsentencepiece.a + """ ) From d327074c5482252eae46617f4770ff155ad7ee24 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Sat, 5 Aug 2023 16:25:03 +0530 Subject: [PATCH 3/5] CI: Use artifacts for bazel cache --- .github/workflows/tests.yml | 53 ++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f3c71bd1..1051cfb3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,7 +1,6 @@ name: tests -#on: [push, pull_request] -on: workflow_dispatch +on: [push, pull_request] # Cancel previous running if a new push is made # Source: https://stackoverflow.com/a/72408109/123545 @@ -21,40 +20,62 @@ jobs: run: | sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test sudo apt-get update - + sudo apt-get install -y g++-10 make git zlib1g-dev m4 - + # Define the compiler sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 30 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 30 - + sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 sudo update-alternatives --set cc /usr/bin/gcc - + sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 sudo update-alternatives --set c++ /usr/bin/g++ - name: Set up Bazel uses: bazelbuild/setup-bazelisk@v2 - - name: Restore bazel cache - uses: actions/cache@v3 + - name: Download bazel cache + uses: dawidd6/action-download-artifact@v2 with: - path: | - ~/.cache/bazel - # Source: https://github.com/actions/cache/blob/67b839edb68371cc5014f6cea11c9aa77238de78/examples.md#linux-2 - key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel') }} - restore-keys: | - ${{ runner.os }}-bazel- + name: bazel-cache + search_artifacts: true + workflow_conclusion: "" + if_no_artifact_found: warn + + - name: Uncompress bazel cache + run: | + mkdir -p ~/.cache/bazel + tar_file="bazel-cache.tar.gz" && \ + [ -f "$tar_file" ] && \ + tar -xzvf "$tar_file" -C ~/.cache/bazel && \ + rm bazel-cache.tar.gz + exit 0 - name: Build Typesense run: bazel build //:typesense-server - name: Run tests - run: bazel test --test_output=all -- //:typesense-test + run: bazel test //:typesense-test + + - name: Compress bazel cache + if: always() + run: | + tar -czvf bazel-cache.tar.gz -C ~/.cache/bazel . + + - name: Save bazel cache + uses: actions/upload-artifact@v3 + if: always() + with: + name: bazel-cache + path: bazel-cache.tar.gz + if-no-files-found: warn + retention-days: 10 # Source: https://github.com/actions/upload-artifact/issues/92#issuecomment-1080347032 - - run: echo "BAZEL_BIN_FULL_PATH=$(readlink -f bazel-bin)" >> $GITHUB_ENV + - name: Set BAZEL_BIN_FULL_PATH + run: echo "BAZEL_BIN_FULL_PATH=$(readlink -f bazel-bin)" >> $GITHUB_ENV - name: Save build artifacts uses: actions/upload-artifact@v3 with: From 406cafe4c795a78ff4578cfbb92ce51946ca4aed Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Sat, 5 Aug 2023 16:33:32 +0530 Subject: [PATCH 4/5] Disable CI again. --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1051cfb3..e9802186 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,7 @@ name: tests -on: [push, pull_request] +on: workflow_dispatch +#on: [push, pull_request] # Cancel previous running if a new push is made # Source: https://stackoverflow.com/a/72408109/123545 From 6c9a000bd8e3db2de65432a7793e6b39494f1d51 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Sat, 5 Aug 2023 16:58:02 +0530 Subject: [PATCH 5/5] Build protobuf first before building Typesense. --- .github/workflows/tests.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e9802186..649da61a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,7 +1,7 @@ name: tests -on: workflow_dispatch -#on: [push, pull_request] +#on: workflow_dispatch +on: [push, pull_request] # Cancel previous running if a new push is made # Source: https://stackoverflow.com/a/72408109/123545 @@ -54,6 +54,13 @@ jobs: rm bazel-cache.tar.gz exit 0 + - name: Build protobuf deps + run: | + bazel build @com_google_protobuf//:protobuf_headers + bazel build @com_google_protobuf//:protobuf_lite + bazel build @com_google_protobuf//:protobuf + bazel build @com_google_protobuf//:protoc + - name: Build Typesense run: bazel build //:typesense-server