Forums / General / attribute_filter and two "like"

attribute_filter and two "like"

Author Message

Philippe VINCENT-ROYOL

Wednesday 09 January 2008 6:08:53 am

Hi,

I've a problem with a fetch function.. I want to concat this two lines but it does nt work ..

$children=fetch( 'content', 'tree', hash( 'parent_node_id',$metiers_node.node_id, 'sort_by',array( 'name', true()), 'class_filter_type','include',
'class_filter_array',array( 'job', 'chained_article' ),
'attribute_filter', array( array('job/title' ,'like', $montitre) ) ) )

$children=fetch( 'content', 'tree', hash( 'parent_node_id',$metiers_node.node_id, 'sort_by',array( 'name', true()), 'class_filter_type','include',
'class_filter_array',array( 'job', 'chained_article' ),
'attribute_filter', array( array('chained_article/title' ,'like', $montitre) ) ) )

It work when i use only the first or the second.. But when i try:

$children=fetch( 'content', 'tree', hash( 'parent_node_id',$metiers_node.node_id, 'sort_by',array( 'name', true()), 'class_filter_type','include',
'class_filter_array',array( 'job', 'chained_article' ),
'attribute_filter', array( 'or', array('job/title' ,'like', $montitre), array('chained_article/title', 'like', $montitre) ) ) )

They are no answer :/

What i m doing wrong?

Thanks

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Heath

Wednesday 09 January 2008 6:24:23 am

Hello Philippe,

Welcome to the eZ Ecosystem!

I've not read your code, yet this post seems very similar in subject. I think I covered this with detailed examples recently.

<i>http://ezpedia.org/wiki/en/ez/solution_how_to_do_an_attribute_filter_using_the_like_condition
http://ez.no/developer/forum/developer/attribute_filter_breaking_fetch</i>

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Philippe VINCENT-ROYOL

Wednesday 09 January 2008 6:31:23 am

Hello Heath,

Thanks for your reply. But i ve already read your link and i cant find why i want finally ..

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Heath

Wednesday 09 January 2008 6:47:47 am

My concern is not with your broken English, it is with your insistence to combine 'class_filter_array' and 'attribute_filter' which I have never seen work successfully within a single fetch.

I think you would be best served in seeking another solution.

Remember 'attribute_filter' is more powerful than 'class_filter_array'. Meaning you don't need the class filter if your using attribute filter because the attribute filter by it's own nature includes it's own class filter internally ... from what I have seen in dev.

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Philippe VINCENT-ROYOL

Wednesday 09 January 2008 6:47:50 am

ive found a solution:

$children1=fetch( 'content', 'tree', hash( 'parent_node_id',$metiers_node.node_id, 'sort_by',array( 'name', true()), 'class_filter_type','include',
'class_filter_array',array( 'job', 'chained_article' ),
'attribute_filter', array( array('job/title' ,'like', $montitre) ) ) )

$children2=fetch( 'content', 'tree', hash( 'parent_node_id',$metiers_node.node_id, 'sort_by',array( 'name', true()), 'class_filter_type','include',
'class_filter_array',array( 'job', 'chained_article' ),
'attribute_filter', array( array('chained_article/title' ,'like', $montitre) ) ) )

$children=merge($children1, $children2)

And it works..

Thanks.

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

André R.

Wednesday 09 January 2008 9:48:57 am

The correct thing would be (using code tags so others even bother reading you code..):

{def $children1 = fetch( 'content', 'tree', hash(
        'parent_node_id', $metiers_node.node_id,
        'sort_by', array( 'name', true()),
        'class_filter_type', 'include', 
        'class_filter_array', array( 'job' ), 
        'attribute_filter', array( array('job/title' ,'like', $montitre) )
       ) ) 
       $children2 = fetch( 'content', 'tree', hash(
        'parent_node_id', $metiers_node.node_id,
        'sort_by', array( 'name', true()),
        'class_filter_type', 'include', 
        'class_filter_array', array( 'chained_article' ), 
        'attribute_filter', array( array('chained_article/title' ,'like', $montitre) )
       ) ) 
       $children = merge( $children1, $children2 )}

Heath: It's true that attribute filter will effectively filter classes as well, but index wise I think using a class filter as well is faster on large dataset. But this depend on the indexes on the ezcontentobject_attribute table, haven't looked at it for a while.
Ref:
http://pubsvn.ez.no/nextgen/trunk/kernel/classes/ezcontentobjecttreenode.php
Search for "function createAttributeFilterSQLStrings".

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Philippe VINCENT-ROYOL

Tuesday 15 January 2008 3:07:48 am

Thanks it works ;)

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Piotr Switkowski

Sunday 03 February 2008 1:51:21 pm

Well, doing two separate fetches and merging results is not the same thing as doing one fetch. The real difference is performance. Let assume, you implemented paging on your website. With single fetch you need to retrieve only few objects for one page. With two fetches and merging you need to retrieve all fitting objects. Also, with merging you cannot sort in database. If you want the result sorted, you need to sort in your template code.

All in all, I cannot understand, why attribute_filter is not supporting attribute filtering on attributes from different classes with 'or'. Should this be registered as ezPublish bug?