Socket
Socket
Sign inDemoInstall

fergies-inverted-index

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fergies-inverted-index - npm Package Compare versions

Comparing version 10.2.0 to 11.0.0

.travis.yml

3

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc