Query for collection equality in MultiValueAttribute

57 views
Skip to first unread message

Marcin Kruglik

unread,
Oct 4, 2018, 11:49:14 AM10/4/18
to cqengine-discuss
Hi,

When I have a collection of Cars where one attribute is a multi value attribute, let say Features.
So I added Cars with bellow Features to my collection:
Car1 { "Alloy wheels", "AC", "leather seats"}
Car2 { "Alloy wheels"}
Car3 {"Alloy wheels", "DAB radio"}
I need to write a query which will return only Car1. Something like Query.equals(featuresAttribute, Collection.of("Alloy wheels", "AC", "leather seat") but only query I can find, which works with MultiValueAttributes is in() or eq() which in my case would return all cars (includes at least one element).

I think this is a common use case, but can't find anything about it. Any leads would be appreciated.

Cheers
Marcin



Marcin Kruglik

unread,
Oct 4, 2018, 12:05:41 PM10/4/18
to cqengine-discuss
Just to add,

My query shouldnt also match Car4 { "Alloy wheels", "AC", "leather seats", "sport  exhaust"}.

Marcin

Niall

unread,
Dec 5, 2018, 6:34:38 PM12/5/18
to cqengine-discuss
Sorry for the delay.
This is a good question.

The best way to solve this is probably to define another attribute NUM_FEATURES which returns the number of features, and to combine that with an in() query.


For example:
Collection<String> exactFeaturesRequired = Arrays.asList("a", "b", "c");

Query<Car> query = and(in(Car.FEATURES, exactFeaturesRequired), equal(Car.NUM_FEATURES, exactFeaturesRequired.size()));

Hope that helps,
Niall

Reply all
Reply to author
Forward
0 new messages