Handle spaces in query string.

This commit is contained in:
Kishore Nallan 2016-08-30 22:07:17 +05:30
parent 44da808f16
commit aa46985bab
3 changed files with 5 additions and 15 deletions

View File

@ -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++) {

View File

@ -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;

View File

@ -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;