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

Handle spaces in query string.

Kishore Nallanaa46985babf5
diff --git a/src/collection.cpp b/src/collection.cpp
index fbead280..840ce269 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -92,7 +92,7 @@ std::vector<nlohmann::json> Collection::search(std::string query, size_t max_res
std::vector<std::vector<art_leaf*>> token_leaves;
for(std::string token: tokens) {
std::vector<art_leaf*> leaves;
- int max_cost = 0;
+ int max_cost = 2;
art_iter_fuzzy_prefix(&t, (const unsigned char *) token.c_str(), (int) token.length()+1, max_cost, 10, leaves);
if(!leaves.empty()) {
for(auto i=0; i<leaves.size(); i++) {
diff --git a/src/main.cpp b/src/main.cpp
index 71ff72fc..0810f9bc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -26,7 +26,7 @@ int main() {
cout << "FINISHED INDEXING!" << endl << flush;
auto begin = std::chrono::high_resolution_clock::now();
- collection->search("plant", 100);
+ collection->search("plant not", 100);
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;
delete collection;
diff --git a/src/server.cpp b/src/server.cpp
index 68ec72de..36b92a61 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -45,7 +45,7 @@ std::map<std::string, std::string> parse_query(const std::string& query) {
for (std::sregex_iterator i = words_begin; i != words_end; i++) {
std::string key = (*i)[1].str();
std::string value = (*i)[2].str();
- query_map[key] = value;
+ query_map[key] = StringUtils::replace_all(value, "%20", " ");
}
return query_map;
@@ -53,16 +53,6 @@ std::map<std::string, std::string> parse_query(const std::string& query) {
static int chunked_test(h2o_handler_t *self, h2o_req_t *req) {
- /*
- nlohmann::json_j;
-
- // add a number that is stored as double (note the implicit conversion of j to an object)
- j["pi"] = 3.141;
-
- // add a Boolean that is stored as bool
- j["happy"] = true;
- */
-
static h2o_generator_t generator = {NULL, NULL};
if (!h2o_memis(req->method.base, req->method.len, H2O_STRLIT("GET"))) {
@@ -152,8 +142,8 @@ static int create_listener(void) {
}
void index_documents() {
- //std::ifstream infile("/Users/kishore/others/wreally/typesense/test/documents.jsonl");
- std::ifstream infile("/Users/kishore/Downloads/hnstories.jsonl");
+ std::ifstream infile("/Users/kishore/others/wreally/typesense/test/documents.jsonl");
+ //std::ifstream infile("/Users/kishore/Downloads/hnstories.jsonl");
std::string json_line;