Filters dont apply

Enonic version: 6.12.3
OS: OSX

I seem to have problem using filters on content queries.
When I run this I get the expected 1 content returned.

const bean = __.newBean('com.enonic.xp.lib.content.QueryContentHandler'); bean.start = 0; bean.count = 3 bean.filters = __.toScriptValue({ boolean: { must: { ids: { values: ["09970a3d-f4b9-4123-bed3-40c43273fe66"] } } } }); const data = __.toNativeObject(bean.execute());

returns:
{ "total": 1, "count": 1, "hits": [ { "_id": "09970a3d-f4b9-4123-bed3-40c43273fe66" ... } ] }

but doing the same query through the contentLib gives me loads of result…
const data = contentLib.query({ start: 0, count: 3, filters: { boolean: { must: { hasValue: { field: "_id", values: ["09970a3d-f4b9-4123-bed3-40c43273fe66"] } } } } });
or with the shorter filter:
boolean: { must: { ids: { values: ["09970a3d-f4b9-4123-bed3-40c43273fe66"] } } }

both gives med wrong result with hits:
{ "total": 56, "count": 3, "hits": [ ... ] }

Looks like you might have some library overwriting content.js from an older version of the library.

The filters option was added on 6.10.0. Check if you are using any library that might bring in an older version of lib-content.

Can you post the dependencies in your build.gradle?

3 Likes

Ahh nice catch, was a dependency I had that had updated gradle.properties to a recent xp release, but had a gradle.build file that didn’t use the variable so where still running on Enonic 6.9.

:clap: thanks for pointing me in the right direction.

The lib that caused this issue where (version 1.3.1):

3 Likes