Skip to content

Commit 0c882c4

Browse files
authored
Migrate deprecated usages of Operations#union (opensearch-project#19397)
Migrate usages of org.apache.lucene.util.automaton.Operations#union(Automaton, Automaton) to Operations#union(Collection<Automation>) Signed-off-by: Sergei Ustimenko <[email protected]> Signed-off-by: fdesu <[email protected]>
1 parent a19434c commit 0c882c4

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4646
- Optimize source conversion in gRPC search hits using zero-copy BytesRef ([#19280](https://github.com/opensearch-project/OpenSearch/pull/19280))
4747
- Allow plugins to copy folders into their config dir during installation ([#19343](https://github.com/opensearch-project/OpenSearch/pull/19343))
4848
- Add failureaccess as runtime dependency to transport-grpc module ([#19339](https://github.com/opensearch-project/OpenSearch/pull/19339))
49+
- Migrate usages of deprecated `Operations#union` from Lucene ([#19397](https://github.com/opensearch-project/OpenSearch/pull/19397))
4950

5051
### Fixed
5152
- Fix unnecessary refreshes on update preparation failures ([#15261](https://github.com/opensearch-project/OpenSearch/issues/15261))

server/src/main/java/org/opensearch/common/lucene/search/AutomatonQueries.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.lucene.util.automaton.Operations;
4242

4343
import java.util.ArrayList;
44+
import java.util.Arrays;
4445
import java.util.Iterator;
4546
import java.util.List;
4647

@@ -177,7 +178,7 @@ public static Automaton toCaseInsensitiveChar(int codepoint) {
177178
int altCase = Character.isLowerCase(codepoint) ? Character.toUpperCase(codepoint) : Character.toLowerCase(codepoint);
178179
Automaton result;
179180
if (altCase != codepoint) {
180-
result = Operations.union(case1, Automata.makeChar(altCase));
181+
result = Operations.union(Arrays.asList(case1, Automata.makeChar(altCase)));
181182
} else {
182183
result = case1;
183184
}

server/src/main/java/org/opensearch/common/xcontent/support/XContentMapValues.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ private static boolean hasNoWildcardsOrDots(String[] fields) {
301301
* For instance, if the original simple regex is `foo`, this will translate
302302
* it into `foo` OR `foo.*`. */
303303
private static Automaton makeMatchDotsInFieldNames(Automaton automaton) {
304+
Automaton automatonMatchingFields = Operations.concatenate(
305+
Arrays.asList(automaton, Automata.makeChar('.'), Automata.makeAnyString())
306+
);
304307
return Operations.determinize(
305-
Operations.union(automaton, Operations.concatenate(Arrays.asList(automaton, Automata.makeChar('.'), Automata.makeAnyString()))),
308+
Operations.union(Arrays.asList(automaton, automatonMatchingFields)),
306309
Operations.DEFAULT_DETERMINIZE_WORK_LIMIT
307310
);
308311
}

server/src/main/java/org/opensearch/indices/SystemIndices.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import org.apache.logging.log4j.LogManager;
3636
import org.apache.logging.log4j.Logger;
37-
import org.apache.lucene.util.automaton.Automata;
3837
import org.apache.lucene.util.automaton.Automaton;
3938
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
4039
import org.apache.lucene.util.automaton.Operations;
@@ -45,7 +44,6 @@
4544
import java.util.Collection;
4645
import java.util.List;
4746
import java.util.Map;
48-
import java.util.Optional;
4947
import java.util.stream.Collectors;
5048

5149
/**
@@ -143,11 +141,9 @@ public boolean validateSystemIndex(String index) {
143141
}
144142

145143
private static CharacterRunAutomaton buildCharacterRunAutomaton(Collection<SystemIndexDescriptor> descriptors) {
146-
Optional<Automaton> automaton = descriptors.stream()
144+
List<Automaton> automatons = descriptors.stream()
147145
.map(descriptor -> Regex.simpleMatchToAutomaton(descriptor.getIndexPattern()))
148-
.reduce(Operations::union);
149-
return new CharacterRunAutomaton(
150-
Operations.determinize(automaton.orElse(Automata.makeEmpty()), Operations.DEFAULT_DETERMINIZE_WORK_LIMIT)
151-
);
146+
.collect(Collectors.toList());
147+
return new CharacterRunAutomaton(Operations.determinize(Operations.union(automatons), Operations.DEFAULT_DETERMINIZE_WORK_LIMIT));
152148
}
153149
}

0 commit comments

Comments
 (0)