Page 1 of 1

Issue? Multiple Filters uses OR, not AND

Posted: January 9th, 2021, 12:03 am
by Izzy
Type: Technical

Details: When filtering either Character Listing or Achievements and using multiple filters (i.e. Race AND Class), the results returned will return anything that matches at least one filter.

I think this is fine when within a single option i.e. they select Fae, Human- so return anyone that matches either of them. The problem is when I'm filtering a class as well, like... Sorcerer. I'm usually thinking: show me Faes and Humans that are Sorcerers. Not: show me all Faes and Humans (regardless of class), all Sorcerers (regardless of race). Or a more common example, I imagine, is looking for active characters that are also the same race.

I rooted around in the code to see if I could debug this issue and think I understand why it happens?
Currently, when filtering, you check the search-filters vs the card's data-filters, and then score the card based on how many filters it matches. If it has 0 matches, it'll be hidden... is my understanding? It's hard to comprehend the minified code LOL.
My first thought was to then just check the number of filters and have the score to display = number of filters... So "race=human&class=cleric" there are two filters, so the score would have to be 2 or else it's hidden.
But that becomes a problem when you have multiple Race filters for example. "race=human&race=fae"... a Human would match 1, Fae would match 1, and a half Human-Fae would match 2. But we would like to show all those cases!
So what now? Perhaps it would be possible to have the card filters use arrays for same filter types, so instead of race=Fae and race=Human, it would be race=[Fae, Human], and you check if race has either option, rewarding only 1 point regardless if it has one or both. You would then be able to check if the matched score matches the number of filters.
Search-filters and card's data-filters would have to be managed similarly to keep the scores consistent.

I coded a very shoddy example of what I mean, which you can see in this JSFiddle.

Re: Issue? Multiple Filters uses OR, not AND

Posted: January 9th, 2021, 1:54 am
by Memoria
I'll look into seeing if I can do something like this. I was aware it sorted by "or" rather than "and" when I built the code. It was easier implementation at the time and adding the filters was somewhat spur of the moment / "for fun" thing.