215 Posts
iliil
6 years ago
3
Topic

Hello

I want to search for items based on selected tags. I need to filter items containing all selected tags so I use match mode “each word exact” and in the settings define comma (,) as the separator.

However, SEBLOD builds the search query like this:

		AND ((t1.tag_id LIKE '4,%' OR t1.tag_id LIKE '%,4,%' OR t1.tag_id LIKE '%,4')
		AND (t1.tag_id LIKE '5,%' OR t1.tag_id LIKE '%,5,%' OR t1.tag_id LIKE '%,5'))

This query will not find any items. The match mode is “each word exact” so I guess the comma should not be there (it is a separator of words). Should the query look more like this?

	AND t1.tag_id = '4'
	AND t1.tag_id = '5'

Is it a bug in this match mode or I overlooked something.

Thanks for help

Michal

Get a Book for SEBLOD
1283 Posts
Bucklash
6 years ago
0
Level 1

You seen cryil’s solution?

https://www.seblod.com/community/forums/lists-search-types/search-contents-with-several-tags

Not sure if Seblod has solution yet

215 Posts
iliil
6 years ago
0
Level 1

Yes, I looked at Cyril's plugin. It's a good job, working well.

But I don't feel comfortable to use third-party plugins for something that can work in the core SEBLOD.

I would like to clarify the "each word exact" functionality first. To me, it seems like a bug... 

Thanks

Mic

215 Posts
iliil
6 years ago
0
Level 1

Hi, I am replying my own post as I start to understand this issue :).

It is a relational division problem. Cyril's solution works but it is too complicated (requires a special field to collect ids of multiple tagged items).

My solution for art_tags (or any other joined mapping table) is to use "any words exact" mode together with "having" clause defining dynamically the exact number of searched tags.

Here is the solution.

I'm looking for items having both of selected two tags (IDs 4 and 5).

1) Apply the "any words exact" mode to art_tags field, that adds the list of desired tags

	 AND t1.tag_id IN ('4','5')

2) Add HAVING clouse with a number of tags defined

HAVING COUNT(t0.id) = 2

It is very simple, however, I didn't find the way how to dynamically add the number of selected tags to the query without Seblod code modifications. So this post is mainly for SEBLOD developers for an insiration :)

For art_tags plugin, I just added a couple of rows to the onCCK_FieldPrepareSearch function

$cnt = count($value); //counts the ammout of selected tags

if ( $isMultiple ) { //existing variable definging if mutliple tags were seleced

$config['query_parts']['having'][] = 'COUNT(t0.id) = '. $cnt; // adds the HAVING clouse to search query

}

This works for me.

It would be nice to be able to to use this approach not only for the art_tags field but also for any other relational content. There is a Seblod field called "search query" that allows appending HAVING clause, but again I didn't find the way how to dynamically pass the number of selected items to the field settings.

Well, that is my contribution to this issue..Michal

Get a Book for SEBLOD