Array filter logic issue

6 years 1 month ago - 6 years 1 month ago #87192 by paulalford
paulalford created the topic: Array filter logic issue

I have two multiple choice questions, lets call them Q1 and Q2, both with the same answer codes.

Q2 has an array exclusion filter set based on Q1, so Q2 only shows the answer codes not selected at Q1. This works fine.

I also have Q3 that needs to show the answers selected at Q1 and Q2. I'm specifying an array filter Q1;Q2. The problem I'm encountering is that the logic is:

display answer code 1 if Q1=1 && Q2=1. This needs to be:
display answer code 1 if Q1=1 OR Q2=1 because the first condition can never be met.

Is there a way of changing the AND to an OR? I can't seem to find any info in the manual.

Thanks in advance.
Last Edit: 6 years 1 month ago by paulalford.

Please Log in or Create an account to join the conversation.

6 years 1 month ago #87248 by TMSWhite
TMSWhite replied the topic: Array filter logic issue
Good point. LimeSurvey always ANDs together compound array_filter and/or array_filter_exclude statements. There are valid reasons for wanting to OR them together, but sometimes AND is the right solution.

Your case is even trickier, since Q2 has an exclusion on Q1, and Q3 uses both. This runs afoul of the cascading feature.

A concrete example is:
Q1: Which animals have you owned?
Q2: Of those you haven't owned, which do you wish you could own someday?
Q3: Why don't you like about these animals?

Since Q2 uses array_filter_exclude = "Q1", and Q3 uses array_filter_exclude = "Q1;Q2", you get relevance like this for Q3:
(( ! is_empty(Q2_1.NAOK)) && ( ! is_empty(Q1_1.NAOK)) && (is_empty(Q1_1.NAOK)))

Which can never be true.

Even if you don't have Q2 array_filter_exclude on Q1, you get:
(( ! is_empty(Q2_1.NAOK)) && ( ! is_empty(Q1_1.NAOK)))

when it should be OR.

Going back to basics:
(1) If you combine two array_filters, should they always be ORed together? What if you want to ensure that the user selected the same option in two different questions?
(2) If you combine two array_filter_excludes, should they always be
(3) What if you mix array_filter and array_filter_exclude?
(4) What if you want to mix filter styles and also support cascading?

Rather than simply using ; to separate filters, perhaps we should allow a syntax to indicate how they should be combined? Since this can get complex, we might do a consolidated array_filter syntax that lets you explicitly mix and match array_filter and array_filter_exclude, such as:

A => filter on A
!A => filter_exclude on A
~A => filter on A, but do not cascade
A|B => A OR B
A&B => A AND B
A&~!B => A AND exclude B, but don't cascade on B
!A&(B|C) => exclude A and filter on A OR B

Alternatively we could finally support sub-question-level relevance and let users explicitly declare the filtering logic for each question.
The following user(s) said Thank You: cris_m

Please Log in or Create an account to join the conversation.

6 years 4 weeks ago #88207 by jelo
jelo replied the topic: Array filter logic issue
Sounds interesting.

What if three multiple choice questions with same itemlist are in the following order

Q2 Nonechoosen items are filtered out
Q3 Choosen items from Q2 are filtered out

What is meant with cascading?

Are you a student conducting a survey? If yes, tell me why you use LimeSurvey?

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!