Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Cmake compatible bazel build.

Kishore Nallan652472f32a37
diff --git a/.gitignore b/.gitignore
index d49bd333..9d0ed87d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
.idea
*.iml
external*
+external
/build*
test-build*
cmake-build*
diff --git a/BUILD b/BUILD
index a0519093..e70b52ed 100644
--- a/BUILD
+++ b/BUILD
@@ -51,6 +51,7 @@ cc_library(
"@lrucache",
"@rocksdb",
"@s2geometry",
+ "@hnsw",
],
)
@@ -117,6 +118,36 @@ cc_test(
data = [
":test_data_files",
"@libart//:data",
+ "@token_offsets//file",
+ ],
+ deps = [
+ ":common_deps",
+ "@com_google_googletest//:gtest",
+ ],
+ defines = [
+ "ROOT_DIR="
+ ],
+)
+
+genrule(
+ name = "write_bazel_bin",
+ srcs = [],
+ outs = ["bazel_bin_dir.txt"],
+ cmd = "echo -n $(BINDIR) > $@",
+)
+
+cc_library(
+ name = "build_deps_all",
+ srcs = [
+ ":src_files",
+ ":test_src_files",
+ ],
+ copts = COPTS,
+ data = [
+ ":test_data_files",
+ "@libart//:data",
+ "@token_offsets//file",
+ ":write_bazel_bin"
],
deps = [
":common_deps",
diff --git a/WORKSPACE b/WORKSPACE
index 34b363f1..e13cc6d2 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,5 +1,6 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
git_repository(
name = "com_grail_bazel_compdb",
@@ -142,6 +143,13 @@ new_git_repository(
remote = "https://github.com/typesense/kakasi.git",
)
+new_git_repository(
+ name = "hnsw",
+ build_file = "//bazel:hnsw.BUILD",
+ commit = "21de18ffabea1a9d1e8b16b49afc6045d7707e4c",
+ remote = "https://github.com/typesense/hnswlib.git",
+)
+
http_archive(
name = "com_github_gflags_gflags",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
@@ -254,3 +262,10 @@ http_archive(
strip_prefix = "libiconv-1.17",
urls = ["https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz"],
)
+
+http_file(
+ name = "token_offsets",
+ downloaded_file_path = "token_offsets.txt",
+ sha256 = "55c1c510ca6335c049f5696f3b94ac7be61e84f3e27cd8169021929b3db99651",
+ urls = ["https://gist.githubusercontent.com/kishorenc/1d330714eb07019f210f16ccb3991217/raw/bd52e05375d305d5aaa7ac06219af999726933a4/token_offsets.log"],
+)
diff --git a/bazel/hnsw.BUILD b/bazel/hnsw.BUILD
new file mode 100644
index 00000000..efca11b1
--- /dev/null
+++ b/bazel/hnsw.BUILD
@@ -0,0 +1,8 @@
+load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
+
+package(default_visibility = ["//visibility:public"])
+
+cc_library(
+ name = "hnsw",
+ hdrs = glob(["hnswlib/**/*.h"]),
+)
diff --git a/bazel/test_files.BUILD b/bazel/test_files.BUILD
new file mode 100644
index 00000000..3f75ec28
--- /dev/null
+++ b/bazel/test_files.BUILD
@@ -0,0 +1,8 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
+
+http_file(
+ name = "token_offsets",
+ downloaded_file_path = "token_offsets.txt",
+ sha256 = "55c1c510ca6335c049f5696f3b94ac7be61e84f3e27cd8169021929b3db99651",
+ urls = ["https://gist.githubusercontent.com/kishorenc/1d330714eb07019f210f16ccb3991217/raw/bd52e05375d305d5aaa7ac06219af999726933a4/token_offsets.log"],
+)
diff --git a/cmake/H2O.cmake b/cmake/H2O.cmake
index 095759e2..6b49e16d 100644
--- a/cmake/H2O.cmake
+++ b/cmake/H2O.cmake
@@ -1,6 +1,6 @@
# Download and build H2O
-set(H2O_VERSION 6dda7d6f21610ecd5256543384fa4b4b345a88ac)
+set(H2O_VERSION 1491a703195790278091fd7aee547fbba78e89af)
set(H2O_NAME h2o-${H2O_VERSION})
set(H2O_TAR_PATH ${DEP_ROOT_DIR}/${H2O_NAME}.tar.gz)
diff --git a/cmake/TestResources.cmake b/cmake/TestResources.cmake
index 5d424811..84865d27 100644
--- a/cmake/TestResources.cmake
+++ b/cmake/TestResources.cmake
@@ -1,15 +1,25 @@
# Download test resources
set(ART_VERSION bbbf588bca55bce095538ee8ca8b422904baebc5)
-set(TEST_RESOURCES_DIR ${CMAKE_SOURCE_DIR}/build/test_resources)
-set(ART_WORDS_PATH ${TEST_RESOURCES_DIR}/words.txt)
-set(ART_UUID_PATH ${TEST_RESOURCES_DIR}/uuid.txt)
-set(TOKEN_OFFSETS_PATH ${TEST_RESOURCES_DIR}/token_offsets.txt)
+set(TEST_RESOURCES_DIR ${CMAKE_SOURCE_DIR}/external/ CACHE STRING "")
+set(ART_WORDS_PATH ${TEST_RESOURCES_DIR}/libart/tests/words.txt)
+set(ART_UUID_PATH ${TEST_RESOURCES_DIR}/libart/tests/uuid.txt)
+set(TOKEN_OFFSETS_PATH ${TEST_RESOURCES_DIR}/token_offsets/file/token_offsets.txt)
if(NOT EXISTS ${TEST_RESOURCES_DIR})
file(MAKE_DIRECTORY ${TEST_RESOURCES_DIR})
endif()
+if(NOT EXISTS ${TEST_RESOURCES_DIR}/libart)
+ file(MAKE_DIRECTORY ${TEST_RESOURCES_DIR}/libart)
+ file(MAKE_DIRECTORY ${TEST_RESOURCES_DIR}/libart/tests)
+endif()
+
+if(NOT EXISTS ${TEST_RESOURCES_DIR}/token_offsets)
+ file(MAKE_DIRECTORY ${TEST_RESOURCES_DIR}/token_offsets)
+ file(MAKE_DIRECTORY ${TEST_RESOURCES_DIR}/token_offsets/file)
+endif()
+
if(NOT EXISTS ${ART_WORDS_PATH} AND BUILD_DEPS STREQUAL "yes")
message(STATUS "Downloading test resource - words.txt")
file(DOWNLOAD https://raw.githubusercontent.com/kishorenc/libart/${ART_VERSION}/tests/words.txt ${ART_WORDS_PATH})
diff --git a/include/app_metrics.h b/include/app_metrics.h
index 5b9d388b..3fd75632 100644
--- a/include/app_metrics.h
+++ b/include/app_metrics.h
@@ -3,7 +3,7 @@
#include "sparsepp.h"
#include "json.hpp"
#include "logger.h"
-#include "config.h"
+#include "tsconfig.h"
#include <mutex>
#include <string>
#include <shared_mutex>
diff --git a/include/batched_indexer.h b/include/batched_indexer.h
index 95073747..04afba58 100644
--- a/include/batched_indexer.h
+++ b/include/batched_indexer.h
@@ -6,7 +6,7 @@
#include "http_data.h"
#include "threadpool.h"
#include "http_server.h"
-#include "config.h"
+#include "tsconfig.h"
class BatchedIndexer {
private:
diff --git a/include/http_data.h b/include/http_data.h
index 9c4228d2..5fb9fab3 100644
--- a/include/http_data.h
+++ b/include/http_data.h
@@ -11,7 +11,7 @@
#include "string_utils.h"
#include "logger.h"
#include "app_metrics.h"
-#include "config.h"
+#include "tsconfig.h"
#define H2O_USE_LIBUV 0
extern "C" {
diff --git a/include/option.h b/include/option.h
index d282712e..0f8c49e0 100644
--- a/include/option.h
+++ b/include/option.h
@@ -1,5 +1,6 @@
#pragma once
#include <stdint.h>
+#include <string>
template <typename T=uint32_t>
class Option {
diff --git a/include/config.h b/include/tsconfig.h
similarity index 100%
rename from include/config.h
rename to include/tsconfig.h
diff --git a/include/typesense_server_utils.h b/include/typesense_server_utils.h
index e4c61909..6ab300b2 100644
--- a/include/typesense_server_utils.h
+++ b/include/typesense_server_utils.h
@@ -4,7 +4,7 @@
#include <string>
#include <iostream>
#include <cmdline.h>
-#include "config.h"
+#include "tsconfig.h"
#include "store.h"
#include "collection_manager.h"
#include <csignal>
diff --git a/src/main/typesense_server.cpp b/src/main/typesense_server.cpp
index 33f2c6a0..79479ab7 100644
--- a/src/main/typesense_server.cpp
+++ b/src/main/typesense_server.cpp
@@ -1,6 +1,6 @@
#include "typesense_server_utils.h"
#include "core_api.h"
-#include "config.h"
+#include "tsconfig.h"
#include "stackprinter.h"
#include "backward.hpp"
diff --git a/src/config.cpp b/src/tsconfig.cpp
similarity index 98%
rename from src/config.cpp
rename to src/tsconfig.cpp
index de599c71..a50664c6 100644
--- a/src/config.cpp
+++ b/src/tsconfig.cpp
@@ -1,6 +1,6 @@
-#include "config.h"
#include "option.h"
#include "json.hpp"
+#include "tsconfig.h"
Option<bool> Config::update_config(const nlohmann::json& req_json) {
bool found_config = false;
diff --git a/test/art_test.cpp b/test/art_test.cpp
index 0b91f092..cbcb4a6a 100644
--- a/test/art_test.cpp
+++ b/test/art_test.cpp
@@ -8,10 +8,10 @@
#include <chrono>
#include <posting.h>
-#define words_file_path std::string("external/libart/tests/words.txt").c_str()
-#define uuid_file_path std::string("external/libart/tests/uuid.txt").c_str()
-#define skus_file_path std::string("test/skus.txt").c_str()
-#define ill_file_path std::string("test/ill.txt").c_str()
+#define words_file_path (std::string(ROOT_DIR) + std::string("external/libart/tests/words.txt")).c_str()
+#define uuid_file_path (std::string(ROOT_DIR) + std::string("external/libart/tests/uuid.txt")).c_str()
+#define skus_file_path (std::string(ROOT_DIR) + std::string("test/skus.txt")).c_str()
+#define ill_file_path (std::string(ROOT_DIR) + std::string("test/ill.txt")).c_str()
art_document get_document(uint32_t id) {
art_document document(id, id, {0});
diff --git a/test/collection_all_fields_test.cpp b/test/collection_all_fields_test.cpp
index d2e419db..e3f7f961 100644
--- a/test/collection_all_fields_test.cpp
+++ b/test/collection_all_fields_test.cpp
@@ -38,7 +38,7 @@ protected:
TEST_F(CollectionAllFieldsTest, IndexDocsWithoutSchema) {
Collection *coll1;
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::vector<field> fields = {};
std::vector<sort_by> sort_fields = { sort_by("points", "DESC") };
diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cpp
index fe14e6ca..8b0f9717 100644
--- a/test/collection_faceting_test.cpp
+++ b/test/collection_faceting_test.cpp
@@ -38,7 +38,7 @@ protected:
TEST_F(CollectionFacetingTest, FacetCounts) {
Collection *coll_array_fields;
- std::ifstream infile("test/numeric_array_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
std::vector<field> fields = {field("name", field_types::STRING, false),
field("name_facet", field_types::STRING, true),
field("age", field_types::INT32, true),
@@ -586,7 +586,7 @@ TEST_F(CollectionFacetingTest, FacetCountsHighlighting) {
TEST_F(CollectionFacetingTest, FacetStatOnFloatFields) {
Collection *coll_float_fields;
- std::ifstream infile("test/float_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/float_documents.jsonl");
std::vector<field> fields = {
field("title", field_types::STRING, false),
field("score", field_types::FLOAT, false),
diff --git a/test/collection_filtering_test.cpp b/test/collection_filtering_test.cpp
index f0fbfe72..153fe084 100644
--- a/test/collection_filtering_test.cpp
+++ b/test/collection_filtering_test.cpp
@@ -38,7 +38,7 @@ protected:
TEST_F(CollectionFilteringTest, FilterOnTextFields) {
Collection *coll_array_fields;
- std::ifstream infile("test/numeric_array_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
std::vector<field> fields = {
field("name", field_types::STRING, false),
field("age", field_types::INT32, false),
@@ -140,7 +140,7 @@ TEST_F(CollectionFilteringTest, FilterOnTextFields) {
TEST_F(CollectionFilteringTest, FacetFieldStringFiltering) {
Collection *coll_str;
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::vector<field> fields = {
field("title", field_types::STRING, false),
field("starring", field_types::STRING, true),
@@ -208,7 +208,7 @@ TEST_F(CollectionFilteringTest, FacetFieldStringFiltering) {
TEST_F(CollectionFilteringTest, FacetFieldStringArrayFiltering) {
Collection *coll_array_fields;
- std::ifstream infile("test/numeric_array_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
std::vector<field> fields = {field("name", field_types::STRING, false),
field("name_facet", field_types::STRING, true),
field("age", field_types::INT32, true),
@@ -325,7 +325,7 @@ TEST_F(CollectionFilteringTest, HandleBadlyFormedFilterQuery) {
// should not crash when filter query is malformed!
Collection *coll_array_fields;
- std::ifstream infile("test/numeric_array_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
std::vector<field> fields = {field("name", field_types::STRING, false), field("age", field_types::INT32, false),
field("years", field_types::INT32_ARRAY, false),
field("timestamps", field_types::INT64_ARRAY, false),
@@ -393,7 +393,7 @@ TEST_F(CollectionFilteringTest, HandleBadlyFormedFilterQuery) {
TEST_F(CollectionFilteringTest, FilterAndQueryFieldRestrictions) {
Collection *coll_mul_fields;
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::vector<field> fields = {
field("title", field_types::STRING, false),
field("starring", field_types::STRING, false),
@@ -502,7 +502,7 @@ TEST_F(CollectionFilteringTest, FilterAndQueryFieldRestrictions) {
TEST_F(CollectionFilteringTest, FilterOnNumericFields) {
Collection *coll_array_fields;
- std::ifstream infile("test/numeric_array_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
std::vector<field> fields = {
field("name", field_types::STRING, false),
field("rating", field_types::FLOAT, false),
@@ -701,7 +701,7 @@ TEST_F(CollectionFilteringTest, FilterOnNumericFields) {
TEST_F(CollectionFilteringTest, FilterOnFloatFields) {
Collection *coll_array_fields;
- std::ifstream infile("test/numeric_array_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
std::vector<field> fields = {
field("name", field_types::STRING, false),
field("age", field_types::INT32, false),
@@ -897,7 +897,7 @@ TEST_F(CollectionFilteringTest, FilterOnNegativeNumericalFields) {
TEST_F(CollectionFilteringTest, ComparatorsOnMultiValuedNumericalField) {
Collection *coll_array_fields;
- std::ifstream infile("test/numeric_array_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
std::vector<field> fields = {
field("name", field_types::STRING, false),
field("age", field_types::INT32, false),
@@ -1991,7 +1991,7 @@ TEST_F(CollectionFilteringTest, RangeFilterOnTimestamp) {
TEST_F(CollectionFilteringTest, QueryBoolFields) {
Collection *coll_bool;
- std::ifstream infile("test/bool_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/bool_documents.jsonl");
std::vector<field> fields = {
field("popular", field_types::BOOL, false),
field("title", field_types::STRING, false),
diff --git a/test/collection_grouping_test.cpp b/test/collection_grouping_test.cpp
index 557136c5..9835f44a 100644
--- a/test/collection_grouping_test.cpp
+++ b/test/collection_grouping_test.cpp
@@ -35,7 +35,7 @@ protected:
coll_group = collectionManager.create_collection("coll_group", 4, fields, "rating").get();
}
- std::ifstream infile("test/group_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/group_documents.jsonl");
std::string json_line;
diff --git a/test/collection_manager_test.cpp b/test/collection_manager_test.cpp
index c47e14e0..c20edb12 100644
--- a/test/collection_manager_test.cpp
+++ b/test/collection_manager_test.cpp
@@ -332,7 +332,7 @@ TEST_F(CollectionManagerTest, GetAllCollections) {
}
TEST_F(CollectionManagerTest, RestoreRecordsOnRestart) {
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::string json_line;
while (std::getline(infile, json_line)) {
@@ -555,7 +555,7 @@ TEST_F(CollectionManagerTest, VerifyEmbeddedParametersOfScopedAPIKey) {
TEST_F(CollectionManagerTest, RestoreAutoSchemaDocsOnRestart) {
Collection *coll1;
- std::ifstream infile("test/optional_fields.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/optional_fields.jsonl");
std::vector<field> fields = {
field("max", field_types::INT32, false)
};
@@ -733,7 +733,7 @@ TEST_F(CollectionManagerTest, RestoreNestedDocsOnRestart) {
}
TEST_F(CollectionManagerTest, DropCollectionCleanly) {
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::string json_line;
while (std::getline(infile, json_line)) {
diff --git a/test/collection_override_test.cpp b/test/collection_override_test.cpp
index 38ca9598..8c5de954 100644
--- a/test/collection_override_test.cpp
+++ b/test/collection_override_test.cpp
@@ -22,7 +22,7 @@ protected:
collectionManager.init(store, 1.0, "auth_key", quit);
collectionManager.load(8, 1000);
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::vector<field> fields = {
field("title", field_types::STRING, false),
field("starring", field_types::STRING, true),
diff --git a/test/collection_sorting_test.cpp b/test/collection_sorting_test.cpp
index 197ac28e..80ffbaf5 100644
--- a/test/collection_sorting_test.cpp
+++ b/test/collection_sorting_test.cpp
@@ -38,7 +38,7 @@ protected:
TEST_F(CollectionSortingTest, SortingOrder) {
Collection *coll_mul_fields;
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::vector<field> fields = {field("title", field_types::STRING, false),
field("starring", field_types::STRING, false),
field("points", field_types::INT32, false),
@@ -145,7 +145,7 @@ TEST_F(CollectionSortingTest, DefaultSortingFieldValidations) {
TEST_F(CollectionSortingTest, NoDefaultSortingField) {
Collection *coll1;
- std::ifstream infile("test/documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/documents.jsonl");
std::vector<field> fields = {field("title", field_types::STRING, false),
field("points", field_types::INT32, false)};
@@ -281,7 +281,7 @@ TEST_F(CollectionSortingTest, TokenOrderingOnFloatValue) {
TEST_F(CollectionSortingTest, Int64AsDefaultSortingField) {
Collection *coll_mul_fields;
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::vector<field> fields = {field("title", field_types::STRING, false),
field("starring", field_types::STRING, false),
field("points", field_types::INT64, false),
@@ -337,7 +337,7 @@ TEST_F(CollectionSortingTest, Int64AsDefaultSortingField) {
TEST_F(CollectionSortingTest, SortOnFloatFields) {
Collection *coll_float_fields;
- std::ifstream infile("test/float_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/float_documents.jsonl");
std::vector<field> fields = {
field("title", field_types::STRING, false),
field("score", field_types::FLOAT, false),
diff --git a/test/collection_synonyms_test.cpp b/test/collection_synonyms_test.cpp
index bde88a64..0a5ee304 100644
--- a/test/collection_synonyms_test.cpp
+++ b/test/collection_synonyms_test.cpp
@@ -22,7 +22,7 @@ protected:
collectionManager.init(store, 1.0, "auth_key", quit);
collectionManager.load(8, 1000);
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::vector<field> fields = {
field("title", field_types::STRING, false),
field("starring", field_types::STRING, true),
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index c2add9b0..9aa327d9 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -27,7 +27,7 @@ protected:
collectionManager.init(store, 1.0, "auth_key", quit);
collectionManager.load(8, 1000);
- std::ifstream infile("test/documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/documents.jsonl");
std::vector<field> search_fields = {
field("title", field_types::STRING, false),
field("points", field_types::INT32, false)
@@ -53,7 +53,7 @@ protected:
infile.close();
- std::ifstream words_file("test/resources/common100_english.txt");
+ std::ifstream words_file(std::string(ROOT_DIR)+"test/resources/common100_english.txt");
std::stringstream strstream;
strstream << words_file.rdbuf();
words_file.close();
@@ -712,7 +712,7 @@ TEST_F(CollectionTest, MultiOccurrenceString) {
TEST_F(CollectionTest, ArrayStringFieldHighlight) {
Collection *coll_array_text;
- std::ifstream infile("test/array_text_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/array_text_documents.jsonl");
std::vector<field> fields = {
field("title", field_types::STRING, false),
field("tags", field_types::STRING_ARRAY, false),
@@ -890,7 +890,7 @@ TEST_F(CollectionTest, ArrayStringFieldHighlight) {
TEST_F(CollectionTest, MultipleFields) {
Collection *coll_mul_fields;
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::vector<field> fields = {
field("title", field_types::STRING, false),
field("starring", field_types::STRING, false),
@@ -1010,7 +1010,7 @@ TEST_F(CollectionTest, MultipleFields) {
TEST_F(CollectionTest, KeywordQueryReturnsResultsBasedOnPerPageParam) {
Collection *coll_mul_fields;
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::vector<field> fields = {
field("title", field_types::STRING, false),
field("starring", field_types::STRING, false),
@@ -1086,7 +1086,7 @@ std::vector<nlohmann::json> import_res_to_json(const std::vector<std::string>& i
TEST_F(CollectionTest, ImportDocumentsUpsert) {
Collection *coll_mul_fields;
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::stringstream strstream;
strstream << infile.rdbuf();
infile.close();
@@ -1509,7 +1509,7 @@ TEST_F(CollectionTest, ImportDocumentsUpsertOptional) {
TEST_F(CollectionTest, ImportDocuments) {
Collection *coll_mul_fields;
- std::ifstream infile("test/multi_field_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/multi_field_documents.jsonl");
std::stringstream strstream;
strstream << infile.rdbuf();
infile.close();
@@ -1648,7 +1648,7 @@ TEST_F(CollectionTest, SearchingWithMissingFields) {
// return error without crashing when searching for fields that do not conform to the schema
Collection *coll_array_fields;
- std::ifstream infile("test/numeric_array_documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
std::vector<field> fields = {field("name", field_types::STRING, false),
field("age", field_types::INT32, false),
field("years", field_types::INT32_ARRAY, false),
@@ -1872,7 +1872,7 @@ TEST_F(CollectionTest, AnIntegerCanBePassedToAFloatField) {
TEST_F(CollectionTest, DeletionOfADocument) {
collectionManager.drop_collection("collection");
- std::ifstream infile("test/documents.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/documents.jsonl");
std::vector<field> search_fields = {field("title", field_types::STRING, false),
field("points", field_types::INT32, false)};
@@ -2106,7 +2106,7 @@ TEST_F(CollectionTest, SearchLargeTextField) {
}
std::string json_line;
- std::ifstream infile("test/large_text_field.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/large_text_field.jsonl");
while (std::getline(infile, json_line)) {
coll_large_text->add(json_line);
@@ -2727,7 +2727,7 @@ TEST_F(CollectionTest, OptionalFields) {
coll1 = collectionManager.create_collection("coll1", 4, fields, "max").get();
}
- std::ifstream infile("test/optional_fields.jsonl");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/optional_fields.jsonl");
std::string json_line;
diff --git a/test/match_score_test.cpp b/test/match_score_test.cpp
index 512ccee5..ad0b2828 100644
--- a/test/match_score_test.cpp
+++ b/test/match_score_test.cpp
@@ -4,7 +4,7 @@
#include "posting_list.h"
#include <fstream>
-#define token_offsets_file_path std::string(std::string(ROOT_DIR)+"/build/test_resources/token_offsets.txt").c_str()
+#define token_offsets_file_path (std::string(ROOT_DIR) + std::string("external/token_offsets/file/token_offsets.txt")).c_str()
TEST(MatchTest, TokenOffsetsExceedWindowSize) {
std::vector<token_positions_t> token_positions = {
diff --git a/test/sorted_array_test.cpp b/test/sorted_array_test.cpp
index 826b333c..d1883a7c 100644
--- a/test/sorted_array_test.cpp
+++ b/test/sorted_array_test.cpp
@@ -208,7 +208,7 @@ TEST(SortedArrayTest, RemoveValues) {
}
TEST(SortedArrayTest, BulkIndexOf) {
- std::ifstream infile("test/ids.txt");
+ std::ifstream infile(std::string(ROOT_DIR)+"test/ids.txt");
sorted_array ids;
diff --git a/test/system_metrics_test.cpp b/test/system_metrics_test.cpp
index 134ef931..0d0e95e5 100644
--- a/test/system_metrics_test.cpp
+++ b/test/system_metrics_test.cpp
@@ -2,7 +2,7 @@
#include "system_metrics.h"
TEST(SystemMetricsTest, ParsingNetworkStats) {
- std::string proc_net_dev_path = "test/resources/proc_net_dev.txt";
+ std::string proc_net_dev_path = std::string(ROOT_DIR)+"test/resources/proc_net_dev.txt";
uint64_t received_bytes, sent_bytes;
SystemMetrics::linux_get_network_data(proc_net_dev_path, received_bytes, sent_bytes);
ASSERT_EQ(324278716, received_bytes);
diff --git a/test/config_test.cpp b/test/tsconfig_test.cpp
similarity index 92%
rename from test/config_test.cpp
rename to test/tsconfig_test.cpp
index 9fd9506b..4338a847 100644
--- a/test/config_test.cpp
+++ b/test/tsconfig_test.cpp
@@ -3,7 +3,7 @@
#include <iostream>
#include <cmdline.h>
#include "typesense_server_utils.h"
-#include "config.h"
+#include "tsconfig.h"
std::vector<char*> get_argv(std::vector<std::string> & args) {
std::vector<char*> argv;
@@ -78,7 +78,7 @@ TEST(ConfigTest, LoadConfigFile) {
std::vector<std::string> args = {
"./typesense-server",
- std::string("--config=") + "test/valid_config.ini"
+ std::string("--config=") + std::string(ROOT_DIR)+"test/valid_config.ini"
};
std::vector<char*> argv = get_argv(args);
init_cmdline_options(options, argv.size() - 1, argv.data());
@@ -102,7 +102,7 @@ TEST(ConfigTest, LoadIncompleteConfigFile) {
std::vector<std::string> args = {
"./typesense-server",
- std::string("--config=") + "test/valid_sparse_config.ini"
+ std::string("--config=") + std::string(ROOT_DIR)+"test/valid_sparse_config.ini"
};
std::vector<char*> argv = get_argv(args);
init_cmdline_options(options, argv.size() - 1, argv.data());
@@ -121,7 +121,7 @@ TEST(ConfigTest, LoadBadConfigFile) {
std::vector<std::string> args = {
"./typesense-server",
- std::string("--config=") + "test/bad_config.ini"
+ std::string("--config=") + std::string(ROOT_DIR)+"test/bad_config.ini"
};
std::vector<char*> argv = get_argv(args);
init_cmdline_options(options, argv.size() - 1, argv.data());
@@ -144,7 +144,7 @@ TEST(ConfigTest, CmdLineArgsOverrideConfigFileAndEnvVars) {
"--api-key=abcd",
"--listen-address=192.168.10.10",
"--cors-domains=http://localhost:8108",
- std::string("--config=") + "test/valid_sparse_config.ini"
+ std::string("--config=") + std::string(ROOT_DIR)+"test/valid_sparse_config.ini"
};
putenv((char*)"TYPESENSE_DATA_DIR=/tmp/ts");
@@ -182,7 +182,7 @@ TEST(ConfigTest, CorsDefaults) {
"--data-dir=/tmp/data",
"--api-key=abcd",
"--listen-address=192.168.10.10",
- std::string("--config=") + "test/valid_sparse_config.ini"
+ std::string("--config=") + std::string(ROOT_DIR)+"test/valid_sparse_config.ini"
};
std::vector<char*> argv = get_argv(args);