Skip to content

Commit e78e85e

Browse files
committed
spotless
1 parent 3e40232 commit e78e85e

File tree

8 files changed

+106
-110
lines changed

8 files changed

+106
-110
lines changed

server/src/main/java/org/elasticsearch/search/SearchModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package org.elasticsearch.search;
1010

11-
import org.apache.lucene.search.Matches;
1211
import org.elasticsearch.common.CheckedBiConsumer;
1312
import org.elasticsearch.common.NamedRegistry;
1413
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;

server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/HighlightUtils.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@
1010
import org.apache.lucene.search.highlight.DefaultEncoder;
1111
import org.apache.lucene.search.highlight.Encoder;
1212
import org.apache.lucene.search.highlight.SimpleHTMLEncoder;
13-
import org.elasticsearch.index.fieldvisitor.CustomFieldsVisitor;
1413
import org.elasticsearch.index.mapper.MappedFieldType;
1514
import org.elasticsearch.index.mapper.ValueFetcher;
1615
import org.elasticsearch.index.query.SearchExecutionContext;
1716
import org.elasticsearch.search.fetch.FetchSubPhase;
1817

1918
import java.io.IOException;
2019
import java.util.ArrayList;
21-
import java.util.Collections;
2220
import java.util.List;
23-
import java.util.Objects;
24-
25-
import static java.util.Collections.singleton;
2621

2722
public final class HighlightUtils {
2823

server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/MatchesFieldHighlighter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.apache.lucene.search.Matches;
1414
import org.apache.lucene.search.MatchesIterator;
1515
import org.apache.lucene.search.MatchesUtils;
16-
import org.apache.lucene.search.matchhighlight.MatchRegionRetriever;
1716
import org.apache.lucene.search.matchhighlight.OffsetRange;
1817
import org.apache.lucene.search.matchhighlight.OffsetsFromTokens;
1918
import org.apache.lucene.search.matchhighlight.OffsetsRetrievalStrategy;
@@ -82,7 +81,7 @@ public List<String> buildHighlights(MatchesIterator it, List<CharSequence> sourc
8281
context.field.fieldOptions().preTags()[0],
8382
context.field.fieldOptions().postTags()[0]
8483
); // TODO multiple field markers a la FVH
85-
List<Passage> passages = passageSelector.pickBest(
84+
List<Passage> passages = passageSelector.pickBest(
8685
contiguousSourceText,
8786
matchRanges,
8887
context.field.fieldOptions().fragmentCharSize(),
@@ -101,8 +100,7 @@ private OffsetsRetrievalStrategy getOffsetStrategy() {
101100
new XOffsetsFromPositions(field, analyzer)
102101
);
103102
case DOCS_AND_FREQS_AND_POSITIONS -> limitOffsets(new XOffsetsFromPositions(field, analyzer));
104-
case DOCS_AND_FREQS, DOCS ->
105-
new OffsetsFromTokens(field, analyzer);
103+
case DOCS_AND_FREQS, DOCS -> new OffsetsFromTokens(field, analyzer);
106104
// This should be unreachable because we won't get a MatchesIterator from an unindexed field
107105
case NONE -> (matchesIterator, doc) -> { throw new IllegalStateException("Field [ " + field + "] is not indexed"); };
108106
};

server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/XOffsetsFromMatchIterator.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
/*
2-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the Elastic License
4-
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5-
* in compliance with, at your election, the Elastic License 2.0 or the Server
6-
* Side Public License, v 1.
2+
* @notice
3+
* Licensed to the Apache Software Foundation (ASF) under one or more
4+
* contributor license agreements. See the NOTICE file distributed with
5+
* this work for additional information regarding copyright ownership.
6+
* The ASF licenses this file to You under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
717
*/
818

919
package org.elasticsearch.search.fetch.subphase.highlight;
1020

11-
1221
import org.apache.lucene.search.MatchesIterator;
1322
import org.apache.lucene.search.matchhighlight.MatchRegionRetriever;
1423
import org.apache.lucene.search.matchhighlight.OffsetRange;
@@ -35,9 +44,7 @@ public final class XOffsetsFromMatchIterator implements OffsetsRetrievalStrategy
3544
}
3645

3746
@Override
38-
public List<OffsetRange> get(
39-
MatchesIterator matchesIterator, MatchRegionRetriever.FieldValueProvider doc)
40-
throws IOException {
47+
public List<OffsetRange> get(MatchesIterator matchesIterator, MatchRegionRetriever.FieldValueProvider doc) throws IOException {
4148
ArrayList<OffsetRange> positionRanges = new ArrayList<>();
4249
ArrayList<OffsetRange> offsetRanges = new ArrayList<>();
4350
while (matchesIterator.next()) {

server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/XOffsetsFromPositions.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
/*
2-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the Elastic License
4-
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5-
* in compliance with, at your election, the Elastic License 2.0 or the Server
6-
* Side Public License, v 1.
2+
* @notice
3+
* Licensed to the Apache Software Foundation (ASF) under one or more
4+
* contributor license agreements. See the NOTICE file distributed with
5+
* this work for additional information regarding copyright ownership.
6+
* The ASF licenses this file to You under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
717
*/
818

919
package org.elasticsearch.search.fetch.subphase.highlight;
@@ -33,9 +43,7 @@ public XOffsetsFromPositions(String field, Analyzer analyzer) {
3343
}
3444

3545
@Override
36-
public List<OffsetRange> get(
37-
MatchesIterator matchesIterator, MatchRegionRetriever.FieldValueProvider doc)
38-
throws IOException {
46+
public List<OffsetRange> get(MatchesIterator matchesIterator, MatchRegionRetriever.FieldValueProvider doc) throws IOException {
3947
ArrayList<OffsetRange> positionRanges = new ArrayList<>();
4048
while (matchesIterator.next()) {
4149
int from = matchesIterator.startPosition();
@@ -50,8 +58,7 @@ public List<OffsetRange> get(
5058
return convertPositionsToOffsets(positionRanges, doc.getValues(field));
5159
}
5260

53-
List<OffsetRange> convertPositionsToOffsets(
54-
ArrayList<OffsetRange> positionRanges, List<CharSequence> values) throws IOException {
61+
List<OffsetRange> convertPositionsToOffsets(ArrayList<OffsetRange> positionRanges, List<CharSequence> values) throws IOException {
5562

5663
if (positionRanges.isEmpty()) {
5764
return positionRanges;

server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/XPassageSelector.java

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
/*
2-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the Elastic License
4-
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5-
* in compliance with, at your election, the Elastic License 2.0 or the Server
6-
* Side Public License, v 1.
2+
* @notice
3+
* Licensed to the Apache Software Foundation (ASF) under one or more
4+
* contributor license agreements. See the NOTICE file distributed with
5+
* this work for additional information regarding copyright ownership.
6+
* The ASF licenses this file to You under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
717
*/
8-
918
package org.elasticsearch.search.fetch.subphase.highlight;
1019

1120
import org.apache.lucene.search.matchhighlight.OffsetRange;
@@ -23,29 +32,28 @@
2332
import java.util.RandomAccess;
2433

2534
public class XPassageSelector {
26-
public static final Comparator<Passage> DEFAULT_SCORER =
27-
(a, b) -> {
28-
// Compare the number of highlights first.
29-
int v;
30-
v = Integer.compare(a.markers.size(), b.markers.size());
31-
if (v != 0) {
32-
return v;
33-
}
35+
public static final Comparator<Passage> DEFAULT_SCORER = (a, b) -> {
36+
// Compare the number of highlights first.
37+
int v;
38+
v = Integer.compare(a.markers.size(), b.markers.size());
39+
if (v != 0) {
40+
return v;
41+
}
3442

35-
// Total number of characters covered by the highlights.
36-
int len1 = 0, len2 = 0;
37-
for (OffsetRange o : a.markers) {
38-
len1 += o.length();
39-
}
40-
for (OffsetRange o : b.markers) {
41-
len2 += o.length();
42-
}
43-
if (len1 != len2) {
44-
return Integer.compare(len1, len2);
45-
}
43+
// Total number of characters covered by the highlights.
44+
int len1 = 0, len2 = 0;
45+
for (OffsetRange o : a.markers) {
46+
len1 += o.length();
47+
}
48+
for (OffsetRange o : b.markers) {
49+
len2 += o.length();
50+
}
51+
if (len1 != len2) {
52+
return Integer.compare(len1, len2);
53+
}
4654

47-
return Integer.compare(b.from, a.from);
48-
};
55+
return Integer.compare(b.from, a.from);
56+
};
4957

5058
private final Comparator<Passage> passageScorer;
5159
private final PassageAdjuster passageAdjuster;
@@ -59,21 +67,17 @@ public XPassageSelector(Comparator<Passage> passageScorer, PassageAdjuster passa
5967
this.passageAdjuster = passageAdjuster;
6068
}
6169

62-
public List<Passage> pickBest(
63-
CharSequence value,
64-
List<? extends OffsetRange> markers,
65-
int maxPassageWindow,
66-
int maxPassages) {
67-
return pickBest(
68-
value, markers, maxPassageWindow, maxPassages, List.of(new OffsetRange(0, value.length())));
70+
public List<Passage> pickBest(CharSequence value, List<? extends OffsetRange> markers, int maxPassageWindow, int maxPassages) {
71+
return pickBest(value, markers, maxPassageWindow, maxPassages, List.of(new OffsetRange(0, value.length())));
6972
}
7073

7174
public List<Passage> pickBest(
7275
CharSequence value,
7376
List<? extends OffsetRange> markers,
7477
int maxPassageWindow,
7578
int maxPassages,
76-
List<OffsetRange> permittedPassageRanges) {
79+
List<OffsetRange> permittedPassageRanges
80+
) {
7781
assert markers instanceof RandomAccess;
7882
assert permittedPassageRanges instanceof RandomAccess;
7983
assert sortedAndNonOverlapping(permittedPassageRanges);
@@ -84,13 +88,12 @@ public List<Passage> pickBest(
8488
}
8589

8690
// Best passages so far.
87-
PriorityQueue<Passage> pq =
88-
new PriorityQueue<>(markers.size()) {
89-
@Override
90-
protected boolean lessThan(Passage a, Passage b) {
91-
return passageScorer.compare(a, b) < 0;
92-
}
93-
};
91+
PriorityQueue<Passage> pq = new PriorityQueue<>(markers.size()) {
92+
@Override
93+
protected boolean lessThan(Passage a, Passage b) {
94+
return passageScorer.compare(a, b) < 0;
95+
}
96+
};
9497

9598
markers = splitOrTruncateToWindows(markers, maxPassageWindow, permittedPassageRanges);
9699

@@ -99,8 +102,7 @@ protected boolean lessThan(Passage a, Passage b) {
99102

100103
final int max = markers.size();
101104
int markerIndex = 0;
102-
nextRange:
103-
for (OffsetRange range : permittedPassageRanges) {
105+
nextRange: for (OffsetRange range : permittedPassageRanges) {
104106
final int rangeTo = Math.min(range.to, value.length());
105107

106108
// Skip ranges outside of the value window anyway.
@@ -151,7 +153,7 @@ protected boolean lessThan(Passage a, Passage b) {
151153
}
152154
}
153155

154-
if (!inside.isEmpty()) {
156+
if (inside.isEmpty() == false) {
155157
pq.insertWithOverflow(new Passage(from, to, inside));
156158
}
157159
}
@@ -166,7 +168,7 @@ protected boolean lessThan(Passage a, Passage b) {
166168
Passage[] passages;
167169
if (pq.size() > 0) {
168170
passages = new Passage[pq.size()];
169-
for (int i = pq.size(); --i >= 0; ) {
171+
for (int i = pq.size(); --i >= 0;) {
170172
passages[i] = pq.pop();
171173
}
172174
} else {
@@ -183,10 +185,7 @@ protected boolean lessThan(Passage a, Passage b) {
183185
OffsetRange newRange = passageAdjuster.adjust(p);
184186
if (newRange.from != p.from || newRange.to != p.to) {
185187
assert newRange.from >= p.from && newRange.to <= p.to
186-
: "Adjusters must not expand the passage's range: was "
187-
+ p
188-
+ " => changed to "
189-
+ newRange;
188+
: "Adjusters must not expand the passage's range: was " + p + " => changed to " + newRange;
190189
passages[x] = new Passage(newRange.from, newRange.to, p.markers);
191190
}
192191
}
@@ -225,7 +224,8 @@ protected boolean lessThan(Passage a, Passage b) {
225224
private List<? extends OffsetRange> splitOrTruncateToWindows(
226225
List<? extends OffsetRange> markers,
227226
int maxPassageWindow,
228-
List<OffsetRange> permittedPassageRanges) {
227+
List<OffsetRange> permittedPassageRanges
228+
) {
229229
// Process markers overlapping with each permitted window.
230230
ArrayList<OffsetRange> processedMarkers = new ArrayList<>(markers.size());
231231
for (OffsetRange marker : markers) {
@@ -266,8 +266,7 @@ static boolean sortedAndNonOverlapping(List<? extends OffsetRange> permittedPass
266266
for (OffsetRange next, previous = i.next(); i.hasNext(); previous = next) {
267267
next = i.next();
268268
if (previous.to > next.from) {
269-
throw new AssertionError(
270-
"Ranges must be sorted and non-overlapping: " + permittedPassageRanges);
269+
throw new AssertionError("Ranges must be sorted and non-overlapping: " + permittedPassageRanges);
271270
}
272271
}
273272
}
@@ -282,7 +281,8 @@ protected Passage[] pickDefaultPassage(
282281
CharSequence value,
283282
int maxCharacterWindow,
284283
int maxPassages,
285-
List<OffsetRange> permittedPassageRanges) {
284+
List<OffsetRange> permittedPassageRanges
285+
) {
286286
// Search for the first range that is not empty.
287287
ArrayList<Passage> defaultPassages = new ArrayList<>();
288288
for (OffsetRange o : permittedPassageRanges) {
@@ -292,11 +292,7 @@ protected Passage[] pickDefaultPassage(
292292

293293
int to = Math.min(value.length(), o.to);
294294
if (o.from < to) {
295-
defaultPassages.add(
296-
new Passage(
297-
o.from,
298-
o.from + Math.min(maxCharacterWindow, o.length()),
299-
Collections.emptyList()));
295+
defaultPassages.add(new Passage(o.from, o.from + Math.min(maxCharacterWindow, o.length()), Collections.emptyList()));
300296
}
301297
}
302298

0 commit comments

Comments
 (0)