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 multiple facets not working.

Kishore Nallan24711d3c5c14
diff --git a/TODO.md b/TODO.md
index 9458d489..609877de 100644
--- a/TODO.md
+++ b/TODO.md
@@ -35,8 +35,9 @@
- ~~Filter query in the API~~
- ~~Facet limit (hardcode to top 10)~~
- ~~Deprecate old split function~~
-- When prefix=true, use token_ranking_field for token ordering
-- Search snippet
+- ~~Multiple facets not working~~
+- When prefix=true, use token_ranking_field for token ordering only for last word
+- Search snippet with highlight
- ID should not have "/"
- Group results by field
- Use rocksdb batch put for atomic insertion
@@ -53,7 +54,6 @@
- Minimum results should be a variable instead of blindly going with max_results
- Pagination parameter
- Iterator
-- Highlight
- UTF-8 support for fuzzy search
- Handle searching for non-existing fields gracefully
- test for same match score but different primary, secondary attr
diff --git a/src/api.cpp b/src/api.cpp
index 8b6cb27d..b7b8b80d 100644
--- a/src/api.cpp
+++ b/src/api.cpp
@@ -116,6 +116,8 @@ void post_create_collection(http_req & req, http_res & res) {
}
void get_search(http_req & req, http_res & res) {
+ auto begin = std::chrono::high_resolution_clock::now();
+
const char *NUM_TYPOS = "num_typos";
const char *PREFIX = "prefix";
const char *FILTER = "filter_by";
@@ -165,8 +167,6 @@ void get_search(http_req & req, http_res & res) {
}
}
- auto begin = std::chrono::high_resolution_clock::now();
-
CollectionManager & collectionManager = CollectionManager::get_instance();
Collection* collection = collectionManager.get_collection(req.params["collection"]);
@@ -184,6 +184,12 @@ void get_search(http_req & req, http_res & res) {
nlohmann::json result = collection->search(req.params["q"], search_fields, filter_str, facet_fields,
sort_fields, std::stoi(req.params[NUM_TYPOS]), 100,
token_order, prefix);
+
+ uint64_t timeMillis = std::chrono::duration_cast<std::chrono::milliseconds>(
+ std::chrono::high_resolution_clock::now() - begin).count();
+
+ result["took_ms"] = timeMillis;
+
const std::string & json_str = result.dump();
//std::cout << "JSON:" << json_str << std::endl;
struct rusage r_usage;
@@ -192,8 +198,7 @@ void get_search(http_req & req, http_res & res) {
//std::cout << "Memory usage: " << r_usage.ru_maxrss << std::endl;
res.send_200(json_str);
- long long int timeMicros = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - begin).count();
- std::cout << "Time taken: " << timeMicros << "us" << std::endl;
+ std::cout << "Time taken: " << timeMillis << "ms" << std::endl;
}
void post_add_document(http_req & req, http_res & res) {
diff --git a/src/http_server.cpp b/src/http_server.cpp
index cd02e2d5..23cac504 100644
--- a/src/http_server.cpp
+++ b/src/http_server.cpp
@@ -104,7 +104,7 @@ std::map<std::string, std::string> HttpServer::parse_query(const std::string& qu
std::string key = (*i)[1].str();
std::string raw_value = (*i)[2].str();
std::string value = StringUtils::url_decode(raw_value);
- if(query_map.count(value) == 0) {
+ if(query_map.count(key) == 0) {
query_map[key] = value;
} else {
query_map[key] = query_map[key] + "&&" + value;