Saved search conditions criteria
The SearchCriteria property of a saved search object is specified as a CriteriaCollection object. CriteriaCollection contains the Conditions property that holds individual Criteria objects or grouped Criteria delimited by parentheses as additional CriteriaCollection objects.
Criteria
A Criteria object is equivalent to a single saved search field condition defined in the Relativity user interface. The object has the following properties:
- Condition – set to either a CriteriaCondition or CriteriaDateCondition. This describes the rule for the field.
- BooleanOperator – must be set to AND or OR using the CriteriaOperatorEnum if there is another Criteria that follows. If not set it will default to AND. CriteriaOperatorEnum values are:
Member name Value Description None 0 None. And 1 Logical AND. Or 2 Logical OR.
CriteriaCollection
The CriteriaCollection object represents a grouping of criteria. You can add a CriteriaCollection to the Conditions list of an existing CriteriaCollection to create grouped conditions delimited by parentheses.
CriteriaCollection has the following properties:
- Conditions – a List that Criteria or additional CriteriaCollection objects should be added to in order to create the entire set of search rules.
- BooleanOperator - must be set to AND or OR using the CriteriaOperatorEnum enumeration if there is another Criteria that follows.
The Conditions property on the Search DTO should be set to a CriteriaCollection object. The initial CriteriaCollection object represents conditions without grouping, but if additional CriteriaCollection objects are added, they will be grouped. See Grouped conditions example.
The following examples illustrate how to create CriteriaCollection objects with the relationship operators between criteria and criteria groups.
Single condition example
The following example sets a Criteria with a condition that checks for a field with the name FixedLengthField equal to “abc”. The Condition property on the Criteria is set to a new CriteriaCondition object with the operator and the field name and value. Then the Criteria object is added to a CriteriaCollection. Finally, the SearchCriteria property of the previously instantiated search DTO is set to the Criteria collection.
// Create a Criteria for the field named "Email Subject" where the value is "FW: "
// NOTE: We assume a field named "Email Subject" exists therefore it can be set by only the name.
// It can also be defined by ArtifactID, ViewFieldID, or Guid.
Criteria criteria = new Criteria();
criteria.Condition = new CriteriaCondition(new Services.Field.FieldRef()
{
Name = "Email Subject"
}, CriteriaConditionEnum.IsLike, "FW: ");
// Add the search condition criteria to the collection.
search.SearchCriteria.Conditions.Add(criteria)
Multiple conditions example
This example demonstrates how to add another Criteria to the CriteriaCollection created in the previous example with a logical OR operator between them ("A OR B"). The relationship between the Criteria in the CriteriaCollection is defined in the Operator property of the first criteria using the CriteriaOperatorEnum.Or enumeration member.
// Create the CriteriaCollection to store the criteria for the search DTO
CriteriaCollection baseConditionCollection = new CriteriaCollection();
// Create a Criteria for the field named "Email Subject" where the value is "FW: "
// NOTE: We assume a field named "Email Subject" exists therefore it can be set by only the name.
// It can also be defined by ArtifactID, ViewFieldID, or Guid.
Criteria criteria1 = new Criteria();
criteria1.Condition = new CriteriaCondition(new Services.Field.FieldRef()
{
Name = "Email Subject"
}, CriteriaConditionEnum.IsLike, "FW: ");
// Set the operator to "Or" to join the two conditions.
criteria1.BooleanOperator = BooleanOperatorEnum.Or;
// Create a second criteria to add to baseConditionCollection
Criteria criteria2 = new Criteria();
criteria2.Condition = new CriteriaCondition(new Services.Field.FieldRef()
{
Name = "Designation"
}, CriteriaConditionEnum.AnyOfThese, new List<int> { 112233, 987987 });
// Add both criteria to the baseConditionCollection and set the DTO
baseConditionCollection.Conditions.Add(criteria1);
baseConditionCollection.Conditions.Add(criteria2);
search.SearchCriteria = baseConditionCollection;
Grouped conditions example
This example demonstrates how to create a logical “(A OR B) AND C” grouping of conditions within a CriteriaCollection by instantiating an additional CriteriaCollection object and adding it to the initial CriteriaCollection.Conditions, followed by a single Criteria object.
// Create the CriteriaCollection to store the criteria for the search DTO
CriteriaCollection baseConditionCollection = new CriteriaCollection();
// Create a new CriteriaCollection for the first set of criteria within the parentheses
CriteriaCollection collectionWithinParens = new CriteriaCollection();
// Create the first two criteria, with an Or BooleanOperator on criteria1, before criteria2
Criteria criteria1 = new Criteria();
criteria1.Condition = new CriteriaCondition(new Services.Field.FieldRef()
{
Name = "Designation"
}, CriteriaConditionEnum.AnyOfThese, new List<int> { 112233, 987987 });
// Add Or BooleanOperator on criteria1.
criteria1.BooleanOperator = BooleanOperatorEnum.Or;
// Add a boolean condition as criteria2.
Criteria criteria2 = new Criteria();
criteria2.Condition = new CriteriaCondition(new Services.Field.FieldRef()
{
Name = "Read Receipt"
}, CriteriaConditionEnum.Is, true);
// Add criteria1 and criteria2 to the collectionWithinParens
collectionWithinParens.Conditions.Add(criteria1);
collectionWithinParens.Conditions.Add(criteria2);
// Set the And BooleanOperator following the collectionWithinParens
collectionWithinParens.BooleanOperator = BooleanOperatorEnum.And;
// Add the collectionWithinParens to the baseConditionCollection
baseConditionCollection.Conditions.Add(collectionWithinParens);
// Create the third Criteria
Criteria criteria3 = new Criteria();
criteria3.Condition = new CriteriaCondition(new Services.Field.FieldRef()
{
Name = "Email Subject"
}, CriteriaConditionEnum.IsLike, "FW: ");
// Add criteria3 to the baseConditionCollection then set the DTO to the base collection.
baseConditionCollection.Conditions.Add(criteria3);
search.SearchCriteria = baseConditionCollection;
CriteriaCondition
The CriteriaCondition object represents a condition for a single non-date Relativity field.
CriteriaCondition includes the following properties:
- FieldIdentifier
- Operator
- NotOperator
- Value
The field must be identified by Name, ArtifactID, or GUID. Use GetFieldsForCriteriaConditionAsync helper method in the saved search interfaces to return the available workspace fields.
The Operator property must be set to a Value of CriteriaConditionEnum. Note that all of the values of the enumeration are not valid for every type of field. The values that can be used correspond to the options available through the Relativity user interface for the field type.
The NotOperator is used to negate a value of CriteriaConditionEnum, by setting NotOperator = true. It is not permitted for some combinations identified in the table below.
The Value property must be set. Value is an object, but its underlying type depends on the value of CriteriaConditionEnum and the type of field. Use the GetFieldsForObjectCriteriaCollectionAsync helper method in the saved search interfaces to return the fields that that can be specified as a subcondition in batch and multi-object conditions.
The following table describes the requirements and allowed CriteriaConditionEnum values for each type of field.
Field Type |
CriteriaCondtionEnum |
Value Type |
Notes |
---|---|---|---|
Text |
AnyOfThese |
List<int> or int[] |
|
Text |
IsSet |
null |
|
Text |
Is, IsLike, LessThan, GreaterThan, StartsWith, EndsWith |
String |
|
Text |
Contains |
String |
Allowed when Include in Text is true and Open to Associations is false. |
Yes/No |
IsSet |
null |
|
Yes/No |
Is |
bool |
|
Single Choice |
IsSet |
null |
|
Single Choice |
AnyOfThese |
List<int> or int[] List<Guid> or Guid[] |
|
Multiple Choice |
IsSet |
null |
|
Multiple Choice |
AnyOfThese, AllOfThese |
List<int> or int[] List<Guid> or Guid[] |
|
Single Object |
IsSet |
null |
|
Single Object |
AnyOfThese |
List<int> or int[] List<Guid> or Guid[] |
|
Single Object |
IsLike |
String |
|
Single Object |
LessThan, GreaterThan |
String |
NotOperator cannot be set to true. |
Multiple Object |
In |
CriteriaCollection |
The value is another set of criteria defined by instantiating a new CriteriaCollection. |
Batch |
In |
CriteriaCollection |
The value is another set of criteria defined by instantiating a new CriteriaCollection. |
Multiple Object, Batch condition value |
IsSet |
null |
NotOperator cannot be set to true |
Multiple Object, Batch condition value |
AnyOfThese, AllOfThese |
List<int> or int[] List<Guid> or Guid[] (for Multiple Object) |
|
Multiple Object, Batch condition value |
IsLIke |
String |
|
Multiple Object, Batch |
LessThan, GreaterThan |
String |
NotOperator cannot be set to true |
Number (Whole Number, Currency, Decimal) |
IsSet |
null |
|
Number (Whole Number, Currency, Decimal) |
Is, GreaterThan, LessThan |
A valid number. |
|
User |
IsLoggedInUser |
null |
NotOperator cannot be set to true |
User |
IsSet |
null |
|
User |
AnyOfThese |
List<int> or int[] |
|
Extracted Text or Full Text |
Contains |
String |
|
Saved Search |
In |
int |
|
CriteriaDateCondition
The CriteriaDateCondition object represents a condition for a single date-type Relativity field.
CriteriaCondition includes the following properties:
- FieldIdentifier
- Operator
- NotOperator
- Value
- Month
The field must be identified by Name, ArtifactID, or GUID.
The Operator property must be set to a Value of CriteriaDateConditionEnum.
The NotOperator property is used to negate a value of CriteriaDateConditionEnum by setting NotOperator = true.
The Value property must be set. The following table presents value types corresponding to CriteriaDateConditionEnum operators.
CriteriaDateConditionEnum |
Value Type |
Notes |
---|---|---|
IsSet |
null |
|
Is, IsBefore, IsBeforeOrOn, IsAfter, IsAfterOrOn |
DateTime |
|
Between |
List<DateTime> or DateTime[] |
Must contain two DateTime objects. |
In |
DateTimeRange enumeration |
If DateTimeRange = MonthOf then Month must be set from the Month enumeration. |
The Value property can be set to DateTimeRange using the DateTimeRange enumeration.
The Month property must be set when the Value property is set to DateTimeRange.MonthOf using the Month enumeration.
CriteriaDateCondition examples
Date is 8/24/2015:
criteria1.Condition = new CriteriaDateCondition("Date Field", CriteriaDateConditionEnum.Is, new DateTime(2015, 08, 24));
Date is between 8/1/2015 and 8/15/2015:
criteria1.Condition = new CriteriaDateCondition("Date Field", CriteriaDateConditionEnum.Between, new List<DateTime>{new DateTime(2015, 08, 01), new DateTime(2015, 08, 15));
Date is in next Week:
criteria1.Condition = new CriteriaDateCondition("Date Field", CriteriaDateConditionEnum.In, DateTimeRange.NextWeek);
Date is in the month of August:
criteria1.Condition = new CriteriaDateCondition("Date Field", CriteriaDateConditionEnum.In, DateTimeRange.MonthOf, Month.August);