Example usage for org.apache.lucene.search Sort Sort

List of usage examples for org.apache.lucene.search Sort Sort

Introduction

In this page you can find the example usage for org.apache.lucene.search Sort Sort.

Prototype

public Sort(SortField... fields) 

Source Link

Document

Sets the sort to the given criteria in succession: the first SortField is checked first, but if it produces a tie, then the second SortField is used to break the tie, etc.

Usage

From source file:org.kie.workbench.common.dmn.backend.editors.types.query.FindAllDmnAssetsQueryTest.java

License:Apache License

@Test
public void testGetSortOrder() {

    final Sort expected = new Sort(new SortField(FILE_NAME_FIELD_SORTED, STRING));
    final Sort actual = query.getSortOrder();

    assertEquals(expected, actual);//from  www .  j  a va  2s .com
}

From source file:org.kie.workbench.common.screens.impl.FindAllLibraryAssetsQuery.java

License:Apache License

@Override
public Sort getSortOrder() {
    return new Sort(new SortField(FieldFactory.FILE_NAME_FIELD_SORTED, SortField.Type.STRING));
}

From source file:org.medici.bia.dao.document.DocumentDAOJpaImpl.java

License:Open Source License

/**
 * /*from   w  w  w.ja v a2 s .c om*/
 */
@Override
public Page searchDocuments(Search searchContainer, PaginationFilter paginationFilter)
        throws PersistenceException {
    // We prepare object of return method.
    Page page = new Page(paginationFilter);

    // We obtain hibernate-search session
    FullTextSession fullTextSession = org.hibernate.search.Search
            .getFullTextSession(((HibernateEntityManager) getEntityManager()).getSession());

    org.apache.lucene.search.Query query = searchContainer.toLuceneQuery();
    logger.info("Lucene Query " + query.toString());

    // We execute search
    org.hibernate.search.FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query,
            Document.class);

    // We set size of result.
    if (paginationFilter.getTotal() == null) {
        page.setTotal(new Long(fullTextQuery.getResultSize()));
    }

    // We set pagination  
    fullTextQuery.setFirstResult(paginationFilter.getFirstRecord());
    fullTextQuery.setMaxResults(paginationFilter.getLength());

    // We manage sorting (this manages sorting on multiple fields)
    paginationFilter = this.generatePaginationFilterHibernateSearch(paginationFilter);
    List<SortingCriteria> sortingCriterias = paginationFilter.getSortingCriterias();
    if (sortingCriterias.size() > 0) {
        SortField[] sortFields = new SortField[sortingCriterias.size()];
        for (int i = 0; i < sortingCriterias.size(); i++) {
            sortFields[i] = new SortField(sortingCriterias.get(i).getColumn(),
                    sortingCriterias.get(i).getColumnType(),
                    (sortingCriterias.get(i).getOrder().equals(Order.ASC) ? true : false));
        }
        fullTextQuery.setSort(new Sort(sortFields));
    }

    // We set search result on return method
    page.setList(fullTextQuery.list());

    return page;
}