Skip to content

AND filter is ignored when its first value does not occur in any item #155

Closed

Description

@trackoor

With conjunction: true, a filter whose first value is not present in the data is dropped, so search returns items that do not have that value and the result depends on the order of the filter values.

const itemsjs = require('itemsjs');

const items = [
  { id: 1, name: 'Shirt', tags: ['cotton'] },
  { id: 2, name: 'Hat', tags: ['wool'] },
];
const engine = itemsjs(items, { aggregations: { tags: { title: 'Tags', conjunction: true } } });

for (const tags of [['silk'], ['silk', 'cotton'], ['cotton', 'silk']]) {
  const r = engine.search({ filters: { tags } });
  console.log(JSON.stringify(tags), r.data.items.map(i => i.name), r.pagination.total,
    r.data.aggregations.tags.buckets.map(b => [b.key, b.doc_count]));
}

Running node repro.js on itemsjs 2.4.4 (master 32b7a46), Node.js v26.13.0:

["silk"] [] 0 [ [ 'cotton', 1 ], [ 'wool', 1 ] ]
["silk","cotton"] [ 'Shirt' ] 1 [ [ 'cotton', 1 ], [ 'wool', 0 ] ]
["cotton","silk"] [] 0 [ [ 'cotton', 0 ], [ 'wool', 0 ] ]

Expected: no items ([] 0) and all bucket counts 0 in every case, because no item has the tag silk. Instead, ['silk', 'cotton'] returns Shirt, and ['silk'] alone reports bucket counts as if no filter were set. The same happens across conjunctive facets (for example, filters: { tags: ['silk'], color: ['red'] } returns the red items).

In matrix (src/utils/facetsCore.js), the loop over conjunctive filters falls through to conjunctive_index = facetData when conjunctive_index is still undefined, so a missing first value leaves conjunctive_index as undefined instead of new FastBitSet([]) (unlike #130, which handled the case where a missing value comes after an existing one).

Credit: https://ucsbplse.github.io/

Activity

  1. cigolpl commented on Nov 12, 2026

    @cigolpl
    Member

    Thank you @trackoor. I'll get back to it in next week

  2. cigolpl commented on Nov 16, 2026

    @cigolpl
    Member
  3. added a commit that references this issue on Nov 22, 2026
    c0c7587
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions