execute query to search work items
Set<IWorkItem> processResolvedResults = new HashSet<IWorkItem>();ITeamRepository teamRepository = sourceRTCConBridge.getTeamRepository();IProjectArea projectArea = sourceRTCConBridge.getProjectAreas().stream().filter(p -> p.getName().equals(sourceProjectArea)).collect(Collectors.toList()).get(0);IAuditableClient auditableClient = (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);IQueryClient queryClient = (IQueryClient) teamRepository.getClientLibrary(IQueryClient.class);SimilarityExpression se = new SimilarityExpression(summaryText,summaryText, null);IQueryableAttribute projectAttribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, sourceRTCConBridge.getMonitor());Expression projectExpression = new AttributeExpression(projectAttribute, AttributeOperation.EQUALS, projectArea);String propertyName = "my.attribute.id";Term term = new Term(Operator.AND);term.add(projectExpression);term.add(problemExpression);term.add(se);QueryResult<IResolvedResult<IWorkItem>> results =queryClient.getResolvedExpressionResults(projectArea, term,IWorkItem.FULL_PROFILE);results.setLimit(Integer.MAX_VALUE);
IQueryableAttribute probattribute=QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, propertyName, auditableClient, sourceRTCConBridge.getMonitor());Expression problemExpression = new AttributeExpression(probattribute, AttributeOperation.CONTAINS, summaryText);
term.add(problemExpression);
while (sourceWorkItems.hasNext(bridge.getMonitor())){...
com.ibm.team.repository.common.query.QueryException: Like predicate is not supported on this query model - com.ibm.team.workitem.common.internal.model.query.impl.WorkItemQueryModelImpl@cbe55221
2 answers
You can't see your custom attributes when creating a query in the web UI? Are you saying that you can't query using your custom attributes at all???
You should be able to do it, of course. I would focus on fixing that before considering to use the API.
The CONTAINS operator can be used with Large HTML attributes.
However, if you just need to search across several project areas, JRS is by far the easiest option. It only takes a minute to create such query.
If you still need to retrieve those work items using the API for whatever reason, I would do as I suggested before: create the queries manually for each Project Area and run them using the API.
"I can display my custom attributes in the results, but i'm not able to set a condition on these attributes."
Something is definitely wrong with that. As I said, I would focus on fixing that. Have you contacted IBM Support?
" I wanna have a score in combination with the results. When i use a manually defined query, I can't get a score..."
As I said, I would use JRS for that. It'll be a hundred times easier to implement than creating a Java API script, and a hundred times faster to run. If you can't use JRS, I would also consider BIRT.
Comments
Miguel Tomico
Oct 26 '16, 8:23 a.m.Your code looks ok.
Are you sure this attribute allows the CONTAINS operation? Is it a String type attribute? Can you use such condition for that attribute creating the query manually? Does replacing CONTAINS with EQUALS make your script work or it also fails?
I always found the Query API a bit complicated. Is there a good reason to build all the conditions using this API like you are doing, instead of creating the query manually and just run it using the API? That would be a lot easier.
Marco Bauer
Oct 26 '16, 8:51 a.m.Hi Miguel,
This attribute is from the type of "Large HTML".
I tried to use EQUAL and it doesn't work as well as the CONTAINS operation.
When I try to create the query in the web UI, I can not see my custom attributes.
The reason why I wanna use the Java API is, I would like to develop a search across several project areas.