@Override
public PagedSet<ModelView> execute(final ServiceActionContext inActionContext) throws ExecutionException
{
long startTime = System.currentTimeMillis();
GetDirectorySearchResultsRequest currentRequest = (GetDirectorySearchResultsRequest) inActionContext
.getParams();
// todo: do more than escape here - remove the advanced chars
String searchText = searchRequestBuilder.escapeAllButWildcardCharacters(currentRequest.getSearchTerm());
// get the current user's Person id.
long userPersonId = inActionContext.getPrincipal().getId();
// build and parse the query, set its paging
String nativeLuceneQuery = queryBuilder.buildNativeQuery(searchText, currentRequest.getWeightedField(),
userPersonId);
FullTextQuery query;
// don't bubble up exceptions that occur from invalid search terms - this is annoying for as-you-type results
try
{
query = searchRequestBuilder.buildQueryFromNativeSearchString(nativeLuceneQuery);
}
catch (Exception ex)
{
return new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest.getEndIndex(), 0,
new ArrayList<ModelView>());
}
searchRequestBuilder.setPaging(query, currentRequest.getStartIndex(), currentRequest.getEndIndex());
// get the results before query.getResultSize() is called for performance (it avoids a second search)
List<ModelView> results = query.getResultList();
// populate any transient properties
transientPropertyPopulator.populateTransientProperties(results, userPersonId, searchText);
// get the paged set, getting the total now that we've already made the query
PagedSet<ModelView> pagedResults = new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest
.getEndIndex(), query.getResultSize(), results);
// set the elapsed time
String elapsedTime = formatElapasedTime(startTime, System.currentTimeMillis());
pagedResults.setElapsedTime(elapsedTime);