3

The SmartTarget 2014 API for .NET has a handy IsEmpty() method on the Tridion.SmartTarget.Query.ResultSet class. You can use this to figure out if the query to SDL Fredhopper did return anything at all. The result set could be empty if there no items, promotions or other things returned by Fredhopper, or if the query timed out.

In the Java verison of API there is no com.tridion.smarttarget.query.ResultSet.isEmpty() or similar. I tried to test if the getItemsTotalCount() is null or 0 (although that is not the same kind of comparison) but that one throws an null pointer exception if the query times out.

So how should I test in the Java API whether I got any results from my query?

5

The IsEmpty property in .NET just checks if the number of Promotions is zero (which is not entirely true if there are search results present).

You can do the same check in Java by calling resultSet.getPromotions().isEmpty().

The getPromotions method will never return null currently, but checking for that could prevent possible NullPointerExceptions in the future.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.