Skip to content

bug with selected value for boolean facet #119

Closed

Description

@SergeyRe

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)

Activity

  1. mulquin commented on Aug 16, 2022

    @mulquin
    Contributor

    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.

  2. cigolpl commented on Mar 9, 2023

    @cigolpl
    Member

    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

  3. SergeyRe commented on Mar 10, 2023

    @SergeyRe
    ContributorAuthor

    Yes. Its actually not big trouble at all.

  4. cigolpl commented on Nov 22, 2025

    @cigolpl
    Member

    @SergeyRe, @mulquin. Done - #149. Thank you for your input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions