当前位置: 首页>>代码示例>>Java>>正文


Java QueryBuilder类代码示例

本文整理汇总了Java中org.hibernate.search.query.dsl.QueryBuilder的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder类的具体用法?Java QueryBuilder怎么用?Java QueryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QueryBuilder类属于org.hibernate.search.query.dsl包,在下文中一共展示了QueryBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFTSQuery

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@Override
public FullTextQuery getFTSQuery(String filterText, final Class<?> entityType, Integer maxResults, String... fields) {

	// entityManager para busquedas de tipo FTS
	final FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);

	// se crea el query usando Hibernate Search query DSL
	final QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(entityType).get();

	// se crea el query sobre los campos indicados
	final Query query = queryBuilder.keyword().onFields(fields).matching(filterText.trim()).createQuery();

	// se enmascara el query de Lucene en uno de Hibernate
	final FullTextQuery jpaQuery = fullTextEntityManager.createFullTextQuery(query, entityType);

	// se define la cantidad maxima de resultados si es mayor a cero
	if (maxResults > 0) {
		jpaQuery.setMaxResults(maxResults);
	}
	// se retorna el query listo para ejecución o para inyeccion de criterias
	return jpaQuery;
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:23,代码来源:AitFTSRepo.java

示例2: search

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@Transactional
@Override
public Page<Book> search(String query, Pageable page) {
	FullTextEntityManager manager = this.getFullTextEntityManager();

	QueryBuilder builder = manager.getSearchFactory().buildQueryBuilder().forEntity(Book.class).get();

	Query luceneQuery = builder.keyword().fuzzy()
			.onFields("author", "title", "lang", "description", "isbn", "genre", "location").matching(query)
			.createQuery();

	FullTextQuery q = manager.createFullTextQuery(luceneQuery, Book.class);
	q.setProjection(FullTextQuery.THIS, FullTextQuery.SCORE);

	long total = q.getResultSize();
	q.setFirstResult(page.getOffset()).setMaxResults(page.getPageSize());

	@SuppressWarnings("unchecked")
	List<Object[]> result = q.getResultList();
	List<Book> fine = new LinkedList<>();
	for (Object[] i : result) {
		fine.add((Book) i[0]);
	}
	return new PageImpl<>(fine, page, total);
}
 
开发者ID:shilongdai,项目名称:bookManager,代码行数:26,代码来源:BookDatabaseImpl.java

示例3: getFTSWildcardQuery

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@Override
public FullTextQuery getFTSWildcardQuery(String filterText, final Class<?> entityType, Integer maxResults, String field) {

	// entityManager para busquedas de tipo FTS
	final FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);

	// se crea el query usando Hibernate Search query DSL
	final QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(entityType).get();

	// se crea el query sobre los campos indicados
	final Query query = queryBuilder.phrase().onField(field).sentence(filterText.trim()).createQuery();

	// se enmascara el query de Lucene en uno de Hibernate
	final FullTextQuery jpaQuery = fullTextEntityManager.createFullTextQuery(query, entityType);

	// se define la cantidad maxima de resultados si es mayor a cero
	if (maxResults > 0) {
		jpaQuery.setMaxResults(maxResults);
	}
	// se retorna el query listo para ejecución o para inyeccion de criterias
	return jpaQuery;
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:23,代码来源:AitFTSRepo.java

示例4: searchByTag

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public List<PostPO> searchByTag(Paging paigng, String tag) {
	FullTextSession fullTextSession = Search.getFullTextSession(super.session());
    SearchFactory sf = fullTextSession.getSearchFactory();
    QueryBuilder qb = sf.buildQueryBuilder().forEntity(PostPO.class).get();
    org.apache.lucene.search.Query luceneQuery  = qb.phrase().onField("tags").sentence(tag).createQuery();

    FullTextQuery query = fullTextSession.createFullTextQuery(luceneQuery);
    query.setFirstResult(paigng.getFirstResult());
    query.setMaxResults(paigng.getMaxResults());

	Sort sort = new Sort(new SortField("id", SortField.Type.LONG, true));
	query.setSort(sort);
	
	paigng.setTotalCount(query.getResultSize());
	
	return query.list();
}
 
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:20,代码来源:PostDaoImpl.java

示例5: search

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@Transactional
@Override
public Collection<User> search(String query) {
    FullTextEntityManager manager = this.getFullTextEntityManager();

    QueryBuilder builder = manager.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();

    Query luceneQuery = builder.keyword().fuzzy()
            .onFields("username").matching(query)
            .createQuery();

    FullTextQuery q = manager.createFullTextQuery(luceneQuery, User.class);
    q.setProjection(FullTextQuery.THIS, FullTextQuery.SCORE);

    @SuppressWarnings("unchecked")
    List<Object[]> result = q.getResultList();
    List<User> fine = new LinkedList<>();
    result.stream().forEach((i) -> {
        fine.add((User) i[0]);
    });
    return fine;
}
 
开发者ID:shilongdai,项目名称:LSChatServer,代码行数:23,代码来源:UserDatabaseImpl.java

示例6: searchByText

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@Override
public List<Product> searchByText(String text) {
	Product productEntity = newInstance();
	FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);

	QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder()
			.forEntity(productEntity.getClass()).get();
	if (!Strings.isNullOrEmpty(text)) {
		Query query = qb.keyword().onField("name").andField("details").andField("technicalDetails").matching(text)
				.createQuery();

		javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query,
				productEntity.getClass());
		List<Product> result = persistenceQuery.getResultList();

		if (CollectionUtils.isNotEmpty(result)) {
			for (Product product : result) {
				loadImagesFromQuantities(product.getQuantities());
			}
		}
		return result;
	}
	return Collections.emptyList();
}
 
开发者ID:raphaelazzolini,项目名称:mercurius,代码行数:25,代码来源:ProductDAOImpl.java

示例7: extractProducts

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
public Map<Integer , List<Products>> extractProducts( String id , int page ) {

        FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(
                em );

        QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(
                Products.class ).get();
        org.apache.lucene.search.Query query = queryBuilder.keyword().onField( "category.id" ).matching(
                id ).createQuery();

        FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery( query ,
                                                                                 Products.class );
        Sort sort = new Sort( new SortField( "price" , SortField.DOUBLE ) );
        fullTextQuery.setSort( sort );

        //fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
        fullTextQuery.setFirstResult( page * 3 );
        fullTextQuery.setMaxResults( 3 );
        List<Products> results = fullTextQuery.getResultList();

        Map<Integer , List<Products>> results_and_total = new HashMap<Integer , List<Products>>();
        results_and_total.put( fullTextQuery.getResultSize() , results );

        return results_and_total;
    }
 
开发者ID:juliocnsouzadev,项目名称:omg_mongodb,代码行数:26,代码来源:EShopBean.java

示例8: searchProducts

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
public List<Products> searchProducts( String search ) {

        FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(
                em );

        QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(
                Products.class ).get();
        org.apache.lucene.search.Query query = queryBuilder.keyword().onField( "product" ).matching(
                search ).createQuery();

        FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery( query ,
                                                                                 Products.class );

        //fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
        fullTextQuery.setMaxResults( 3 );

        List results = fullTextQuery.getResultList();

        return results;
    }
 
开发者ID:juliocnsouzadev,项目名称:omg_mongodb,代码行数:21,代码来源:EShopBean.java

示例9: extractCustomer

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
public Customers extractCustomer( String email , String password ) {

        FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(
                em );

        QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(
                Customers.class ).get();
        org.apache.lucene.search.Query query = queryBuilder.bool().must( queryBuilder.keyword()
                .onField( "email" ).matching( email ).createQuery() ).must( queryBuilder.keyword()
                        .onField( "password" ).matching( password ).createQuery() ).createQuery();

        FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery( query ,
                                                                                 Customers.class );

        //fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
        List results = fullTextQuery.getResultList();

        if ( results.isEmpty() ) {
            return null;
        }

        return ( Customers ) results.get( 0 );
    }
 
开发者ID:juliocnsouzadev,项目名称:omg_mongodb,代码行数:24,代码来源:EShopBean.java

示例10: processKeywords

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@Nullable
@SuppressWarnings({ CompilerWarnings.UNCHECKED })
private Long[] processKeywords(EntityManager entityManager, @Nullable Integer maxResults) {
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(this.entityImplClass).get();
    BooleanJunction<?> conjunction = queryBuilder.bool();

    PropertyMetadata keywordPropMetadata;

    for (String keywordPropName : this.keywords.keySet()) {
        conjunction = conjunction.must(queryBuilder.keyword()
            .onFields((keywordPropMetadata = this.entityPropMetadatas.get(keywordPropName)).getLowercaseFieldName(),
                keywordPropMetadata.getEdgeNgramFieldName(), keywordPropMetadata.getNgramFieldName(), keywordPropMetadata.getPhoneticFieldName())
            .matching(StringUtils.join(this.keywords.get(keywordPropName), StringUtils.SPACE)).createQuery());
    }

    FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(new InterceptingQuery(conjunction.createQuery()), this.entityImplClass);
    fullTextQuery.setProjection(ProjectionConstants.ID);

    if (maxResults != null) {
        fullTextQuery.setMaxResults(maxResults);
    }

    return ((List<Object[]>) fullTextQuery.getResultList()).stream().map(fullTextResult -> ((Long) fullTextResult[0])).toArray(Long[]::new);
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:26,代码来源:SdcctCriteriaImpl.java

示例11: testSearchIndex

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@Test
@Transactional(timeout=900)
public void testSearchIndex() throws Exception {

	final QueryBuilder qb = getFullTextEntityManager().getSearchFactory().buildQueryBuilder()
			.forEntity(DocumentContentData.class).get();
	final org.apache.lucene.search.Query luceneQuery = qb.keyword().onFields("content").matching("programmering")
			.createQuery();

	// wrap Lucene query in a javax.persistence.Query
	final javax.persistence.Query jpaQuery = getFullTextEntityManager().createFullTextQuery(luceneQuery,
			DocumentContentData.class);

	// execute search
	final List<DocumentContentData> result = jpaQuery.setMaxResults(500).getResultList();
	assertTrue("expect some result",result.size()> 0);
}
 
开发者ID:Hack23,项目名称:cia,代码行数:18,代码来源:SearchIndexerImplITest.java

示例12: executeSearchQuery

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> List<T> executeSearchQuery(
		RestSearchKey key,
		Class<T> typeClass,
		FullTextSession fullTextEntityManager,
		QueryBuilder queryBuilder,
		Map<String, Query> crtsMap
		) {

	FullTextQuery fullTextQuery = createFullTextQuery(typeClass,
			fullTextEntityManager, queryBuilder, crtsMap);

	if(key.hasOrders()){

		hibernateSearchBuilder.defineOrder(key, fullTextQuery);
	}

	hibernateSearchBuilder.definePaging(key, fullTextQuery);

	return fullTextQuery.list(); 

}
 
开发者ID:mcraken,项目名称:spring-scaffy,代码行数:23,代码来源:SessionHibernateSearchDao.java

示例13: createFullTextQuery

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
private <T> FullTextQuery createFullTextQuery(Class<T> typeClass,
		FullTextSession fullTextSession,
		QueryBuilder queryBuilder, Map<String, Query> crtsMap) {
	BooleanJunction<?> booleanJunction = hibernateSearchBuilder.createFinalBooleanJunction(
			queryBuilder, crtsMap);

	FullTextQuery fullTextQuery = null;
	
	if(booleanJunction == null){
		fullTextQuery =
		fullTextSession.createFullTextQuery(queryBuilder.all().createQuery(), typeClass);
	} else {
		
		fullTextQuery =
		fullTextSession.createFullTextQuery(
				booleanJunction.createQuery(), typeClass);
	}
	return fullTextQuery;
}
 
开发者ID:mcraken,项目名称:spring-scaffy,代码行数:20,代码来源:SessionHibernateSearchDao.java

示例14: executeSearchQuery

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> List<T> executeSearchQuery(
		RestSearchKey key,
		Class<T> typeClass,
		FullTextEntityManager fullTextEntityManager,
		QueryBuilder queryBuilder,
		Map<String, Query> crtsMap
		) {

	FullTextQuery fullTextQuery = createFullTextQuery(typeClass,
			fullTextEntityManager, queryBuilder, crtsMap);

	if(key.hasOrders()){

		hibernateSearchBuilder.defineOrder(key, fullTextQuery);
	}

	hibernateSearchBuilder.definePaging(key, fullTextQuery);

	return fullTextQuery.getResultList(); 

}
 
开发者ID:mcraken,项目名称:spring-scaffy,代码行数:23,代码来源:JPAHibernateSearchDao.java

示例15: createFullTextQuery

import org.hibernate.search.query.dsl.QueryBuilder; //导入依赖的package包/类
private <T> FullTextQuery createFullTextQuery(Class<T> typeClass,
		FullTextEntityManager fullTextEntityManager,
		QueryBuilder queryBuilder, Map<String, Query> crtsMap) {
	BooleanJunction<?> booleanJunction = hibernateSearchBuilder.createFinalBooleanJunction(
			queryBuilder, crtsMap);

	FullTextQuery fullTextQuery = null;

	if(booleanJunction == null){
		fullTextQuery =
		fullTextEntityManager.createFullTextQuery(
				queryBuilder.all().createQuery(), typeClass);
	} else {
		
		fullTextQuery =
		fullTextEntityManager.createFullTextQuery(
				booleanJunction.createQuery(), typeClass);
	}
	return fullTextQuery;
}
 
开发者ID:mcraken,项目名称:spring-scaffy,代码行数:21,代码来源:JPAHibernateSearchDao.java


注:本文中的org.hibernate.search.query.dsl.QueryBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。