Java Code Examples for org.hibernate.search.jpa.FullTextQuery#setProjection()

The following examples show how to use org.hibernate.search.jpa.FullTextQuery#setProjection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateSearchUtil.java    From javaee-lab with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> List<Serializable> findId(Class<T> clazz, SearchParameters sp, List<SingularAttribute<?, ?>> availableProperties) {
    //log.info("Searching {} with terms : {} with available Properties: {}", new Object[]{clazz.getSimpleName(), sp.getTerms(), availableProperties});
    FullTextEntityManager fullTextEntityManager = getFullTextEntityManager(entityManager);
    Query query = sp.getLuceneQueryBuilder().build(fullTextEntityManager, sp, availableProperties);

    if (query == null) {
        return null;
    }

    FullTextQuery ftq = fullTextEntityManager.createFullTextQuery( //
            query, clazz);
    ftq.setProjection("id");
    if (sp.getMaxResults() > 0) {
        ftq.setMaxResults(sp.getMaxResults());
    }
    List<Serializable> ids = newArrayList();
    List<Object[]> resultList = ftq.getResultList();
    for (Object[] result : resultList) {
        ids.add((Serializable) result[0]);
    }
    return ids;
}
 
Example 2
Source File: PageRepositoryImpl.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Override
public List<Long> searchForId(PageSearchRequest request) {
	FullTextQuery persistenceQuery = buildFullTextQuery(request, Pageable.unpaged(), null);
	persistenceQuery.setProjection("id");
	List<Object[]> results = persistenceQuery.getResultList();
	List<Long> nos = results.stream().map(result -> (long) result[0]).collect(Collectors.toList());
	return nos;
}
 
Example 3
Source File: ArticleRepositoryImpl.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Override
public List<Long> searchForId(ArticleSearchRequest request) {
	FullTextQuery persistenceQuery = buildFullTextQuery(request, Pageable.unpaged(), null);
	persistenceQuery.setProjection("id");
	List<Object[]> results = persistenceQuery.getResultList();
	List<Long> nos = results.stream().map(result -> (long) result[0]).collect(Collectors.toList());
	return nos;
}
 
Example 4
Source File: UserRepositoryImpl.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Override
public List<Long> searchForId(UserSearchRequest request) {
	FullTextQuery persistenceQuery = buildFullTextQuery(request, Pageable.unpaged(), null);
	persistenceQuery.setProjection("id");
	List<Object[]> results = persistenceQuery.getResultList();
	List<Long> nos = results.stream().map(result -> (long) result[0]).collect(Collectors.toList());
	return nos;
}
 
Example 5
Source File: CustomFieldRepositoryImpl.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Override
public List<Long> searchForId(CustomFieldSearchRequest request) {
	FullTextQuery persistenceQuery = buildFullTextQuery(request, Pageable.unpaged(), null);
	persistenceQuery.setProjection("id");
	List<Object[]> results = persistenceQuery.getResultList();
	List<Long> nos = results.stream().map(result -> (long) result[0]).collect(Collectors.toList());
	return nos;
}