|
| 1 | +/* |
| 2 | + * Hibernate Search, full-text search for your domain model |
| 3 | + * |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 2.1 or later |
| 5 | + * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
| 6 | + */ |
| 7 | +package org.hibernate.search.engine.mapper.scope; |
| 8 | + |
| 9 | +import java.util.function.Function; |
| 10 | + |
| 11 | +import org.hibernate.search.engine.backend.scope.IndexScopeExtension; |
| 12 | +import org.hibernate.search.engine.common.EntityReference; |
| 13 | +import org.hibernate.search.engine.search.aggregation.AggregationKey; |
| 14 | +import org.hibernate.search.engine.search.aggregation.SearchAggregation; |
| 15 | +import org.hibernate.search.engine.search.aggregation.dsl.SearchAggregationFactory; |
| 16 | +import org.hibernate.search.engine.search.highlighter.dsl.SearchHighlighterFactory; |
| 17 | +import org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory; |
| 18 | +import org.hibernate.search.engine.search.projection.dsl.SearchProjectionFactory; |
| 19 | +import org.hibernate.search.engine.search.query.dsl.SearchQueryOptionsStep; |
| 20 | +import org.hibernate.search.engine.search.query.dsl.SearchQuerySelectStep; |
| 21 | +import org.hibernate.search.engine.search.query.dsl.SearchQueryWhereStep; |
| 22 | +import org.hibernate.search.engine.search.sort.dsl.SearchSortFactory; |
| 23 | +import org.hibernate.search.util.common.SearchException; |
| 24 | + |
| 25 | +/** |
| 26 | + * Represents a set of types and the corresponding indexes. |
| 27 | + * <p> |
| 28 | + * The scope can be used for search, to build search-related objects (predicate, sort, projection, aggregation, ...), |
| 29 | + * or to define the targeted entities/indexes |
| 30 | + * when passing it to the search session. |
| 31 | + * |
| 32 | + * @param <E> A supertype of all types in this scope. |
| 33 | + * @param <ER> The type of entity reference used by the scope. |
| 34 | + */ |
| 35 | +public interface SearchScope<E, ER extends EntityReference> { |
| 36 | + |
| 37 | + /** |
| 38 | + * Initiate the building of a search predicate. |
| 39 | + * <p> |
| 40 | + * The predicate will only be valid for search queries |
| 41 | + * created using this scope or another scope instance targeting the same indexes. |
| 42 | + * <p> |
| 43 | + * Note this method is only necessary if you do not want to use lambda expressions, |
| 44 | + * since you can {@link SearchQueryWhereStep#where(Function) define predicates with lambdas} |
| 45 | + * within the search query DSL, |
| 46 | + * removing the need to create separate objects to represent the predicates. |
| 47 | + * |
| 48 | + * @return A predicate factory. |
| 49 | + * @see SearchPredicateFactory |
| 50 | + */ |
| 51 | + SearchPredicateFactory predicate(); |
| 52 | + |
| 53 | + /** |
| 54 | + * Initiate the building of a search sort. |
| 55 | + * <p> |
| 56 | + * The sort will only be valid for search queries |
| 57 | + * created using this scope or another scope instance targeting the same indexes. |
| 58 | + * or a wider scope. |
| 59 | + * <p> |
| 60 | + * Note this method is only necessary if you do not want to use lambda expressions, |
| 61 | + * since you can {@link SearchQueryOptionsStep#sort(Function) define sorts with lambdas} |
| 62 | + * within the search query DSL, |
| 63 | + * removing the need to create separate objects to represent the sorts. |
| 64 | + * |
| 65 | + * @return A sort factory. |
| 66 | + * @see SearchSortFactory |
| 67 | + */ |
| 68 | + SearchSortFactory sort(); |
| 69 | + |
| 70 | + /** |
| 71 | + * Initiate the building of a search projection that will be valid for the indexes in this scope. |
| 72 | + * <p> |
| 73 | + * The projection will only be valid for search queries |
| 74 | + * created using this scope or another scope instance targeting the same indexes. |
| 75 | + * <p> |
| 76 | + * Note this method is only necessary if you do not want to use lambda expressions, |
| 77 | + * since you can {@link SearchQuerySelectStep#select(Function)} define projections with lambdas} |
| 78 | + * within the search query DSL, |
| 79 | + * removing the need to create separate objects to represent the projections. |
| 80 | + * |
| 81 | + * @return A projection factory. |
| 82 | + * @see SearchProjectionFactory |
| 83 | + */ |
| 84 | + SearchProjectionFactory<ER, E> projection(); |
| 85 | + |
| 86 | + /** |
| 87 | + * Initiate the building of a search aggregation that will be valid for the indexes in this scope. |
| 88 | + * <p> |
| 89 | + * The aggregation will only be usable in search queries |
| 90 | + * created using this scope or another scope instance targeting the same indexes. |
| 91 | + * <p> |
| 92 | + * Note this method is only necessary if you do not want to use lambda expressions, |
| 93 | + * since you can {@link SearchQueryOptionsStep#aggregation(AggregationKey, SearchAggregation)} define aggregations with lambdas} |
| 94 | + * within the search query DSL, |
| 95 | + * removing the need to create separate objects to represent the aggregation. |
| 96 | + * |
| 97 | + * @return An aggregation factory. |
| 98 | + * @see SearchAggregationFactory |
| 99 | + */ |
| 100 | + SearchAggregationFactory aggregation(); |
| 101 | + |
| 102 | + /** |
| 103 | + * Initiate the building of a highlighter that will be valid for the indexes in this scope. |
| 104 | + * <p> |
| 105 | + * The highlighter will only be valid for search queries |
| 106 | + * created using this scope or another scope instance targeting the same indexes. |
| 107 | + * <p> |
| 108 | + * Note this method is only necessary if you do not want to use lambda expressions, |
| 109 | + * since you can {@link SearchQueryOptionsStep#highlighter(Function) define highlighters with lambdas} |
| 110 | + * within the search query DSL, |
| 111 | + * removing the need to create separate objects to represent the projections. |
| 112 | + * |
| 113 | + * @return A highlighter factory. |
| 114 | + */ |
| 115 | + SearchHighlighterFactory highlighter(); |
| 116 | + |
| 117 | + /** |
| 118 | + * Extend the current search scope with the given extension, |
| 119 | + * resulting in an extended search scope offering backend-specific utilities. |
| 120 | + * |
| 121 | + * @param extension The extension to apply. |
| 122 | + * @param <T> The type of search scope provided by the extension. |
| 123 | + * @return The extended search scope. |
| 124 | + * @throws SearchException If the extension cannot be applied (wrong underlying technology, ...). |
| 125 | + */ |
| 126 | + <T> T extension(IndexScopeExtension<T> extension); |
| 127 | + |
| 128 | +} |
0 commit comments