本文整理汇总了Java中org.hibernate.search.jpa.FullTextEntityManager.createFullTextQuery方法的典型用法代码示例。如果您正苦于以下问题:Java FullTextEntityManager.createFullTextQuery方法的具体用法?Java FullTextEntityManager.createFullTextQuery怎么用?Java FullTextEntityManager.createFullTextQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.search.jpa.FullTextEntityManager
的用法示例。
在下文中一共展示了FullTextEntityManager.createFullTextQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
/**
* Searches the lucene store for a specific query
*
* @param <T> What type of information are we searching
* @param clazz The class of the information we are searching
* @param queryText The query text
* @return list of entities
* @throws ParseException the parse exception
*/
public final <T extends BaseEntity> List<Object[]> search(final Class<T> clazz, final String queryText) throws ParseException {
final FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
final SearchFactory searchFactory = fullTextEntityManager.getSearchFactory();
final QueryParser parser = new MultiFieldQueryParser(getClassLuceneFields(clazz), searchFactory.getAnalyzer(clazz));
final List<Query> parsedQueries = Arrays.stream(queryText.split("AND"))
.map(e -> parseQuery(e, parser))
.filter(Objects::nonNull)
.collect(Collectors.toList());
final BooleanQuery.Builder bq = new BooleanQuery.Builder();
parsedQueries.forEach(e -> bq.add(e, BooleanClause.Occur.MUST));
final FullTextQuery jpaQuery = fullTextEntityManager.createFullTextQuery(bq.build(), clazz);
jpaQuery.setProjection(ProjectionConstants.SCORE, ProjectionConstants.EXPLANATION, ProjectionConstants.THIS);
return (List<Object[]>) jpaQuery.getResultList();
}
示例2: getFTSQuery
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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;
}
示例3: search
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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);
}
示例4: getFTSWildcardQuery
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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;
}
示例5: search
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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;
}
示例6: extractCustomer
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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 );
}
示例7: searchByText
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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();
}
示例8: processKeywords
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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);
}
示例9: createFullTextQuery
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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;
}
示例10: find
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> List<T> find(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);
if (sp.getMaxResults() > 0) {
ftq.setMaxResults(sp.getMaxResults());
}
return ftq.getResultList();
}
示例11: findId
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
@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;
}
示例12: extractCategories
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
public List<String> extractCategories() {
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(
em );
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(
Categories.class ).get();
org.apache.lucene.search.Query query = queryBuilder.all().createQuery();
FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery( query ,
Categories.class );
fullTextQuery.setProjection( FullTextQuery.ID , "category" );
Sort sort = new Sort( new SortField( "category" , SortField.STRING ) );
fullTextQuery.setSort( sort );
//fullTextQuery.initializeObjectsWith(ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID);
List<String> results = fullTextQuery.getResultList();
return results;
}
示例13: extractProducts
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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;
}
示例14: searchProducts
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的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;
}
示例15: extractPromotionalProducts
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
public List<Products> extractPromotionalProducts() {
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(
em );
org.apache.lucene.search.Query query = NumericRangeQuery.newDoubleRange( "old_price" , 0.0d ,
1000d , false ,
true );
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);
List results = fullTextQuery.getResultList();
return results;
}