fergies-inverted-index
Advanced tools
Comparing version 13.0.0-rc.4 to 13.0.0-rc.5
{ | ||
"name": "fergies-inverted-index", | ||
"version": "13.0.0-rc.4", | ||
"version": "13.0.0-rc.5", | ||
"description": "An inverted index that allows javascript objects to be easily serialised and retrieved using promises and map-reduce", | ||
@@ -5,0 +5,0 @@ "browser": "src/entrypoints/browser.js", |
@@ -125,3 +125,3 @@ # Fergie's Inverted Index | ||
const ii = await InvertedIndex({ name: 'myIndex' }) | ||
const ii = InvertedIndex({ name: 'myIndex' }) | ||
``` | ||
@@ -141,5 +141,6 @@ | ||
### `AGGREGATION_FILTER(aggregation, query).then(result)` | ||
### `AGGREGATION_FILTER(aggregation, query, trimEmpty).then(result)` | ||
The aggregation (either FACETS or BUCKETS) is filtered by the query | ||
The aggregation (either FACETS or BUCKETS) is filtered by the | ||
query. Use boolean `trimEmpty` to show or hide empty buckets | ||
@@ -146,0 +147,0 @@ ```javascript |
@@ -184,9 +184,20 @@ import charwise from 'charwise' | ||
// return the filtered aggregation | ||
const AGGREGATION_FILTER = (aggregation, filterSet) => { | ||
if (!filterSet || filterSet.length === 0) return aggregation | ||
const AGGREGATION_FILTER = (aggregation, filterSet, trimEmpty = true) => { | ||
// console.log(aggregation) | ||
// console.log(JSON.stringify(filterSet, null, 2)) | ||
if (!filterSet) return aggregation // no filter provided- return everything | ||
if (filterSet.length === 0) return [] // search returned no results | ||
filterSet = new Set(filterSet.map(item => item._id)) | ||
return aggregation.map(bucket => | ||
Object.assign(bucket, { | ||
_id: [...new Set([...bucket._id].filter(x => filterSet.has(x)))] | ||
}) | ||
return ( | ||
aggregation | ||
.map(bucket => | ||
Object.assign(bucket, { | ||
_id: [...new Set([...bucket._id].filter(x => filterSet.has(x)))] | ||
}) | ||
) | ||
// remove empty buckets | ||
.filter(facet => (trimEmpty ? facet._id.length : true)) | ||
) | ||
@@ -193,0 +204,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
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
37074
778
498