itemsapi / itemsjs

Extremely fast faceted search engine in JavaScript - lightweight, flexible, and simple to use

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug with selected value for boolean facet

SergeyRe opened this issue · comments

to reproduce:

const data = [{ "boolean": true, "string": "true" }]
const itemsjs = require('itemsjs')(data, {
    aggregations: {
        boolean: {},
        string: {}
    }
});

const aggs = itemsjs.search({
    filters: {
        boolean: [true],
        string: ["true"]
    }
}).data.aggregations

console.log(aggs.boolean.buckets, aggs.string.buckets)

//[{ key: 'true', doc_count: 1, selected: false }][{ key: 'true', doc_count: 1, selected: true }]`

for comparison there 2 fields : boolean and string . Both are aggregations and search made under both of them
in first case we have "selected:false" for boolean ( looks like a bug) and "selected:true" for string ( its OK)

commented

This is happening because of line 370 in helpers.js.

Currently to check if something is selected, filters.indexOf(v2[0]) !== -1 is used.

v2[0] is the result of lodash chain().toPairs().map() but it is actually a string, so the indexOf above fails.

Thank you for bringing this issue. After reviewing the issue, I have determined that this is not a bug, but rather an improvement request. At this time, ItemsJS does not support boolean filters, but using strings can serve as a temporary workaround. Please let me know if this workaround is limiting you in any way

Yes. Its actually not big trouble at all.