This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_10x in repository https://gitbox.apache.org/repos/asf/solr.git
commit 5747b366992c4db4f9f918fe59797b671cb620c4 Author: Serhiy Bzhezytskyy <[email protected]> AuthorDate: Thu Jul 30 04:44:45 2026 +0300 SOLR-18313: Prep for Lucene 11: use newer Lucene API forms (#4651) * Sort "missing value" (where docs without a value in the sort field are placed) * Automaton concatenation in the reverse-wildcard query path. Co-authored-by: Serhiy Bzhezytskyy <[email protected]> (cherry picked from commit bd6df9214eeff4a959970cbd0ef58fb1f951dd76) --- .../unreleased/SOLR-18313-prep-for-lucene-11.yml | 10 ++++++ .../apache/solr/parser/SolrQueryParserBase.java | 5 +-- .../java/org/apache/solr/schema/EnumFieldType.java | 12 ++++++- .../src/java/org/apache/solr/schema/FieldType.java | 37 +++++++++++----------- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/changelog/unreleased/SOLR-18313-prep-for-lucene-11.yml b/changelog/unreleased/SOLR-18313-prep-for-lucene-11.yml new file mode 100644 index 00000000000..2ce54549879 --- /dev/null +++ b/changelog/unreleased/SOLR-18313-prep-for-lucene-11.yml @@ -0,0 +1,10 @@ +# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc +title: > + Prep for Lucene 11: switch two internal call sites (sort missing-value handling and automaton + concatenation) to the newer Lucene API forms that already exist in Lucene 10.4. No behavior change. +type: changed +authors: + - name: Serhiy Bzhezytskyy +links: + - name: SOLR-18313 + url: https://issues.apache.org/jira/browse/SOLR-18313 diff --git a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java index 42cedf82979..e1202a5c249 100644 --- a/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java +++ b/solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java @@ -1296,14 +1296,15 @@ public abstract class SolrQueryParserBase extends QueryBuilder { WildcardQuery.toAutomaton(term, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT); // TODO: we should likely use the automaton to calculate shouldReverse, too. if (factory.shouldReverse(termStr)) { - automaton = Operations.concatenate(automaton, Automata.makeChar(factory.getMarkerChar())); + automaton = + Operations.concatenate(List.of(automaton, Automata.makeChar(factory.getMarkerChar()))); automaton = Operations.reverse(automaton); } else { // reverse wildcardfilter is active: remove false positives // fsa representing false positives (markerChar*) Automaton falsePositives = Operations.concatenate( - Automata.makeChar(factory.getMarkerChar()), Automata.makeAnyString()); + List.of(Automata.makeChar(factory.getMarkerChar()), Automata.makeAnyString())); // subtract these away automaton = Operations.minus(automaton, falsePositives, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT); diff --git a/solr/core/src/java/org/apache/solr/schema/EnumFieldType.java b/solr/core/src/java/org/apache/solr/schema/EnumFieldType.java index 47aaf472d46..2dc89f73a57 100644 --- a/solr/core/src/java/org/apache/solr/schema/EnumFieldType.java +++ b/solr/core/src/java/org/apache/solr/schema/EnumFieldType.java @@ -41,6 +41,7 @@ import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortedNumericSelector; +import org.apache.lucene.search.SortedNumericSortField; import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; @@ -452,7 +453,16 @@ public class EnumFieldType extends PrimitiveFieldType { final SortField result = getNumericSort(field, NumberType.INTEGER, top); if (null == result.getMissingValue()) { // special case 'enum' default behavior: assume missing values are "below" all enum values - result.setMissingValue(Integer.MIN_VALUE); + if (result instanceof SortedNumericSortField snsf) { + return new SortedNumericSortField( + snsf.getField(), + snsf.getNumericType(), + snsf.getReverse(), + snsf.getSelector(), + Integer.MIN_VALUE); + } + return new SortField( + result.getField(), result.getType(), result.getReverse(), Integer.MIN_VALUE); } return result; } diff --git a/solr/core/src/java/org/apache/solr/schema/FieldType.java b/solr/core/src/java/org/apache/solr/schema/FieldType.java index 1452233beee..14a7b274b4a 100644 --- a/solr/core/src/java/org/apache/solr/schema/FieldType.java +++ b/solr/core/src/java/org/apache/solr/schema/FieldType.java @@ -778,10 +778,8 @@ public abstract class FieldType extends FieldProperties { Object missingHigh) { field.checkSortability(); - SortField sf = new SortField(field.getName(), sortType, reverse); - applySetMissingValue(field, sf, missingLow, missingHigh); - - return sf; + return new SortField( + field.getName(), sortType, reverse, missingValue(field, reverse, missingLow, missingHigh)); } /** Same as {@link #getSortField} but using {@link SortedSetSortField} */ @@ -793,10 +791,8 @@ public abstract class FieldType extends FieldProperties { Object missingHigh) { field.checkSortability(); - SortField sf = new SortedSetSortField(field.getName(), reverse, selector); - applySetMissingValue(field, sf, missingLow, missingHigh); - - return sf; + return new SortedSetSortField( + field.getName(), reverse, selector, missingValue(field, reverse, missingLow, missingHigh)); } /** Same as {@link #getSortField} but using {@link SortedNumericSortField}. */ @@ -809,25 +805,30 @@ public abstract class FieldType extends FieldProperties { Object missingHigh) { field.checkSortability(); - SortField sf = new SortedNumericSortField(field.getName(), sortType, reverse, selector); - applySetMissingValue(field, sf, missingLow, missingHigh); - - return sf; + return new SortedNumericSortField( + field.getName(), + sortType, + reverse, + selector, + missingValue(field, reverse, missingLow, missingHigh)); } /** + * Computes the sort {@code missingValue} to pass to a {@link SortField} constructor based on the + * field's {@code sortMissingFirst}/{@code sortMissingLast} properties and the sort direction. + * Returns {@code null} when neither property is set. + * * @see #getSortField * @see #getSortedSetSortField */ - private static void applySetMissingValue( - SchemaField field, SortField sortField, Object missingLow, Object missingHigh) { - final boolean reverse = sortField.getReverse(); - + private static Object missingValue( + SchemaField field, boolean reverse, Object missingLow, Object missingHigh) { if (field.sortMissingLast()) { - sortField.setMissingValue(reverse ? missingLow : missingHigh); + return reverse ? missingLow : missingHigh; } else if (field.sortMissingFirst()) { - sortField.setMissingValue(reverse ? missingHigh : missingLow); + return reverse ? missingHigh : missingLow; } + return null; } /**
