|
4 | 4 | */
|
5 | 5 | package org.hibernate.search.engine.search.projection.dsl;
|
6 | 6 |
|
| 7 | +import java.util.Comparator; |
| 8 | +import java.util.Optional; |
| 9 | +import java.util.Set; |
| 10 | +import java.util.SortedSet; |
7 | 11 | import java.util.function.Function;
|
8 | 12 |
|
9 | 13 | import org.hibernate.search.engine.search.highlighter.dsl.HighlighterOptionsStep;
|
10 | 14 | import org.hibernate.search.engine.search.projection.ProjectionAccumulator;
|
| 15 | +import org.hibernate.search.util.common.annotation.Incubating; |
11 | 16 |
|
12 | 17 | /**
|
13 | 18 | * The initial and final step in a highlight definition, where optional parameters can be set.
|
@@ -59,4 +64,73 @@ public interface HighlightProjectionOptionsStep extends HighlightProjectionFinal
|
59 | 64 | * @param <R> The type of the final result.
|
60 | 65 | */
|
61 | 66 | <R> ProjectionFinalStep<R> accumulator(ProjectionAccumulator.Provider<String, R> accumulator);
|
| 67 | + |
| 68 | + /** |
| 69 | + * Defines the projection as single-valued, i.e. returning {@code String} instead of {@code List<String>}. |
| 70 | + * <p> |
| 71 | + * Can only be used when the highlighter that creates highlighted fragments for this projection is configured |
| 72 | + * to return a single fragment at most, i.e. when {@link HighlighterOptionsStep#numberOfFragments(int) .numberOfFragments(1)} |
| 73 | + * is applied to the highlighter. |
| 74 | + * Otherwise, it will lead to an exception being thrown when the query is created. |
| 75 | + * |
| 76 | + * @return A final step in the highlight projection definition. |
| 77 | + * @see HighlighterOptionsStep#numberOfFragments(int) |
| 78 | + */ |
| 79 | + @Incubating |
| 80 | + default ProjectionFinalStep<String> nullable() { |
| 81 | + return accumulator( ProjectionAccumulator.nullable() ); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Defines the projection as single-valued wrapped in an {@link Optional}, i.e. returning {@code Optional<String>} instead of {@code List<String>}. |
| 86 | + * <p> |
| 87 | + * Can only be used when the highlighter that creates highlighted fragments for this projection is configured |
| 88 | + * to return a single fragment at most, i.e. when {@link HighlighterOptionsStep#numberOfFragments(int) .numberOfFragments(1)} |
| 89 | + * is applied to the highlighter. |
| 90 | + * Otherwise, it will lead to an exception being thrown when the query is created. |
| 91 | + * |
| 92 | + * @return A final step in the highlight projection definition. |
| 93 | + * @see HighlighterOptionsStep#numberOfFragments(int) |
| 94 | + */ |
| 95 | + @Incubating |
| 96 | + default ProjectionFinalStep<Optional<String>> optional() { |
| 97 | + return accumulator( ProjectionAccumulator.optional() ); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Changes the collection accumulating the values to {@link Set} instead of {@link java.util.List}. |
| 102 | + * @return A final step in the highlight projection definition. |
| 103 | + */ |
| 104 | + @Incubating |
| 105 | + default ProjectionFinalStep<Set<String>> set() { |
| 106 | + return accumulator( ProjectionAccumulator.set() ); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Changes the collection accumulating the values to {@link SortedSet} instead of {@link java.util.List}. |
| 111 | + * @return A final step in the highlight projection definition. |
| 112 | + */ |
| 113 | + @Incubating |
| 114 | + default ProjectionFinalStep<SortedSet<String>> sortedSet() { |
| 115 | + return accumulator( ProjectionAccumulator.sortedSet() ); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Changes the collection accumulating the values to {@link SortedSet} instead of {@link java.util.List}. |
| 120 | + * @param comparator The comparator to use for sorting strings within the set. |
| 121 | + * @return A final step in the highlight projection definition. |
| 122 | + */ |
| 123 | + @Incubating |
| 124 | + default ProjectionFinalStep<SortedSet<String>> sortedSet(Comparator<String> comparator) { |
| 125 | + return accumulator( ProjectionAccumulator.sortedSet( comparator ) ); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Changes the collection accumulating the values to {@code String[]} instead of {@link java.util.List}. |
| 130 | + * @return A final step in the highlight projection definition. |
| 131 | + */ |
| 132 | + @Incubating |
| 133 | + default ProjectionFinalStep<String[]> array() { |
| 134 | + return accumulator( ProjectionAccumulator.array( String.class ) ); |
| 135 | + } |
62 | 136 | }
|
0 commit comments