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

Fix compile errors.

Kishore Nallanbf6df4587a35
diff --git a/TODO.md b/TODO.md
index 61c8de9c..ccd3c991 100644
--- a/TODO.md
+++ b/TODO.md
@@ -29,6 +29,7 @@
- ~~Facets~~
- ~~Schema validation during insertion (missing fields + type errors)~~
- ~~Proper score field for ranking tokens~~
+- ~~Throw errors when schema is broken~~
- Prevent string copy during indexing
- clean special chars before indexing
- Minimum results should be a variable instead of blindly going with max_results
@@ -48,7 +49,6 @@
- Benchmark with -ffast-math
- Space sensitivity
- Use bitmap index instead of compressed array for doc list
-- Throw errors when schema is broken
- Primary_rank_scores and secondary_rank_scores hashmaps should be combined
- Proper logging
- d-ary heap?
diff --git a/src/collection.cpp b/src/collection.cpp
index e077a946..80e63976 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -85,11 +85,11 @@ Option<uint32_t> Collection::index_in_memory(const nlohmann::json &document, uin
"but is not found in the document.");
}
- if(!document[token_ordering_field].is_number()) {
+ if(!token_ordering_field.empty() && !document[token_ordering_field].is_number()) {
return Option<>(400, "Token ordering field `" + token_ordering_field + "` must be an INT32.");
}
- if(document[token_ordering_field].get<int64_t>() > INT32_MAX) {
+ if(!token_ordering_field.empty() && document[token_ordering_field].get<int64_t>() > INT32_MAX) {
return Option<>(400, "Token ordering field `" + token_ordering_field + "` exceeds maximum value of INT32.");
}
@@ -745,9 +745,7 @@ void Collection::search_field(std::string & query, const std::string & field, ui
} else {
int token_len = prefix ? (int) token.length() : (int) token.length() + 1;
- if(token_rank == 2) {
- std::cout << "\n";
- }
+ int count = search_index.count(field);
art_fuzzy_search(search_index.at(field), (const unsigned char *) token.c_str(), token_len,
costs[token_index], costs[token_index], 3, token_order, prefix, leaves);
diff --git a/src/main/benchmark.cpp b/src/main/benchmark.cpp
index 167c76bd..c51fec34 100644
--- a/src/main/benchmark.cpp
+++ b/src/main/benchmark.cpp
@@ -24,10 +24,10 @@ int main(int argc, char* argv[]) {
Collection *collection = collectionManager.get_collection("collection");
if(collection == nullptr) {
- collection = collectionManager.create_collection("collection", fields_to_index, rank_fields);
+ collection = collectionManager.create_collection("collection", fields_to_index, {}, rank_fields);
}
- std::ifstream infile(argv[1]);
+ std::ifstream infile("/Users/kishore/Downloads/hnstories_small.jsonl");
std::string json_line;
@@ -48,7 +48,7 @@ int main(int argc, char* argv[]) {
while(counter < 3000) {
auto i = counter % 5;
- auto results = collection->search(queries[i], search_fields, {}, { }, 1, 100, MAX_SCORE, 0);
+ auto results = collection->search(queries[i], search_fields, "", { }, {"points"}, 1, 100, MAX_SCORE, 0);
results_total += results.size();
counter++;
}
diff --git a/src/main/main.cpp b/src/main/main.cpp
index 52d4f733..52b28058 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -53,7 +53,7 @@ int main(int argc, char* argv[]) {
Collection *collection = collectionManager.get_collection("collection");
if(collection == nullptr) {
- collection = collectionManager.create_collection("collection", fields_to_index, rank_fields);
+ collection = collectionManager.create_collection("collection", fields_to_index, {}, rank_fields);
std::ifstream infile(std::string(ROOT_DIR)+"test/documents.jsonl");
//std::ifstream infile(argv[1]);
@@ -71,8 +71,9 @@ int main(int argc, char* argv[]) {
auto begin = std::chrono::high_resolution_clock::now();
std::vector<std::string> search_fields = {"title"};
- collection->search("the", search_fields, {}, { }, 1, 100, MAX_SCORE, 0);
- long long int timeMillis = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - begin).count();
+ collection->search("the", search_fields, "", {}, {"points"}, 1, 100, MAX_SCORE, 0);
+ long long int timeMillis =
+ std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - begin).count();
cout << "Time taken: " << timeMillis << "us" << endl;
return 0;
}
\ No newline at end of file
diff --git a/src/main/server.cpp b/src/main/server.cpp
index 85bd1523..2dec8818 100644
--- a/src/main/server.cpp
+++ b/src/main/server.cpp
@@ -101,7 +101,7 @@ static int get_search(h2o_handler_t *self, h2o_req_t *req) {
std::vector<std::string> search_fields = {"title"};
nlohmann::json result = collection->search(query_map["q"], search_fields, filter_str, { },
- std::stoi(query_map[NUM_TYPOS]), 100, token_order, false);
+ {"points"}, std::stoi(query_map[NUM_TYPOS]), 100, token_order, false);
std::string json_str = result.dump();
//std::cout << "JSON:" << json_str << std::endl;
struct rusage r_usage;
@@ -234,7 +234,7 @@ int main(int argc, char **argv) {
collectionManager.init(store);
collection = collectionManager.get_collection("collection");
if(collection == nullptr) {
- collection = collectionManager.create_collection("collection", search_fields, rank_fields);
+ collection = collectionManager.create_collection("collection", search_fields, {}, rank_fields);
//index_documents(std::string(ROOT_DIR)+"test/documents.jsonl");
index_documents(argv[1]);
}