It's all about the answers!

Ask a question

execute query to search work items

Marco Bauer (1112) | asked Oct 26 '16, 7:31 a.m.
 Hi all,

I am trying to develop a function to search work items by any term within a project area.
My code works fine for the standard attributes:

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 = "";
Term term = new Term(Operator.AND);
QueryResult<IResolvedResult<IWorkItem>> results =
queryClient.getResolvedExpressionResults(projectArea, term,IWorkItem.FULL_PROFILE);

I added 3 custom attributes and i need to search within these fields. So, i added the following lines:

IQueryableAttribute probattribute=QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(projectArea, propertyName, auditableClient, sourceRTCConBridge.getMonitor()); 
Expression problemExpression = new AttributeExpression(probattribute, AttributeOperation.CONTAINS, summaryText);


When i try to process the results with:

while (sourceWorkItems.hasNext(bridge.getMonitor()))

I get every time an exception: Like predicate is not supported on this query model -

Thanks in advance.
(please let me know If there is a way to use a REST webservice to search work items in a particular project area)

Miguel Tomico commented Oct 26 '16, 8:22 a.m. | edited 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 commented 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.

2 answers

permanent link
Miguel Tomico (5001423) | answered Oct 26 '16, 9:10 a.m.
edited Oct 26 '16, 9:18 a.m.

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.

Marco Bauer commented Oct 26 '16, 9:43 a.m.

I can display my custom attributes in the results, but i'm not able to set a condition on these attributes.
The reason why i would like to use the Java API is: I wanna have a score in combination with the results. When i use a manually defined query, I can't get a score...

permanent link
Miguel Tomico (5001423) | answered Oct 26 '16, 9:47 a.m.

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

Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.