public PagedSet<T> execute(final LuceneSearchRequest inRequest)
{
/**
* Convoluted like this to make testing possible.
*/
FullTextEntityManager sessionEntityManager = fullTextEntityManager;
if (sessionEntityManager == null)
{
sessionEntityManager = Search.getFullTextEntityManager(getEntityManager());
}
QueryParser parser = queryBuilder.buildQueryParser();
List<T> results = null;
PagedSet<T> pagedSet = null;
try
{
StringBuilder query = new StringBuilder();
// TODO Escape!!
for (Entry<String, Float> entry : inRequest.getFields().entrySet())
{
query.append(entry.getKey());
query.append(":");
query.append("(%1$s)^");
query.append(Float.toString(entry.getValue()));
query.append(" ");
}
String luceneQueryString = String.format(query.toString(), inRequest.getSearchString());
org.apache.lucene.search.Query luceneQuery = parser.parse(luceneQueryString);
FullTextQuery fullTextQuery = sessionEntityManager.createFullTextQuery(luceneQuery, inRequest
.getObjectType());
fullTextQuery.setFirstResult(inRequest.getFirstResult());
fullTextQuery.setMaxResults(inRequest.getMaxResults());