Tridion Filter : replacement for SetCustomMetaQuery

273 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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

1
On

Please try with:

CustomMetaValueCriteria criteria1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("Key"), "Yes", Criteria.GreaterThanOrEqual);

Let me know if this works.