fergies-inverted-index
Advanced tools
Comparing version 10.2.0 to 11.0.0
{ | ||
"name": "fergies-inverted-index", | ||
"version": "10.2.0", | ||
"version": "11.0.0", | ||
"description": "An inverted index that allows javascript objects to be easily serialised and retrieved using promises and map-reduce", | ||
@@ -18,2 +18,3 @@ "browser": "src/browser.js", | ||
"diacritic": "^0.0.2", | ||
"level-out": "^1.0.1", | ||
"memory-level": "^1.0.0", | ||
@@ -20,0 +21,0 @@ "path-browserify": "^1.0.1", |
@@ -39,4 +39,5 @@ const charwise = require('charwise') | ||
// boomness#1.00 etc | ||
tokenAppend: '', | ||
// tokenAppend: '', | ||
caseSensitive: true, | ||
isLeaf: item => typeof item === 'string' || typeof item === 'number', | ||
stopwords: [], | ||
@@ -43,0 +44,0 @@ doNotIndexField: [], |
@@ -148,33 +148,32 @@ const tokenParser = require('./parseToken.js') | ||
return Promise.all( | ||
token.FIELD.map(fieldName => { | ||
return new Promise(resolve => | ||
new EntryStream(ops._db, { | ||
gte: formatKey(fieldName, token.VALUE.GTE), | ||
lte: formatKey(fieldName, token.VALUE.LTE, true), | ||
limit: token.LIMIT, | ||
reverse: token.REVERSE | ||
}) | ||
.on('data', token => { | ||
return token.value.forEach(docId => { | ||
return rs.set(docId, [ | ||
...(rs.get(docId) || []), | ||
JSON.stringify({ | ||
FIELD: token.key[1], | ||
VALUE: token.key[2][0], | ||
SCORE: token.key[2][1] | ||
}) | ||
]) | ||
}) | ||
token.FIELD.map( | ||
fieldName => | ||
new Promise(resolve => | ||
new EntryStream(ops._db, { | ||
gte: formatKey(fieldName, token.VALUE.GTE), | ||
lte: formatKey(fieldName, token.VALUE.LTE, true), | ||
limit: token.LIMIT, | ||
reverse: token.REVERSE | ||
}) | ||
.on('end', resolve) | ||
) | ||
}) | ||
.on('data', token => | ||
token.value.forEach(docId => | ||
rs.set(docId, [ | ||
...(rs.get(docId) || []), | ||
JSON.stringify({ | ||
FIELD: token.key[1], | ||
VALUE: token.key[2][0], | ||
SCORE: token.key[2][1] | ||
}) | ||
]) | ||
) | ||
) | ||
.on('end', resolve) | ||
) | ||
) | ||
).then(() => | ||
resolve( | ||
Array.from(rs.keys()).map(id => { | ||
return { | ||
_id: id, | ||
_match: rs.get(id) | ||
} | ||
}) | ||
Array.from(rs.keys()).map(id => ({ | ||
_id: id, | ||
_match: rs.get(id) | ||
})) | ||
) | ||
@@ -181,0 +180,0 @@ ) |
@@ -10,2 +10,4 @@ const trav = require('traverse') | ||
const invertDoc = (obj, putOptions) => { | ||
// console.log(JSON.stringify(obj._object, null, 2)) | ||
if (obj._object == null) { | ||
@@ -20,3 +22,2 @@ return { | ||
trav(obj._object).forEach(function (node) { | ||
let searchable = true | ||
const fieldName = this.path | ||
@@ -27,35 +28,22 @@ // allowing numbers in path names create ambiguity with arrays | ||
.join('.') | ||
if (fieldName === '_id') searchable = false | ||
// Skip fields that are not to be indexed | ||
if ( | ||
putOptions.doNotIndexField.filter(item => fieldName.startsWith(item)) | ||
.length | ||
) { | ||
searchable = false | ||
} | ||
// TODO: deal with "comments" using objects | ||
// deal with stopwords | ||
if ( | ||
this.isLeaf && | ||
ops.stopwords.includes((this.node + '').split('#')[0]) // TODO: is # still used? | ||
) { | ||
searchable = false | ||
} | ||
if (searchable && this.isLeaf) { | ||
let key | ||
try { | ||
const parsedJSON = JSON.parse(this.node) | ||
if (!Array.isArray(parsedJSON)) throw new Error() | ||
this.update(parsedJSON, true) | ||
key = JSON.stringify([fieldName, parsedJSON]) | ||
} catch (e) { | ||
key = JSON.stringify([fieldName, [this.node]]) | ||
if (fieldName !== '_id') { | ||
// Skip fields that are not to be indexed | ||
if ( | ||
!putOptions.doNotIndexField.filter(item => fieldName.startsWith(item)) | ||
.length | ||
) { | ||
if (ops.isLeaf(this.node)) { | ||
// deal with stopwords | ||
if (!ops.stopwords.includes(this.node)) { | ||
const key = JSON.stringify([ | ||
fieldName, | ||
[this.node].flat(Infinity) | ||
]) | ||
// bump to lower case if not case sensitive | ||
keys.push(ops.caseSensitive ? key : key.toLowerCase()) | ||
} | ||
// calling .update is the only way to move on to the next node | ||
this.update(this.node, true) | ||
} | ||
} | ||
// bump to lower case if not case sensitive | ||
keys.push(ops.caseSensitive ? key : key.toLowerCase()) | ||
} | ||
@@ -105,2 +93,3 @@ }) | ||
key: ['IDX', ...JSON.parse(indexKeys[i])], | ||
// if newSet is [] then simply remove the index entry | ||
@@ -139,4 +128,2 @@ // otherwise update | ||
if (typeof id === 'number') return id | ||
// else | ||
// return ++incrementalId | ||
} | ||
@@ -143,0 +130,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172600
43
5724
16
1