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

Support JSONP response for the search API alone.

Kishore Nallandda3a0a06ac5
diff --git a/TODO.md b/TODO.md
index 54717680..a7a10315 100644
--- a/TODO.md
+++ b/TODO.md
@@ -41,14 +41,15 @@
- ~~Proper pagination~~
- ~~Pagination parameter~~
- ~~Drop collection API~~
+- ~~JSONP response~~
+- "error":"Not found." is sent when query has no hits
+- Number of records in collection
+- Use rocksdb batch put for atomic insertion
+- Fix API response codes
- When prefix=true, use token_ranking_field for token ordering only for last word
- Query token ids should match query token ordering
- ID should not have "/"
- Group results by field
-- Number of records in collection
-- Fix API response codes
-- JSONP response
-- Use rocksdb batch put for atomic insertion
- Handle store-get() not finding a key
- ~~Test for asc/desc upper/lower casing~~
- ~~Test for search without any sort_by given~~
diff --git a/src/api.cpp b/src/api.cpp
index 59b00c6a..6c966bd5 100644
--- a/src/api.cpp
+++ b/src/api.cpp
@@ -141,6 +141,7 @@ void get_search(http_req & req, http_res & res) {
const char *FACET_BY = "facet_by";
const char *PER_PAGE = "per_page";
const char *PAGE = "page";
+ const char *CALLBACK = "callback";
if(req.params.count(NUM_TYPOS) == 0) {
req.params[NUM_TYPOS] = "2";
@@ -216,13 +217,17 @@ void get_search(http_req & req, http_res & res) {
result["took_ms"] = timeMillis;
- const std::string & json_str = result.dump();
- //std::cout << "JSON:" << json_str << std::endl;
+ const std::string & results_json_str = result.dump();
+
struct rusage r_usage;
getrusage(RUSAGE_SELF,&r_usage);
-
//std::cout << "Memory usage: " << r_usage.ru_maxrss << std::endl;
- res.send_200(json_str);
+
+ if(req.params.count(CALLBACK) == 0) {
+ res.send_200(results_json_str);
+ } else {
+ res.send_200(req.params[CALLBACK] + "(" + results_json_str + ");");
+ }
std::cout << "Time taken: " << timeMillis << "ms" << std::endl;
}