tridiontridion-2011tridion-content-delivery

Tridion Filter : replacement for SetCustomMetaQuery


What is the replacement for SetCustomMetaQuery in Broker query Mechanism (Tridion 2011)? I got lots of help through this post posted by me earlier.

for

query.SetCustomMetaQuery("KEY_NAME='Key' AND KEY_STRING_VALUE >= 'Yes'");

I tried

CustomMetaValueCriteria criteria1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("Key"), "Yes");
mainCriteria =CriteriaFactory.And(mainCriteria, criteria1);
query.Criteria = mainCriteria;

But I am stuck at below two examples in one of the filter CTs.

query.SetCustomMetaQuery("(((KEY_NAME='EventStartDate' AND 
KEY_DATE_VALUE >= '" + lowerDate + "')) or
((KEY_NAME='EventEndDate' AND KEY_DATE_VALUE >= '" + lowerDate + "')))"")

and

query.SetCustomMetaQuery("KEY_NAME = 'Publication_Issue_Date' and 
((convert(varchar(10), key_date_value, 101) = convert(varchar(10), 
cast('" + sIssueDate + "' as datetime), 101)) or
key_string_value like '%" + dtIssue[%=nNumber%].Year + "-0" + dtIssue[%=nNumber%].Month + "-" + dDay[%=nNumber%] + "%')");

Could any please help me with this?


Solution

  • Thought I'd have a stab at this so could be way off!

    How's this for the first example:

    CustomMetaValueCriteria criteria1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("EventStartDate"), lowerDate, Criteria.GreaterThanOrEqual);
    CustomMetaValueCriteria criteria2 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("EventEndDate"), lowerDate, Criteria.GreaterThanOrEqual);
    
    OrCriteria or = new OrCriteria(criteria1, criteria2);
    

    Assumes that "lowerDate" is a DateTime.

    The second one is a bit confusing, it looks like its checking for the existence of "Publication_Issue_Date" and any KEY_DATE_VALE that equals the sIssueDate variable OR that there's a string metadata value in the from of a date. So is that going to be something like?

    CustomMetaKeyCriteria criteria1 = new CustomMetaKeyCriteria ("Publication_Issue_Date")
    CustomMetaValueCriteria criteria2 = new CustomMetaValueCriteria(sIssueDate);
    AndCriteria andCriteria = new AndCriteria(criteria1, criteria2);
    
    string dt = dtIssue[%=nNumber%].Year + "-0" + dtIssue[%=nNumber%].Month + "-" + dDay[%=nNumber%];
    CustomMetaValueCriteria criteria3 = new CustomMetaValueCriteria(dt, Criteria.Like)
    
    OrCriteria or = new OrCriteria(andCriteria, criteria3);
    

    Cheers