Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 ANDing multiple values in a field
ln_e Offline
Junior Member
**
Posts: 3
Joined: Sep 2015
Post: #1
ANDing multiple values in a field
Hi,

First of all, fantastic plugin, it's come in very useful. Now; I have a thread prefix/category setup where I have a relatively large number of possible values for one field (users may freely select any combination thereof). I'd like for it to be filtered such that selecting multiple values requires all of them to be present for threads to show up, like a logcial AND:

Quote:Topic 1
FIELD: A C D F

Topic 2
FIELD: A D F

Topic 3
FIELD: A C D

Selected filter: A C

==>

"Topic 1" and "Topic 3" are shown.

Currently, (and as per documentation) stacking filters works as an OR, meaning that it's not possible to filter for specific combinations within a single field (selecting A C D F would return all three Topics, which is not particularly helpful).

I was wondering whether there's a way to set it up so multiple filters for a multiple value field will be treated as filters across different keys/fields would be, or if not, whether there's a relatively unconvoluted way for me to hack it in on my copy of the plugin (I don't need OR filtering).

Anyone got any ideas?
(This post was last modified: 09-23-2015 11:46 PM by ln_e.)
09-23-2015 11:45 PM
Find all posts by this user Quote this message in a reply
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #2
RE: ANDing multiple values in a field
I am not 100% sure if I get what you want - is it something like this?

http://www.leefish.nl/mybb/forumdisplay.php?fid=22

If so, then try this :  http://mybbhacks.zingaburga.com/showthre...http://mybbhacks.zingaburga.com/showthread.php?tid=1418&pid=1195


[Image: leelink.gif]
MYBB1.6 & XThreads
(This post was last modified: 09-24-2015 12:05 AM by leefish.)
09-23-2015 11:53 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ln_e Offline
Junior Member
**
Posts: 3
Joined: Sep 2015
Post: #3
RE: ANDing multiple values in a field
Yes, except instead of being spread across three key/fields, it is all part of the same key/field, which is multiple select.

From the OP you linked:

(08-11-2012 08:00 PM)Jumper Wrote:  prefix 1
values: value1, value2, value3, value4, value5
prefix 2
values: example1, example2, example3, example4, example5
prefix 3
values: test1, test2, test3, test4, test5

now i need a triple dropdown-menue, where you can select the values from prefix 1, prefix 2 and prefix 3, and for example: if you select the values "value2" & "example1" & "test4", and click on a search-button, results should only be displayed entries where this 3 values match.

possible?

What I'd like to do:

prefix 1
values: value1, value2, value3, value4, value5

If I select "value1" & "value3" & "value5" as a filter (all within prefix 1), results should only be displayed where an item has all three selected values.
(This post was last modified: 09-24-2015 12:18 AM by ln_e.)
09-24-2015 12:17 AM
Find all posts by this user Quote this message in a reply
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #4
RE: ANDing multiple values in a field
Ah yea, that is why I split it all up into the categories - I did not want the overhead of a huge many options field. I think you need ZB or rateU - sorry Frown


[Image: leelink.gif]
MYBB1.6 & XThreads
09-24-2015 12:21 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ln_e Offline
Junior Member
**
Posts: 3
Joined: Sep 2015
Post: #5
RE: ANDing multiple values in a field
Thanks for the help anyway! :)

I think I've figured it out in the meantime, although would still like to know if there is a less hacky solution.

For anyone looking to do something similar, this is the part that handles multiple select queries in xt_forumdhooks.php

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if(!xthreads_empty($threadfield_cache[$field]['multival'])) {
				// ugly, but no other way to really do this...
				$qstr = '(';
				$qor = '';
				switch($filtermode) {
					case XTHREADS_FILTER_PREFIX:
						$cfield = xthreads_db_concat_sql(array("\"\n\"", $fieldname));
						$qlpre = "%\n";
						$qlpost = '';
						break;
					case XTHREADS_FILTER_ANYWHERE:
						$cfield = $fieldname;
						$qlpre = $qlpost = '';
						break;
					default:
						$cfield = xthreads_db_concat_sql(array("\"\n\"", $fieldname, "\"\n\""));
						$qlpre = "%\n";
						$qlpost = "\n%";
				}
				foreach($val2 as &$v) {
					$qstr .= $qor.$cfield.' LIKE "'.$qlpre.xthreads_forumdisplay_filter_parselike($v, $filtermode).$qlpost.'"';
					if(!$qor) $qor = ' OR ';
				}
				$qstr .= ')';
			}



Quote:$qstr .= $qor.$cfield.' LIKE "'.$qlpre.xthreads_forumdisplay_filter_parselike($v, $filtermode).$qlpost.'"';
if(!$qor) $qor = ' OR ';

This is where the multiple values are ORed together, you can just duct tape it with an AND:

Quote:$qstr .= $qor.$cfield.' LIKE "'.$qlpre.xthreads_forumdisplay_filter_parselike($v, $filtermode).$qlpost.'"';
if(!$qor) $qor = ' AND ';


Not a pretty solution by any means, but it does the job.
09-24-2015 03:12 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #6
RE: ANDing multiple values in a field
I just want to add an idea just by using templates, but we  need multiple checkbox fields with single value. Then modify the templates so it looks like one input.

For example, lets say we have 4 values, A, B, C and D

Option A:
Key: oa
Hide Thread Field: check all.
Input Field Type: Checkboxes
Value List: A
Multiple Value Delimiter: space or whatever
Filtering Mode: Exact match

Option B:
Key: ob
Hide Thread Field: check all.
Input Field Type: Checkboxes
Value List: B
Multiple Value Delimiter: space or whatever
Filtering Mode: Exact match

Option C:
Key: oc
Hide Thread Field: check all.
Input Field Type: Checkboxes
Value List: C
Multiple Value Delimiter: space or whatever
Filtering Mode: Exact match

Option D:
Key: od
Hide Thread Field: check all.
Input Field Type: Checkboxes
Value List: D
Custom Modify Error:
This one forces user to select at least one options.

Code:
<if !$mybb->input['xthreads_oa'] && !$mybb->input['xthreads_ob'] && !$mybb->input['xthreads_oc'] && !$mybb->input['xthreads_od'] then>
Please select at least one Options
</if>

Multiple Value Delimiter: space or whatever
Filtering Mode: Exact match

Insert this code inside the form (for example before {$posticons}) in template_prefix_newthread and template_prefix_editpost_first

HTML Code
<tr>
<td class="trow2" width="20%"><strong>Options</strong></td>
<td class="trow2">{$tfinput['oa']} {$tfinput['ob']} {$tfinput['oc']} {$tfinput['od']}</td>
</tr>


Then for filtering interface, insert this code inside the form in template_prefix_forumdisplay_searchforum_inline (don't forget to activate the Enable XThreads' Inline Forum Search setting:

HTML Code
<input type="checkbox" class="checkbox" name="filtertf_oa" value="A"{$GLOBALS['filters_set']['oa']['checked']['A']}  /> A
<input type="checkbox" class="checkbox" name="filtertf_ob" value="B"{$GLOBALS['filters_set']['ob']['checked']['B']}  /> B
<input type="checkbox" class="checkbox" name="filtertf_oc" value="C"{$GLOBALS['filters_set']['oc']['checked']['C']}  /> C
<input type="checkbox" class="checkbox" name="filtertf_od" value="D"{$GLOBALS['filters_set']['od']['checked']['D']}  /> D



Attached File(s) Thumbnail(s)
       

09-25-2015 05:56 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #7
RE: ANDing multiple values in a field
Your solution is probably the best there is.  I'm not sure if there's a nice way to toggle OR/AND, so I picked the most likely to be used, OR.
Filtering on multi-valued fields is quite ugly, so I didn't really want to put much effort into it.  It's there for completeness sake, but the performance of the queries needed to achieve it is quite bad.

My Blog
09-29-2015 12:24 PM
Find all posts by this user Quote this message in a reply
umetkaran Offline
Member
***
Posts: 110
Joined: Aug 2014
Post: #8
RE: ANDing multiple values in a field
(09-24-2015 03:12 AM)ln_e Wrote:  Thanks for the help anyway! Smile

I think I've figured it out in the meantime, although would still like to know if there is a less hacky solution.

For anyone looking to do something similar, this is the part that handles multiple select queries in xt_forumdhooks.php


Quote:$qstr .= $qor.$cfield.' LIKE "'.$qlpre.xthreads_forumdisplay_filter_parselike($v, $filtermode).$qlpost.'"';
if(!$qor) $qor = ' OR ';

This is where the multiple values are ORed together, you can just duct tape it with an AND:

Quote:$qstr .= $qor.$cfield.' LIKE "'.$qlpre.xthreads_forumdisplay_filter_parselike($v, $filtermode).$qlpost.'"';
if(!$qor) $qor = ' AND ';


Not a pretty solution by any means, but it does the job.

(09-29-2015 12:24 PM)ZiNgA BuRgA Wrote:  Your solution is probably the best there is.  I'm not sure if there's a nice way to toggle OR/AND, so I picked the most likely to be used, OR.

i try this way, but not work. & filter mode i changed (exact macth, contains, wildcard)

for simple choosing (with little choice), i try RateU solution.

wowtopik.com -> + marketplace forum & youtube sharing
webdiskus.com -> + website marketplace (domain, web, hosting etc)
(This post was last modified: 02-03-2017 10:22 AM by umetkaran.)
06-22-2016 06:05 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: