本文整理汇总了Java中org.hibernate.search.query.dsl.BooleanJunction类的典型用法代码示例。如果您正苦于以下问题:Java BooleanJunction类的具体用法?Java BooleanJunction怎么用?Java BooleanJunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BooleanJunction类属于org.hibernate.search.query.dsl包,在下文中一共展示了BooleanJunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processKeywords
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的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: createFullTextQuery
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的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;
}
示例3: createFullTextQuery
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的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;
}
示例4: createEqualsQuery
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的package包/类
private static Query createEqualsQuery(Column column, Object value, boolean and,
boolean not, BooleanJunction<BooleanJunction> junction, QueryBuilder queryBuilder) {
String nis = column.getSourceName();
return createEqualsQuery( nis, value, and, not, junction, queryBuilder);
// Query queryKey = queryBuilder.keyword()
// .onField(column.getNameInSource())
// .matching(value).createQuery();
//
// if (not) {
// junction.must(queryKey).not();
// } else if (and) {
// junction.must(queryKey);
// } else if (junction != null) {
// junction.should(queryKey);
// }
// return queryKey;
}
示例5: getSearchByNameQuery
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的package包/类
private FullTextQuery getSearchByNameQuery(String searchTerm) {
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(getEntityManager());
QueryBuilder projectQueryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder()
.forEntity(Project.class).get();
BooleanJunction<?> booleanJunction = projectQueryBuilder.bool();
if (StringUtils.hasText(searchTerm)) {
booleanJunction.must(projectQueryBuilder
.keyword()
.fuzzy().withPrefixLength(1).withThreshold(0.8F)
.onField(Binding.project().name().getPath())
.matching(searchTerm)
.createQuery());
} else {
booleanJunction.must(projectQueryBuilder.all().createQuery());
}
return fullTextEntityManager.createFullTextQuery(booleanJunction.createQuery(), Project.class);
}
示例6: getSearchQuery
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的package包/类
private FullTextQuery getSearchQuery(String searchTerm) {
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(getEntityManager());
QueryBuilder userQueryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder()
.forEntity(User.class).get();
BooleanJunction<?> booleanJunction = userQueryBuilder.bool();
if (StringUtils.hasText(searchTerm)) {
booleanJunction.must(userQueryBuilder
.keyword()
.fuzzy().withPrefixLength(1).withThreshold(0.8F)
.onField(Binding.user().userName().getPath())
.andField(Binding.user().fullName().getPath())
.matching(searchTerm)
.createQuery());
} else {
booleanJunction.must(userQueryBuilder.all().createQuery());
}
return fullTextEntityManager.createFullTextQuery(booleanJunction.createQuery(), User.class);
}
示例7: searchAutocompleteWithoutProject
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的package包/类
@Override
public List<Artifact> searchAutocompleteWithoutProject(String searchPattern, Integer limit, Integer offset) throws ServiceException {
String[] searchFields = new String[] {
Binding.artifact().artifactId().getPath(),
Binding.artifact().group().groupId().getPath()
};
QueryBuilder queryBuilder = Search.getFullTextEntityManager(getEntityManager()).getSearchFactory().buildQueryBuilder()
.forEntity(Artifact.class).get();
Query notDeprecatedQuery = queryBuilder.keyword().onField(Binding.artifact().deprecationStatus().getPath()).matching(ArtifactDeprecationStatus.NORMAL).createQuery();
Query withoutProjectQuery = queryBuilder.keyword().onField(Binding.artifact().project().getPath()).matching(null).createQuery();
BooleanJunction<?> booleanJunction = queryBuilder.bool()
.must(notDeprecatedQuery)
.must(withoutProjectQuery);
List<SortField> sortFields = ImmutableList.<SortField>builder()
.add(new SortField(Binding.artifact().group().getPath() + '.' + ArtifactGroup.GROUP_ID_SORT_FIELD_NAME, SortField.Type.STRING))
.add(new SortField(Artifact.ARTIFACT_ID_SORT_FIELD_NAME, SortField.Type.STRING))
.build();
Sort sort = new Sort(sortFields.toArray(new SortField[sortFields.size()]));
return hibernateSearchService.searchAutocomplete(getObjectClass(), searchFields, searchPattern, booleanJunction.createQuery(), limit, offset, sort);
}
示例8: all
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的package包/类
public Query all(Collection<Query> subQueries) {
BooleanJunction<BooleanJunction> bool = queryBuilder.bool();
for (Query subQuery : subQueries) {
bool.must(subQuery);
}
return bool.createQuery();
}
示例9: any
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的package包/类
public Query any(Collection<Query> subQueries) {
BooleanJunction<BooleanJunction> bool = queryBuilder.bool();
for (Query subQuery : subQueries) {
bool.should(subQuery);
}
return bool.createQuery();
}
示例10: in
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的package包/类
public Query in(String fieldName, Collection<?> values) {
BooleanJunction<BooleanJunction> bool = queryBuilder.bool();
for (Object value : values) {
bool.should(equal(fieldName, value));
}
return bool.createQuery();
}
示例11: searchByKeyword
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的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();
}
示例12: differencesMandatoryFor
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的package包/类
@Override
public IHistoryLogSearchQuery differencesMandatoryFor(Set<HistoryEventType> mandatoryDifferencesEventTypes) {
if (!mandatoryDifferencesEventTypes.isEmpty()) {
List<HistoryEventType> allowedWithoutDifferenceEventTypes = EnumUtils.getEnumList(HistoryEventType.class);
allowedWithoutDifferenceEventTypes.removeAll(mandatoryDifferencesEventTypes);
BooleanJunction<?> junction = getDefaultQueryBuilder().bool();
shouldIfNotNull(
junction,
matchOneIfGiven(Bindings.historyLog().eventType(), allowedWithoutDifferenceEventTypes),
matchIfGiven(AbstractHistoryLog.HAS_DIFFERENCES, true)
);
must(junction.createQuery());
}
return this;
}
示例13: all
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的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;
}
示例14: any
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的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;
}
示例15: matchOneIfGiven
import org.hibernate.search.query.dsl.BooleanJunction; //导入依赖的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();
}