AquaLogic User Interaction Development Guide

     Previous Next  Open TOC in new window   View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Using Query Constraints with the IDK Remote Search API

To limit search results to an object type or filter on a specific object property, use constraints.

Portal properties are represented as standard fields (PortalField, PlumtreeField) that can be accessed in search results by name or by iteration. By default, searches return a set of standard properties; you can choose to retrieve additional properties. To find the property ID, edit the property and note the ObjectID in the query string (for example, &in_hi_ObjectID=206).
This example sets constraints to limit the results to documents that are less than a year old.
Note: The code below should be executed within a method that can throw a SearchException and a RemoteException.

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)
...

  Back to Top      Previous Next