List of usage examples for org.apache.lucene.search SortField SortField
public SortField(String field, FieldComparatorSource comparator, boolean reverse)
From source file:SearchHelpDocs.java
License:Open Source License
/** * Default search, sort by score and date *//*from www . j a va2s .c o m*/ private static Sort createSort() throws Exception { Sort sort = new Sort(); SortField fields[] = { SortField.FIELD_SCORE, new SortField("yyyymmdd", SortField.STRING, true) }; sort.setSort(fields); return sort; }
From source file:am.ik.categolj2.domain.repository.entry.EntryRepositoryImpl.java
License:Apache License
Page<Entry> searchTemplate(Pageable pageable,
Function<QueryBuilder, org.apache.lucene.search.Query> queryCreator) {
try {// w w w .j a v a2 s. c o m
creatingIndex.get();
} catch (InterruptedException e) {
logger.warn("Interrupted!", e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
logger.error("Index creation failed!!", e);
}
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder()
.forEntity(Entry.class).get();
org.apache.lucene.search.Query query = queryCreator.apply(queryBuilder);
org.apache.lucene.search.Sort sort = new Sort(
new SortField("lastModifiedDate", SortField.Type.STRING_VAL, true));
Query jpaQuery = fullTextEntityManager.createFullTextQuery(query, Entry.class).setSort(sort)
.setFirstResult(pageable.getOffset()).setMaxResults(pageable.getPageSize());
int count = fullTextEntityManager.createFullTextQuery(query, Entry.class).getResultSize();
@SuppressWarnings("unchecked")
List<Entry> content = jpaQuery.getResultList();
return new PageImpl<>(content, pageable, count);
}
From source file:axiom.scripting.rhino.LuceneQueryDispatcher.java
License:Open Source License
private Sort getLuceneSort(SortObject sort) { if (sort == null) { return null; }//from w w w . j av a 2 s. c om QuerySortField[] fields = sort.getSortFields(); if (fields == null) { return null; } final int length = fields.length; SortField[] sortFields = new SortField[length]; for (int i = 0; i < length; i++) { String s = fields[i].getField(); if (s == null) { return null; } sortFields[i] = new SortField(s, SortField.STRING, !fields[i].isAscending()); } return new Sort(sortFields); }
From source file:br.ufba.dcc.mestrado.computacao.repository.impl.ProjectRepositoryImpl.java
private void configureRelevanceSort(FullTextQuery fullTextQuery) { boolean reverse = true; SortField userContSortField = new SortField(SearchFieldsEnum.projectUserCount.fieldName(), SortField.Type.LONG, reverse); SortField ratingContSortField = new SortField(SearchFieldsEnum.projectRatingCount.fieldName(), SortField.Type.LONG, reverse); SortField reviewContSortField = new SortField(SearchFieldsEnum.projectReviewCount.fieldName(), SortField.Type.LONG, reverse); List<SortField> sortFieldList = new LinkedList<>(); sortFieldList.addAll(Arrays.asList(Sort.RELEVANCE.getSort())); sortFieldList.add(userContSortField); sortFieldList.add(reviewContSortField); sortFieldList.add(ratingContSortField); Sort sort = new Sort(userContSortField); fullTextQuery.setSort(sort);//from w ww . java 2 s. co m }
From source file:ccc.plugins.search.lucene.SimpleLuceneFS.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w .j a va2 s. co m public SearchResult find(final String searchTerms, final String sort, final SortOrder order, final int nofOfResultsPerPage, final int pageNo) { final int page = pageNo - 1; final Sort sorter = (null == sort) ? null : new Sort(new SortField(sort, SortField.STRING_VAL, (SortOrder.DESC == order))); if (searchTerms == null || searchTerms.trim().equals("")) { return new SearchResult(new HashSet<UUID>(), 0, nofOfResultsPerPage, searchTerms, page); } final int maxHits = (page + 1) * nofOfResultsPerPage; final CapturingHandler capturingHandler = new CapturingHandler(nofOfResultsPerPage, page); find(searchTerms, maxHits, sorter, null, capturingHandler); return new SearchResult(capturingHandler.getHits(), capturingHandler.getTotalResultsCount(), nofOfResultsPerPage, searchTerms, page); }
From source file:ccc.plugins.search.lucene.SimpleLuceneFS.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w ww .j a v a 2 s . c o m public SearchResult find(final String searchTerms, final String sort, final SortOrder order, final ACL userPerms, final int nofOfResultsPerPage, final int pageNo) { final int page = pageNo - 1; final Sort sorter = (null == sort) ? null : new Sort(new SortField(sort, SortField.STRING_VAL, (SortOrder.DESC == order))); if (searchTerms == null || searchTerms.trim().equals("")) { return new SearchResult(new HashSet<UUID>(), 0, nofOfResultsPerPage, searchTerms, page); } final int maxHits = (page + 1) * nofOfResultsPerPage; final CapturingHandler capturingHandler = new CapturingHandler(nofOfResultsPerPage, page); find(searchTerms, maxHits, sorter, userPerms, capturingHandler); return new SearchResult(capturingHandler.getHits(), capturingHandler.getTotalResultsCount(), nofOfResultsPerPage, searchTerms, page); }
From source file:com.aistor.modules.cms.service.ArticleService.java
License:Open Source License
/** * //ww w.ja v a 2 s.co m */ public Page<Article> search(Page<Article> page, String q) { // ? BooleanQuery query = articleDao.getFullTextQuery(q, "title", "keywords", "desciption", "articleData.content"); // ? BooleanQuery queryFilter = articleDao.getFullTextQuery( new BooleanClause(new TermQuery(new Term("status", Article.STATUS_RELEASE)), Occur.MUST)); // ? Sort sort = new Sort(new SortField("updateDate", SortField.DOC, true)); // articleDao.search(page, query, queryFilter, sort); // articleDao.keywordsHighlight(query, page.getList(), "desciption", "articleData.content"); return page; }
From source file:com.amalto.core.storage.hibernate.FullTextQueryHandler.java
License:Open Source License
@Override public StorageResults visit(OrderBy orderBy) { TypedExpression field = orderBy.getExpression(); if (field instanceof Field) { FieldMetadata fieldMetadata = ((Field) field).getFieldMetadata(); SortField sortField = new SortField(fieldMetadata.getName(), getSortType(fieldMetadata), orderBy.getDirection() == OrderBy.Direction.DESC); query.setSort(new Sort(sortField)); return null; } else {//from w w w.java 2s .co m throw new NotImplementedException("No support for order by for full text search on non-field."); } }
From source file:com.b2international.snowowl.snomed.api.impl.ClassificationRunIndex.java
License:Apache License
public void trimIndex(int maximumResultsToKeep) throws IOException { final Query query = Fields.newQuery().field(FIELD_CLASS, ClassificationRun.class.getSimpleName()) .matchAll();// w w w . j ava2s .co m // Sort by decreasing document order final Sort sort = new Sort(new SortField(null, Type.DOC, true)); final ClassificationRun lastRunToKeep = Iterables .getFirst(search(query, ClassificationRun.class, sort, maximumResultsToKeep - 1, 1), null); if (lastRunToKeep == null) { return; } final Date lastCreationDate = lastRunToKeep.getCreationDate(); final Query trimmingQuery = LongPoint.newRangeQuery(FIELD_CREATION_DATE, Long.MIN_VALUE, lastCreationDate.getTime()); writer.deleteDocuments(trimmingQuery); commit(); }
From source file:com.bewsia.script.safe.lucene.SEntity.java
License:Open Source License
public SortField newSortField(String field, int type, boolean reverse) { return new SortField(field, type, reverse); }