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

Adding external dependencies.

Kishore Nallanc095c166f0e5
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 93e20fdf..d8e02b12 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,9 +1,11 @@
cmake_minimum_required(VERSION 2.8)
project(search)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -std=gnu++11 -O2")
include_directories(include)
+include_directories(dependencies/ewah/include)
#file(GLOB SOURCES "src/*.cpp")
-add_executable(search src/art.cpp src/main.cpp)
\ No newline at end of file
+add_executable(search src/art.cpp src/main.cpp)
+target_link_libraries(search for)
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..df888421
--- /dev/null
+++ b/README.md
@@ -0,0 +1,9 @@
+# Typesense
+
+A typo tolerant, open source search engine that helps you build delightful search experiences.
+
+## Dependencies
+
+* [libfor](https://github.com/cruppstahl/for/)
+
+© 2016 Wreally Studios Inc.
\ No newline at end of file
diff --git a/include/heap_array.h b/include/heap_array.h
new file mode 100644
index 00000000..37890e69
--- /dev/null
+++ b/include/heap_array.h
@@ -0,0 +1,53 @@
+#pragma once
+
+template <typename T> inline void swapMe(T& a, T& b){
+ T c = a;
+ a = b;
+ b = c;
+}
+
+struct HeapArray {
+ enum{maxSize = 5000};
+
+ int size;
+ uint32_t data[maxSize];
+
+ void add(const uint32_t& val){
+ if (size >= maxSize){
+ if(data[0] <= val)
+ return;
+
+ data[0] = val;
+
+ for (int i = 0; (2*i+1) < maxSize; ){
+ int next = 2*i + 1;
+ if (data[next] < data[next+1])
+ next++;
+ if (data[i] < data[next])
+ swapMe(data[i], data[next]);
+ else
+ break;
+ i = next;
+ }
+ }
+ else {
+ data[size++] = val;
+ for (int i = size - 1; i > 0;){
+ int parent = (i-1)/2;
+ if (data[parent] < data[i]){
+ swapMe(data[parent], data[i]);
+ i = parent;
+ }
+ else
+ break;
+ }
+ }
+ }
+
+ void clear(){
+ size = 0;
+ }
+
+ HeapArray() :size(0){
+ }
+};
\ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 1a0c7c55..c3386ba4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,6 +3,11 @@
#include "art.h"
#include <fstream>
#include <art.h>
+#include "heap_array.h"
+#include <chrono>
+
+#include <stdlib.h> /* srand, rand */
+#include <time.h> /* time */
using namespace std;
@@ -13,6 +18,42 @@ static int test_prefix_cb(void *data, const unsigned char *k, uint32_t k_len, vo
return 0;
}
+void benchmark_heap_array() {
+ srand (time(NULL));
+
+ vector<uint32_t> records;
+
+ for(uint32_t i=0; i<10000000; i++) {
+ records.push_back((const unsigned int &) rand());
+ }
+
+ vector<uint32_t> hits;
+
+ for(uint32_t i=0; i<records.size(); i++) {
+ if(i%10 == 0) {
+ hits.push_back(i);
+ }
+ }
+
+ auto begin = std::chrono::high_resolution_clock::now();
+
+ HeapArray heapArray;
+
+ for(uint32_t i=0; i<hits.size(); i++) {
+ heapArray.add(records[hits[i]]);
+ }
+
+ std::sort(std::begin(heapArray.data), std::end(heapArray.data));
+
+ long long int timeMillis = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - begin).count();
+
+ for(uint32_t i=0; i<heapArray.maxSize; i++) {
+ cout << "Res: " << heapArray.data[i] << endl;
+ }
+
+ cout << "Time taken: " << timeMillis << endl;
+}
+
int main() {
cout << "Running demo...\n\n";
//cout << "SIZE OF: " << sizeof(X) << endl;
@@ -31,12 +72,20 @@ int main() {
num++;
}
- const unsigned char *prefix = (const unsigned char *) "r";
- art_iter_fuzzy_prefix(&t, prefix, strlen((const char *) prefix), 0, test_prefix_cb, NULL);
+ const unsigned char *prefix = (const unsigned char *) "responsibe";
+
+ auto begin = std::chrono::high_resolution_clock::now();
+
+ art_iter_fuzzy_prefix(&t, prefix, strlen((const char *) prefix), 1, test_prefix_cb, NULL);
+
+ long long int timeMillis = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - begin).count();
+
// art_iter_prefix(&t, prefix, strlen((const char *) prefix), test_prefix_cb, NULL);
// art_iter(&t, test_prefix_cb, NULL);
+ cout << "Time taken: " << timeMillis << "us" << endl;
+
art_tree_destroy(&t);
return 0;
}
\ No newline at end of file