diff --git a/README.md b/README.md
index fd4ee0e..be0a839 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+
+
diff --git a/src/cache.js b/src/cache.js
index 4514947..5cd7407 100644
--- a/src/cache.js
+++ b/src/cache.js
@@ -160,7 +160,7 @@ CacheClass.prototype.del = function(id){
key = this.queue[i];
item = this.cache[key];
- if(item.indexOf(id) !== -1){
+ if(item.includes(id)){
this.queue.splice(i--, 1);
delete this.cache[key];
diff --git a/src/document.js b/src/document.js
index 25da47c..d93c61b 100644
--- a/src/document.js
+++ b/src/document.js
@@ -58,6 +58,8 @@ function Document(options){
if(SUPPORT_TAGS){
+ // TODO case-insensitive tags
+
this.tag = ((opt = document["tag"]) && parse_tree(opt, this.marker));
this.tagindex = opt && create_object();
}
@@ -185,6 +187,8 @@ function parse_tree(key, marker){
return count > 1 ? tree : tree[0];
}
+// TODO support generic function created from string when tree depth > 1
+
function parse_simple(obj, tree){
if(is_string(tree)){
@@ -202,6 +206,8 @@ function parse_simple(obj, tree){
return obj;
}
+// TODO support generic function created from string when tree depth > 1
+
function store_value(obj, store, tree, pos, key){
obj = obj[key];
@@ -345,7 +351,7 @@ Document.prototype.add = function(id, content, _append){
dupes[key] = 1;
arr = this.tagindex[key] || (this.tagindex[key] = []);
- if(!_append || (arr.indexOf(id) === -1)){
+ if(!_append || !arr.includes(id)){
arr[arr.length] = id;
diff --git a/src/index.js b/src/index.js
index 797cda8..54d520a 100644
--- a/src/index.js
+++ b/src/index.js
@@ -117,6 +117,10 @@ Index.prototype.append = function(id, content){
return this.add(id, content, true);
};
+// TODO:
+// string + number as text
+// boolean, null, undefined as ?
+
/**
* @param {!number|string} id
* @param {!string} content
@@ -133,7 +137,7 @@ Index.prototype.add = function(id, content, _append, _skip_update){
return this.update(id, content);
}
- content = this.encode(content);
+ content = this.encode("" + content);
const length = content.length;
if(length){
@@ -353,7 +357,7 @@ Index.prototype.push_index = function(dupes, value, score, id, append, keyword){
arr = arr[score] || (arr[score] = []);
}
- if(!append || (arr.indexOf(id) === -1)){
+ if(!append || !arr.includes(id)){
arr[arr.length] = id;
@@ -396,16 +400,16 @@ Index.prototype.search = function(query, limit, options){
if(options){
+ query = options["query"] || query;
limit = options["limit"];
offset = options["offset"] || 0;
context = options["context"];
suggest = SUPPORT_SUGGESTION && options["suggest"];
- query = options["query"] || query;
}
if(query){
- query = /** @type {Array} */ (this.encode(query));
+ query = /** @type {Array} */ (this.encode("" + query));
length = query.length;
// TODO: solve this in one single loop below
@@ -421,7 +425,7 @@ Index.prototype.search = function(query, limit, options){
if(term && (term.length >= this.minlength) && !dupes[term]){
- // this fast path just could applied when not in memory-optimized mode
+ // this fast path can just apply when not in memory-optimized mode
if(!this.optimize && !suggest && !this.map[term]){
diff --git a/src/intersect.js b/src/intersect.js
index 1336cba..16828e6 100644
--- a/src/intersect.js
+++ b/src/intersect.js
@@ -1,7 +1,7 @@
import { create_object, concat } from "./common.js";
/**
- * Implementation based on Array.indexOf() provides better performance,
+ * Implementation based on Array.includes() provides better performance,
* but it needs at least one word in the query which is less frequent.
* Also on large indexes it does not scale well performance-wise.
* This strategy also lacks of suggestion capabilities (matching & sorting).
@@ -97,7 +97,7 @@ import { create_object, concat } from "./common.js";
//
// if(arr.length){
//
-// found = arr.indexOf(id) !== -1;
+// found = arr.includes(id);
//
// if(found){
//
@@ -280,7 +280,8 @@ export function intersect(arrays, limit, offset, suggest) {
if(suggest){
- check_suggest[id] = (check_idx = check_suggest[id]) ? ++check_idx : check_idx = 1;
+ check_idx = (check_suggest[id] || 0) + 1;
+ check_suggest[id] = check_idx;
// do not adding IDs which are already included in the result (saves one loop)
// the first intersection match has the check index 2, so shift by -2
@@ -373,7 +374,7 @@ export function intersect_union(mandatory, arrays) {
check[mandatory[x]] = 1;
}
- for(let x = 0, arr; x < arrays.length; x++){
+ for(let x = 0, arr; x < arrays.length; x++){
arr = arrays[x];
diff --git a/src/lang.js b/src/lang.js
index 92749d9..14f62ca 100644
--- a/src/lang.js
+++ b/src/lang.js
@@ -45,6 +45,8 @@ export function pipeline(str, normalize, split, _collapse){
return str;
}
+// TODO improve normalize + remove non-delimited chars like in "I'm" + split on whitespace+
+
export const regex_whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u;
const regex_normalize = /[\u0300-\u036f]/g;
diff --git a/src/serialize.js b/src/serialize.js
index 7477f2d..6faf52c 100644
--- a/src/serialize.js
+++ b/src/serialize.js
@@ -1,3 +1,5 @@
+// TODO return promises instead of inner await
+
import { IndexInterface, DocumentInterface } from "./type.js";
import { create_object, is_string } from "./common.js";