Skip to content

Commit ab14b1c

Browse files
author
marvinw
committed
OAK-12051: Use sorting by score as new default.
1 parent 5aa8db0 commit ab14b1c

4 files changed

Lines changed: 28 additions & 28 deletions

File tree

oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,10 @@ public Oak with(@NotNull Whiteboard whiteboard) {
577577
}
578578

579579
if (queryEngineSettings != null) {
580-
Feature sortUnionQueryByScoreFeature = newFeature(QueryEngineSettings.FT_SORT_UNION_QUERY_BY_SCORE, whiteboard);
581-
LOG.info("Registered sort union query by score feature: " + QueryEngineSettings.FT_SORT_UNION_QUERY_BY_SCORE);
582-
closer.register(sortUnionQueryByScoreFeature);
583-
queryEngineSettings.setSortUnionQueryByScoreFeature(sortUnionQueryByScoreFeature);
584-
580+
Feature sortUnionQueryLegacyModeFeature = newFeature(QueryEngineSettings.FT_SORT_UNION_QUERY_LEGACY_MODE, whiteboard);
581+
LOG.info("Registered sort union query legacy mode feature: " + QueryEngineSettings.FT_SORT_UNION_QUERY_LEGACY_MODE);
582+
closer.register(sortUnionQueryLegacyModeFeature);
583+
queryEngineSettings.setSortUnionQueryLegacyModeFeature(sortUnionQueryLegacyModeFeature);
585584
Feature optimizeXPathUnion = newFeature(QueryEngineSettings.FT_OPTIMIZE_XPATH_UNION, whiteboard);
586585
LOG.info("Registered optimize XPath union feature: " + QueryEngineSettings.FT_OPTIMIZE_XPATH_UNION);
587586
closer.register(optimizeXPathUnion);
@@ -994,8 +993,8 @@ public void setPrefetchFeature(@Nullable Feature prefetch) {
994993
settings.setPrefetchFeature(prefetch);
995994
}
996995

997-
public void setSortUnionQueryByScoreFeature(@Nullable Feature feature) {
998-
settings.setSortUnionQueryByScoreFeature(feature);
996+
public void setSortUnionQueryLegacyModeFeature(@Nullable Feature feature) {
997+
settings.setSortUnionQueryLegacyModeFeature(feature);
999998
}
1000999

10011000
public void setOptimizeXPathUnion(@Nullable Feature feature) {

oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineSettings.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class QueryEngineSettings implements QueryEngineSettingsMBean, QueryLimit
6161

6262
public static final String OAK_QUERY_PREFETCH_COUNT = "oak.prefetchCount";
6363

64-
public static final String FT_SORT_UNION_QUERY_BY_SCORE = "FT_OAK-12051";
64+
public static final String FT_SORT_UNION_QUERY_LEGACY_MODE = "FT_OAK-12051";
6565

6666
public static final String FT_OPTIMIZE_XPATH_UNION = "FT_OAK-12007";
6767

@@ -120,7 +120,7 @@ public class QueryEngineSettings implements QueryEngineSettingsMBean, QueryLimit
120120
private final long queryLengthErrorLimit = Long.getLong(OAK_QUERY_LENGTH_ERROR_LIMIT, 100 * 1024 * 1024); //100MB
121121

122122
private Feature prefetchFeature;
123-
private Feature sortUnionQueryByScoreFeature;
123+
private Feature sortUnionQueryLegacyModeFeature;
124124
private Feature optimizeXPathUnion;
125125

126126
private String autoOptionsMappingJson = "{}";
@@ -226,13 +226,13 @@ public void setFastQuerySize(boolean fastQuerySize) {
226226
System.setProperty(OAK_FAST_QUERY_SIZE, String.valueOf(fastQuerySize));
227227
}
228228

229-
public void setSortUnionQueryByScoreFeature(@Nullable Feature feature) {
230-
this.sortUnionQueryByScoreFeature = feature;
229+
public void setSortUnionQueryLegacyModeFeature(@Nullable Feature feature) {
230+
this.sortUnionQueryLegacyModeFeature = feature;
231231
}
232232

233-
public boolean isSortUnionQueryByScoreEnabled() {
234-
// disable if the feature toggle is not used
235-
return sortUnionQueryByScoreFeature != null && sortUnionQueryByScoreFeature.isEnabled();
233+
public boolean isSortUnionQueryLegacyModeEnabled() {
234+
// Legacy mode (concatenate) is disabled by default; score-based sorting is the default behavior
235+
return sortUnionQueryLegacyModeFeature != null && sortUnionQueryLegacyModeFeature.isEnabled();
236236
}
237237

238238
public void setOptimizeXPathUnion(@Nullable Feature feature) {

oak-core/src/main/java/org/apache/jackrabbit/oak/query/UnionQueryImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ public Iterator<ResultRowImpl> getRows() {
324324
rightIter = ((MeasuringIterator) rightRows).getDelegate();
325325
}
326326
if (orderBy == null) {
327-
if(!settings.isSortUnionQueryByScoreEnabled()) {
328-
// Default old behavior
327+
if(settings.isSortUnionQueryLegacyModeEnabled()) {
328+
// Legacy mode: concatenate results without score-based merging
329329
it = IteratorUtils.chainedIterator(leftIter, rightIter);
330330
} else {
331331
boolean leftHasScore = isScorePresent(left);

oak-core/src/test/java/org/apache/jackrabbit/oak/query/UnionQueryTest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public class UnionQueryTest extends AbstractQueryTest {
6969
protected ContentRepository createRepository() {
7070
store = new MemoryNodeStore();
7171
qeSettings = new QueryEngineSettings();
72-
Feature sortFeature = createFeature(true);
73-
qeSettings.setSortUnionQueryByScoreFeature(sortFeature);
72+
Feature sortFeature = createFeature(false);
73+
qeSettings.setSortUnionQueryLegacyModeFeature(sortFeature);
7474

7575
return new Oak(store)
7676
.with(new OpenSecurityProvider())
@@ -439,36 +439,37 @@ public void testUnionMergingEmptyIterators() throws Exception {
439439
}
440440

441441
@Test
442-
public void testSortUnionQueryScoreFlagDisabled() throws Exception {
443-
QueryEngineSettings disabledSettings = new QueryEngineSettings();
444-
Feature sortFeature = createFeature(false);
445-
disabledSettings.setSortUnionQueryByScoreFeature(sortFeature);
442+
public void testSortUnionQueryLegacyModeEnabled() throws Exception {
443+
// When legacy mode is enabled, query results should be concatenated
444+
QueryEngineSettings legacySettings = new QueryEngineSettings();
445+
Feature legacyModeFeature = createFeature(true);
446+
legacySettings.setSortUnionQueryLegacyModeFeature(legacyModeFeature);
446447
MockQueryBuilder leftQuery = new MockQueryBuilder(true)
447448
.addResult("/left/doc1", 0.8)
448449
.addResult("/left/doc2", 0.7);
449450
MockQueryBuilder rightQuery = new MockQueryBuilder(true)
450451
.addResult("/right/doc1", 0.9)
451452
.addResult("/right/doc2", 0.6);
452453

453-
UnionQueryImpl unionQuery = new UnionQueryImpl(true, leftQuery.build(), rightQuery.build(), disabledSettings);
454+
UnionQueryImpl unionQuery = new UnionQueryImpl(true, leftQuery.build(), rightQuery.build(), legacySettings);
454455
List<ScoredResult> results = executeUnionAndGetScoredResults(unionQuery);
455456
assertPathOrder(results, new String[]{"/left/doc1", "/left/doc2", "/right/doc1", "/right/doc2"});
456457
}
457458

458459
@Test
459-
public void testSortUnionQueryScoreFlagIsNull() throws Exception {
460-
QueryEngineSettings disabledSettings = new QueryEngineSettings();
461-
disabledSettings.setSortUnionQueryByScoreFeature(null);
460+
public void testSortUnionQueryLegacyModeNotSet() throws Exception {
461+
QueryEngineSettings defaultSettings = new QueryEngineSettings();
462+
defaultSettings.setSortUnionQueryLegacyModeFeature(null);
462463
MockQueryBuilder leftQuery = new MockQueryBuilder(true)
463464
.addResult("/left/doc1", 0.8)
464465
.addResult("/left/doc2", 0.7);
465466
MockQueryBuilder rightQuery = new MockQueryBuilder(true)
466467
.addResult("/right/doc1", 0.9)
467468
.addResult("/right/doc2", 0.6);
468469

469-
UnionQueryImpl unionQuery = new UnionQueryImpl(true, leftQuery.build(), rightQuery.build(), disabledSettings);
470+
UnionQueryImpl unionQuery = new UnionQueryImpl(true, leftQuery.build(), rightQuery.build(), defaultSettings);
470471
List<ScoredResult> results = executeUnionAndGetScoredResults(unionQuery);
471-
assertPathOrder(results, new String[]{"/left/doc1", "/left/doc2", "/right/doc1", "/right/doc2"});
472+
assertPathOrder(results, new String[]{"/right/doc1", "/left/doc1", "/left/doc2", "/right/doc2"});
472473
}
473474

474475
@Test

0 commit comments

Comments
 (0)