@Override
public PagedSet<GalleryItem> execute(final ServiceActionContext inActionContext) throws ExecutionException
{
long startTime = System.currentTimeMillis();
GetGallerySearchResultsRequest actionRequest = (GetGallerySearchResultsRequest) inActionContext.getParams();
LuceneSearchRequest request = new LuceneSearchRequest();
request.setMaxResults(actionRequest.getMaxResultsPerPage());
request.setFirstResult(actionRequest.getStartingIndex());
Class< ? > objectType;
if (actionRequest.getType() == GalleryItemType.THEME)
{
objectType = Theme.class;
}
else
{
objectType = GadgetDefinition.class;
}
// TODO pull into Spring.
Map<String, Float> fields = new HashMap<String, Float>();
fields.put("name", 2.0F);
fields.put("title", 2.0F);
fields.put("description", 1.0F);
fields.put("author", 1.0F);
request.setFields(fields);
List<String> sortFields = new ArrayList<String>();
sortFields.add(actionRequest.getSort());
request.setSortFields(sortFields);
request.setObjectType(objectType);
request.setSearchString(actionRequest.getSearchText());
PagedSet<GalleryItem> results = searchMapper.execute(request);
if (logger.isDebugEnabled())
{
logger.debug("Retrieved " + results.getTotal() + " from the search, returning "
+ results.getPagedSet().size() + " items from the searchText: " + actionRequest.getSearchText()
+ " .");
}
// set the elapsed time
String elapsedTime = formatElapasedTime(startTime, System.currentTimeMillis());