本文整理汇总了Java中org.hibernate.search.query.dsl.QueryBuilder.bool方法的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder.bool方法的具体用法?Java QueryBuilder.bool怎么用?Java QueryBuilder.bool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.search.query.dsl.QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.bool方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: searchByKeyword
import org.hibernate.search.query.dsl.QueryBuilder; //导入方法依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<TweetEntity> searchByKeyword(final String keywords, final LocalDate from, final LocalDate to) {
// Must be retrieved inside a transaction to take part of
final FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
// Prepare a search query builder
final QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(TweetEntity.class).get();
// This is a boolean junction... I'll add at least a keyword query
final BooleanJunction<BooleanJunction> outer = queryBuilder.bool();
outer.must(
queryBuilder
.keyword()
.onFields("content")
.matching(keywords)
.createQuery()
);
// And then 2 range queries if from and to are not null
Optional.ofNullable(from)
.map(f -> f.atStartOfDay(UTC)) // Must be a zoned date time to fit the field
.map(f -> queryBuilder.range().onField("created_at").above(f).createQuery())
.ifPresent(q -> outer.must(q));
Optional.ofNullable(to)
.map(f -> f.plusDays(1).atStartOfDay(UTC)) // Same here, but a day later
.map(f -> queryBuilder.range().onField("created_at").below(f).excludeLimit().createQuery()) // which i exclude
.ifPresent(q -> outer.must(q));
return fullTextEntityManager.createFullTextQuery(outer.createQuery(), TweetEntity.class).getResultList();
}
示例3: all
import org.hibernate.search.query.dsl.QueryBuilder; //导入方法依赖的package包/类
@Override
public Query all(QueryBuilder builder, Query ... queries) {
BooleanJunction<?> junction = null;
for (Query query : queries) {
if (query != null) {
junction = junction != null ? junction : builder.bool();
junction.must(query);
}
}
return junction != null ? junction.createQuery() : null;
}
示例4: any
import org.hibernate.search.query.dsl.QueryBuilder; //导入方法依赖的package包/类
@Override
public Query any(QueryBuilder builder, Query ... queries) {
BooleanJunction<?> junction = null;
for (Query query : queries) {
if (query != null) {
junction = junction != null ? junction : builder.bool();
junction.should(query);
}
}
return junction != null ? junction.createQuery() : null;
}
示例5: matchOneIfGiven
import org.hibernate.search.query.dsl.QueryBuilder; //导入方法依赖的package包/类
@Override
public <P> Query matchOneIfGiven(QueryBuilder builder, String fieldPath, Collection<? extends P> possibleValues) {
if (possibleValues == null || possibleValues.isEmpty()) {
return null;
}
BooleanJunction<?> subJunction = builder.bool();
for (P possibleValue : possibleValues) {
subJunction.should(builder.keyword()
.onField(fieldPath)
.matching(possibleValue)
.createQuery());
}
return subJunction.createQuery();
}
示例6: matchAllIfGiven
import org.hibernate.search.query.dsl.QueryBuilder; //导入方法依赖的package包/类
@Override
public <P> Query matchAllIfGiven(QueryBuilder builder, String fieldPath, Collection<? extends P> values) {
if (values == null || values.isEmpty()) {
return null;
}
BooleanJunction<?> subJunction = builder.bool();
for (P possibleValue : values) {
subJunction.must(builder.keyword()
.onField(fieldPath)
.matching(possibleValue)
.createQuery());
}
return subJunction.createQuery();
}
示例7: performSearch
import org.hibernate.search.query.dsl.QueryBuilder; //导入方法依赖的package包/类
private static List<Object> performSearch(Condition where, String cacheName, ObjectConnection connection)
throws TranslatorException {
LogManager.logTrace(LogConstants.CTX_CONNECTOR,
"Using Lucene Searching."); //$NON-NLS-1$
Class<?> type = connection.getType(cacheName);
//Map<?, ?> cache,
SearchManager searchManager = Search
.getSearchManager((Cache<?, ?>) connection.getCacheContainer().getCache(cacheName) );
QueryBuilder queryBuilder = searchManager.buildQueryBuilderForClass(type).get();
BooleanJunction<BooleanJunction> junction = queryBuilder.bool();
boolean createdQueries = buildQueryFromWhereClause(where,
junction, queryBuilder);
Query query = null;
if (createdQueries) {
query = junction.createQuery();
} else {
query = queryBuilder.all().createQuery();
}
CacheQuery cacheQuery = searchManager.getQuery(query, type); // rootNodeType
List<Object> results = cacheQuery.list();
if (results == null || results.isEmpty()) {
return Collections.emptyList();
}
return results;
}
示例8: findAdherentByName
import org.hibernate.search.query.dsl.QueryBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Transactional
public Page<Adherent> findAdherentByName(String name, Pageable pageable) {
final FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);
// Create native Lucene query using the query DSL
// alternatively you can write the Lucene query using the Lucene query parser
// or the Lucene programmatic API. The Hibernate Search DSL is recommended though
final QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Adherent.class).get();
final Analyzer analyzer = fullTextEntityManager.getSearchFactory().getAnalyzer("nameAnalyzer");
final BooleanJunction<?> query = qb.bool();
tokenized(analyzer, name).forEach(term -> query.must(qb.keyword().wildcard().onField("fullName").matching('*' + term + '*').createQuery()));
// wrap Lucene query in a javax.persistence.Query
final FullTextQuery persistenceQuery = fullTextEntityManager.createFullTextQuery(query.createQuery(), Adherent.class);
persistenceQuery.setFirstResult(pageable.getOffset());
persistenceQuery.setMaxResults(pageable.getPageSize());
// Apply a sort if needed
if (pageable.getSort() != null) {
final List<SortField> sortFields = new ArrayList<>();
for (final Order sortOrder : pageable.getSort()) {
sortFields.add(new SortField(sortOrder.getProperty(), SortField.Type.STRING, !sortOrder.isAscending()));
}
persistenceQuery.setSort(new Sort(sortFields.toArray(new SortField[sortFields.size()])));
}
// execute search
final List<Adherent> result = persistenceQuery.getResultList();
return new PageImpl<>(result, pageable, pageable.getOffset() + result.size() + 1);
}
示例9: createFinalBooleanJunction
import org.hibernate.search.query.dsl.QueryBuilder; //导入方法依赖的package包/类
public BooleanJunction<?> createFinalBooleanJunction(
QueryBuilder queryBuilder, Map<String, Query> crtsMap) {
Query[] queries = null;
if(crtsMap != null)
queries = crtsMap.values().toArray(new Query[]{});
BooleanJunction<?> booleanJunction = null;
if(queries != null){
booleanJunction = queryBuilder.bool();
for(Query query : queries)
booleanJunction = booleanJunction.must(query);
}
return booleanJunction;
}
示例10: handle
import org.hibernate.search.query.dsl.QueryBuilder; //导入方法依赖的package包/类
public <T> void handle(RestCriteria restCriteria,
Map<String, Query> criteria, QueryBuilder queryBuilder)
throws BadCriteriaValueException, CriteriaIDNotFoundException {
BooleanJunction<?> booleanJunction = queryBuilder.bool();
booleanJunction
.must(queryBuilder.keyword().onField(restCriteria.readCriteriaName()).matching(restCriteria.getParsedValue()).createQuery()).not();
Query query = booleanJunction.createQuery();
criteria.put(restCriteria.readCriteriaId(), query);
}