@Test public final void executeTest() throws ParseException { LuceneSearchRequest request = new LuceneSearchRequest(); request.setMaxResults(2); request.setFirstResult(0); 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("sort"); request.setSortFields(sortFields); request.setObjectType(Theme.class); request.setSearchString("search text"); context.checking(new Expectations() { { QueryParser parser = context.mock(QueryParser.class); Query query = context.mock(Query.class); oneOf(queryBuilder).buildQueryParser(); will(returnValue(parser)); oneOf(parser).parse(with(any(String.class))); will(returnValue(query)); oneOf(fullTextEm).createFullTextQuery(query, Theme.class); } }); sut.execute(request); }
@SuppressWarnings("unchecked") @Override public PagedSet<T> execute(final LuceneSearchRequest inRequest) { 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(); 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()); SortField[] fields = new SortField[inRequest.getSortFields().size()]; for (int i = 0; i < inRequest.getSortFields().size(); i++) { fields[i] = new SortField(inRequest.getSortFields().get(i), true); } Sort sort = new Sort(fields); fullTextQuery.setSort(sort); results = fullTextQuery.getResultList(); if (results.equals(Collections.EMPTY_LIST)) { results = new ArrayList<T>(); } pagedSet = new PagedSet<T>(inRequest.getFirstResult(), inRequest.getFirstResult() + results.size() - 1, fullTextQuery.getResultSize(), results); } catch (ParseException e) { log.error(e); } return pagedSet; }
LuceneSearchMapper extends ReadMapper<LuceneSearchRequest, PagedSet<T>> { @SuppressWarnings("unchecked") @Override public PagedSet<T> execute(final LuceneSearchRequest inRequest) { 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(); 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()); SortField[] fields = new SortField[inRequest.getSortFields().size()]; for (int i = 0; i < inRequest.getSortFields().size(); i++) { fields[i] = new SortField(inRequest.getSortFields().get(i), true); } Sort sort = new Sort(fields); fullTextQuery.setSort(sort); results = fullTextQuery.getResultList(); if (results.equals(Collections.EMPTY_LIST)) { results = new ArrayList<T>(); } pagedSet = new PagedSet<T>(inRequest.getFirstResult(), inRequest.getFirstResult() + results.size() - 1, fullTextQuery.getResultSize(), results); } catch (ParseException e) { log.error(e); } return pagedSet; } }
LuceneSearchMapper extends ReadMapper<LuceneSearchRequest, PagedSet<T>> { @SuppressWarnings("unchecked") @Override public PagedSet<T> execute(final LuceneSearchRequest inRequest) { 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(); 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()); SortField[] fields = new SortField[inRequest.getSortFields().size()]; for (int i = 0; i < inRequest.getSortFields().size(); i++) { fields[i] = new SortField(inRequest.getSortFields().get(i), true); } Sort sort = new Sort(fields); fullTextQuery.setSort(sort); results = fullTextQuery.getResultList(); if (results.equals(Collections.EMPTY_LIST)) { results = new ArrayList<T>(); } pagedSet = new PagedSet<T>(inRequest.getFirstResult(), inRequest.getFirstResult() + results.size() - 1, fullTextQuery.getResultSize(), results); } catch (ParseException e) { log.error(e); } return pagedSet; }  }
LuceneSearchMapper extends ReadMapper<LuceneSearchRequest, PagedSet<T>> { @SuppressWarnings("unchecked") @Override public PagedSet<T> execute(final LuceneSearchRequest inRequest) { 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(); 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()); SortField[] fields = new SortField[inRequest.getSortFields().size()]; for (int i = 0; i < inRequest.getSortFields().size(); i++) { fields[i] = new SortField(inRequest.getSortFields().get(i), true); } Sort sort = new Sort(fields); fullTextQuery.setSort(sort); results = fullTextQuery.getResultList(); if (results.equals(Collections.EMPTY_LIST)) { results = new ArrayList<T>(); } pagedSet = new PagedSet<T>(inRequest.getFirstResult(), inRequest.getFirstResult() + results.size() - 1, fullTextQuery.getResultSize(), results); } catch (ParseException e) { log.error(e); } return pagedSet; }  final void setFullTextEntityManager(final FullTextEntityManager inFullTextEntityManager); final QueryParserBuilder getQueryBuilder(); final void setQueryBuilder(final QueryParserBuilder inQueryBuilder); @SuppressWarnings("unchecked") @Override PagedSet<T> execute(final LuceneSearchRequest inRequest); }
LuceneSearchMapper extends ReadMapper<LuceneSearchRequest, PagedSet<T>> { @SuppressWarnings("unchecked") @Override public PagedSet<T> execute(final LuceneSearchRequest inRequest) { 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(); 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()); SortField[] fields = new SortField[inRequest.getSortFields().size()]; for (int i = 0; i < inRequest.getSortFields().size(); i++) { fields[i] = new SortField(inRequest.getSortFields().get(i), true); } Sort sort = new Sort(fields); fullTextQuery.setSort(sort); results = fullTextQuery.getResultList(); if (results.equals(Collections.EMPTY_LIST)) { results = new ArrayList<T>(); } pagedSet = new PagedSet<T>(inRequest.getFirstResult(), inRequest.getFirstResult() + results.size() - 1, fullTextQuery.getResultSize(), results); } catch (ParseException e) { log.error(e); } return pagedSet; }  final void setFullTextEntityManager(final FullTextEntityManager inFullTextEntityManager); final QueryParserBuilder getQueryBuilder(); final void setQueryBuilder(final QueryParserBuilder inQueryBuilder); @SuppressWarnings("unchecked") @Override PagedSet<T> execute(final LuceneSearchRequest inRequest);  }