To limit search results to an object type or filter on a specific object property, use constraints.
Java
...
//add a property field to the search
//SetFieldsToReturn adds fields to the existing default fields
//make the PortalField based on the property ID
int propertyID = 206;
Field[] fieldsToReturn = new Field[] {PortalField.forID(propertyID)};
searchRequest.setFieldsToReturn(fieldsToReturn);
//constrain the results to documents
ObjectClass[] objectClasses = new ObjectClass[] {ObjectClass.Document};
searchRequest.setObjectTypesToSearch(objectClasses);
//return only documents that are less than a year old
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -1);
Date createdDate = cal.getTime();
IFilterClause filterClause = searchFactory.createAndFilterClause();
filterClause.addStatement(PlumtreeField.CREATED, Operator.GreaterThan, createdDate);
searchRequest.setQuery(searchString, filterClause);
//execute the query and display the results
DisplayResults(searchRequest, propertyID);
...
.NET (C#)
...
//add a property field to the search
//SetFieldsToReturn adds fields to the existing default fields
//make the PortalField based on the property ID
int propertyID = 206;
Field[] fieldsToReturn = new Field[] {PortalField.ForID(propertyID)};
searchRequest.SetFieldsToReturn(fieldsToReturn);
//constrain the results to documents
ObjectClass[] objectClasses = new ObjectClass[] {ObjectClass.Document};
searchRequest.SetObjectTypesToSearch(objectClasses);
//return only documents that are less than a year old
DateTime createdDate = DateTime.Today.AddYears(-1);
IFilterClause filterClause = searchFactory.CreateAndFilterClause();
filterClause.AddStatement(PlumtreeField.CREATED, Operator.GreaterThan, createdDate);
searchRequest.SetQuery(searchString, filterClause);
//execute the query and display the results
DisplayResults(searchRequest, propertyID);
...
.NET (VB)
... 'add a property field to the search 'note that SetFieldsToReturn only adds fields to the existing default fields 'make the PortalField based on the property ID Dim propertyID As Int32 = 206 Dim fieldsToReturn(0) As Field fieldsToReturn(0) = PortalField.ForID(propertyID) searchRequest.SetFieldsToReturn(fieldsToReturn) 'constrain the results to documents Dim objectClasses(0) As ObjectClass objectClasses(0) = ObjectClass.Document searchRequest.SetObjectTypesToSearch(objectClasses) 'return only documents that are less than a year old Dim createdDate As DateTime = DateTime.Today.AddYears(-1) Dim filterClause As IFilterClause = searchFactory.CreateAndFilterClause() filterClause.AddStatement(PlumtreeField.CREATED, Operator.GreaterThan, createdDate) searchRequest.SetQuery(searchString, filterClause) 'execute the query and display the results DisplayResults(searchRequest, propertyID) ...