Share » Forums » Setup & design » help with complex attribute_filter

help with complex attribute_filter

help with complex attribute_filter

Wednesday 15 September 2004 3:09:17 am - 8 replies

Author Message

Paul Borgermans

Wednesday 15 September 2004 4:37:52 am

Hi Alessandro

You cannot 'nest' and/or attribute filtering AFAIK. In similar instances, I use the patched ezobjectcontenttreenode.php class (see contribs) to allow for 'in' logic. This can be used in your situation.

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Alessandro Cipriani

Wednesday 15 September 2004 6:00:42 am

thanks paul!
i downloaded the patched file, but i never used the 'in' clause.
please, can you give me an example on how to translate the 'and' (/'or') clause in the 'in' one?

best regards
alessandro

Paul Borgermans

Wednesday 15 September 2004 9:12:08 am

Hi Alessandro,

something like:

attribute_filter, array(and,array(322,'=',0),array(331,'in','(1,2,3)')))),

So the 'in' behaves like a nested 'or'

If you need text as possibilities, you will have to surround them with quotes and build your in variable outside the fetch in a {let} block. The array implode/concat operators are your friends there

simplified example:

{let myselection="('all','all-but-one')"

...   attribute_filter, array(and,array(322,'=',0),array(331,'in',$myselection)))),

{/let}

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Alessandro Cipriani

Thursday 16 September 2004 1:01:12 am

hi paul
thanks for your replies
but i still am not able to get it work...
that's the code:

			{let memo=fetch( content, tree, hash( parent_node_id, 250,
									class_filter_type, "include",
									class_filter_array, array(42),
									depth, 10,
									attribute_filter, array(and,array(322,'=',0),array(331,'in',"('call','tutti')")),
									limit, 5,
									sort_by, array( published, false() )
									))}

and i don't retrieve any memo.
that's the sql output:

SELECT ezcontentobject.*,
ezcontentobject_tree.*,
ezcontentclass.name as class_name

, ezcontentobject_name.name as name, ezcontentobject_name.real_translation
FROM
ezcontentobject_tree,
ezcontentobject,ezcontentclass
, ezcontentobject_name

, ezcontentobject_attribute a1 , ezcontentobject_attribute a2

WHERE
path_string like '/1/2/250/%' and depth <= 12 and



a1.contentobject_id = ezcontentobject.id AND
a1.contentclassattribute_id = 322 AND
a1.version = ezcontentobject_name.content_version AND
a1.language_code = ezcontentobject_name.real_translation AND
a2.contentobject_id = ezcontentobject.id AND
a2.contentclassattribute_id = 331 AND
a2.version = ezcontentobject_name.content_version AND
a2.language_code = ezcontentobject_name.real_translation AND
( a1.sort_key_int = '0' AND a2.sort_key_string IN (\'call\',\'tutti\') ) AND
ezcontentclass.version=0 AND
node_id != 250 AND
ezcontentobject_tree.contentobject_id = ezcontentobject.id AND
ezcontentclass.id = ezcontentobject.contentclass_id AND

( ezcontentobject.contentclass_id = '42' ) AND
ezcontentobject_tree.contentobject_is_published = 1
and ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id and
ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version and
ezcontentobject_name.content_translation = 'ita-IT'
AND ((ezcontentobject.section_id in (1, 10, 11, 5, 8)) or (ezcontentobject.contentclass_id in (16) AND ezcontentobject.section_id in (2)) or (ezcontentobject.section_id in (10, 6, 8)) or (ezcontentobject.contentclass_id in (44) AND ezcontentobject.section_id in (5)))

ORDER BY ezcontentobject.published DESC
LIMIT 0, 5

the error i retrieve when i paste the query in the mysql client is:
Error: You have mismatched `'`

any hint?
thanks a lot
alessandro

Paul Borgermans

Thursday 16 September 2004 1:28:22 am

Hi Alessandro,

Unfortunately you need to contruct the string for the 'in' filter outside the fetch to avoid the escapes on the quote characters.

{let myinstring=concat("('",'call',"','",'tutti',"')")
     memo=fetch( content, tree, hash( parent_node_id, 250,
		class_filter_type, "include",
		class_filter_array, array(42),
		depth, 10,
		attribute_filter, array(and,array(322,'=',0),array(331,'in',$myinstring)),
		limit, 5,
		sort_by, array( published, false() )
		))}
My inistring: {$myinstring}
{/let}

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Alessandro Cipriani

Friday 17 September 2004 6:33:15 am

paul
i pasted your code in my tpl but the error i get is the same:

SELECT ezcontentobject.*,
ezcontentobject_tree.*,
ezcontentclass.name as class_name

, ezcontentobject_name.name as name, ezcontentobject_name.real_translation
FROM
ezcontentobject_tree,
ezcontentobject,ezcontentclass
, ezcontentobject_name

, ezcontentobject_attribute a1 , ezcontentobject_attribute a2

WHERE
path_string like '/1/2/250/%' and depth <= 12 and



a1.contentobject_id = ezcontentobject.id AND
a1.contentclassattribute_id = 322 AND
a1.version = ezcontentobject_name.content_version AND
a1.language_code = ezcontentobject_name.real_translation AND
a2.contentobject_id = ezcontentobject.id AND
a2.contentclassattribute_id = 331 AND
a2.version = ezcontentobject_name.content_version AND
a2.language_code = ezcontentobject_name.real_translation AND
( a1.sort_key_int = '0' AND a2.sort_key_string IN (\'call\',\'tutti\') ) AND
ezcontentclass.version=0 AND
node_id != 250 AND
ezcontentobject_tree.contentobject_id = ezcontentobject.id AND
ezcontentclass.id = ezcontentobject.contentclass_id AND

( ezcontentobject.contentclass_id = '42' ) AND
ezcontentobject_tree.contentobject_is_published = 1
and ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id and
ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version and
ezcontentobject_name.content_translation = 'ita-IT'
AND ((ezcontentobject.section_id in (1, 10, 11, 5, 8)) or (ezcontentobject.contentclass_id in (16) AND ezcontentobject.section_id in (2)) or (ezcontentobject.section_id in (10, 6, 8)) or (ezcontentobject.contentclass_id in (44) AND ezcontentobject.section_id in (5)))

ORDER BY ezcontentobject.published DESC
LIMIT 0, 5

Error: You have mismatched `'`

...
thanks for your patience..
best regards
alessandro

Alessandro Cipriani

Friday 17 September 2004 6:47:28 am

ooooops....
paul, i've seen where is the problem... i'm using the 3.4.0 version... is there nothing to do with the 3.4.0?
i can't upgrade right now....
thanx a lot
alessandro

Paul Borgermans

Friday 17 September 2004 7:07:06 am

Yes, must be a bug in 3.4.0 (or php settings?)

I tested it on 3.4.1 and 3.4.2 (from pubsvn) and it works here like intended.

I was thinking of making it easier, like the possibility to supply an array instead of a string, but too much time constraints now.

Don't you have other issues with 3.4.0 as well? Try hard to upgrade, lots of things have been fixed in the 3.4.2 branch on pubsvn

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu