Tridion: Replacement for Query.QueryOperator metho

2020-03-25 16:55发布

问题:

Query.QueryOperator.AND_Field We were using this method in Tridion R5.3 VBscript templates and it worked well. Recently , while migrating to Tridion 2011 SP1, we tried using this method, but it doesn't works. We understood that this method is depreciated in new tridion versions.

As per some posts in Forum, we also enabled the following lines in CD_Storage_Conf:

<SearchFilter Name="SearchFilter" Class="com.tridion.broker.components.meta.MsSqlSearchFilterHome" defaultStorageId="defaultdb"/> 
<Item typeMapping="Query" storageId="defaultdb"/>

The question is, what is replacement of the 'Query.QueryOperator.AND_Field' method? How can we use this filter in C# ? How to use the Broker Querying Mechanism mentioned in the support API files?

Thanks.

回答1:

In SDL Tridion 2011 Content Delivery, you create a Query object and add a Criteria object to it using the setCriteria method. The Query object accepts one Criteria object ONLY, but that Criteria object can in turn reference other Criteria objects in a tree structure.

For a good example of creating a Query filter using both AND and OR operators, see Creating a filter in the SDL Tridion 2011 SP1 documentation in SDL LiveContent.

// Schema has ID of either 511 (Article) or 34 (Press Release).
ItemSchemaCriteria IsArticle = new ItemSchemaCriteria(511);
ItemSchemaCriteria IsPressRelease = new ItemSchemaCriteria(34);
Criteria IsArticleOrPressRelease = CriteriaFactory.Or(IsArticle, IsPressRelease);

// Type of the item is 16 (Component).
ItemTypeCriteria IsComponent = new ItemTypeCriteria(16);

// Both of the above conditions must be true
Criteria AllCriteria = CriteriaFactory.And(IsArticleOrPressRelease, IsComponent);

// Add these criteria to a query
Query MyQuery = new Query();
MyQuery.Criteria = AllCriteria;