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

Node score should be a int32_t.

Kishore Nallane24e0fae5dc6
diff --git a/TODO.md b/TODO.md
index e23bbf8f..9ac2d6d7 100644
--- a/TODO.md
+++ b/TODO.md
@@ -60,12 +60,12 @@
- ~~json::parse must be wrapped in try catch~~
- ~~Collection Manager collections map should store plain collection name~~
- ~~init_collection of Collection manager should probably take seq_id as param~~
-- node score should be int32, no longer uint16 like in document struct
+- ~~node score should be int32, no longer uint16 like in document struct~~
+- Typo in prefix search
- Proper logging
- https support
- Validate before string to int conversion in the http api layer
- When field of "id" but not string, what happens?
-- Typo in prefix search
- test for num_documents
- test for string filter comparison: title < "foo"
- test for token ranking on float field
diff --git a/include/art.h b/include/art.h
index f807cf44..fe82890b 100644
--- a/include/art.h
+++ b/include/art.h
@@ -44,7 +44,7 @@ typedef struct {
uint8_t num_children;
uint8_t partial_len;
unsigned char partial[MAX_PREFIX_LEN];
- uint32_t max_score;
+ int32_t max_score;
uint32_t max_token_count;
} art_node;
@@ -98,7 +98,7 @@ typedef struct {
* `offsets` refer to the index locations where a token appeared in the document
*/
typedef struct {
- uint16_t score;
+ int32_t score;
uint32_t id;
uint32_t offsets_len;
uint32_t* offsets;
@@ -110,7 +110,7 @@ typedef struct {
*/
typedef struct {
art_values* values;
- uint32_t max_score;
+ int32_t max_score;
uint32_t key_len;
unsigned char key[];
} art_leaf;
diff --git a/src/art.cpp b/src/art.cpp
index c675ecd9..515e60ee 100644
--- a/src/art.cpp
+++ b/src/art.cpp
@@ -67,7 +67,7 @@ bool compare_art_node_frequency(const art_node *a, const art_node *b) {
}
bool compare_art_node_score(const art_node* a, const art_node* b) {
- uint32_t a_value = 0, b_value = 0;
+ int32_t a_value = 0, b_value = 0;
if(IS_LEAF(a)) {
art_leaf* al = (art_leaf *) LEAF_RAW(a);
@@ -542,7 +542,7 @@ static void add_child4(art_node4 *n, art_node **ref, unsigned char c, void *chil
memmove(n->children+idx+1, n->children+idx,
(n->n.num_children - idx)*sizeof(void*));
- uint16_t child_max_score = IS_LEAF(child) ? ((art_leaf *) LEAF_RAW(child))->max_score : ((art_node *) child)->max_score;
+ int32_t child_max_score = IS_LEAF(child) ? ((art_leaf *) LEAF_RAW(child))->max_score : ((art_node *) child)->max_score;
uint32_t child_token_count = IS_LEAF(child) ? ((art_leaf *) LEAF_RAW(child))->values->ids.getLength() : ((art_node *) child)->max_token_count;
n->n.max_score = MAX(n->n.max_score, child_max_score);
@@ -648,7 +648,7 @@ static void* recursive_insert(art_node *n, art_node **ref, const unsigned char *
return NULL;
}
- n->max_score = (uint16_t) MAX(n->max_score, (const uint16_t &) document->score);
+ n->max_score = MAX(n->max_score, document->score);
n->max_token_count = MAX(n->max_token_count, num_hits);
// Check if given node has a prefix
diff --git a/test/art_test.cpp b/test/art_test.cpp
index b62b065c..ebb6629a 100644
--- a/test/art_test.cpp
+++ b/test/art_test.cpp
@@ -11,7 +11,7 @@
art_document get_document(uint32_t id) {
art_document document;
- document.score = (uint16_t) id;
+ document.score = id;
document.id = id;
document.offsets = new uint32_t[1]{0};
document.offsets_len = 1;