David Scherrer created OAK-12399:
------------------------------------
Summary: Investigate secondary ordering by jcr:score after an
ordered property
Key: OAK-12399
URL: https://issues.apache.org/jira/browse/OAK-12399
Project: Jackrabbit Oak
Issue Type: Test
Environment: Oak version: 2.4.0
Java version: 21.0.12.1
h2. Index:
- Name: custom.fluffyProducts
- Type: Lucene
- compatVersion: 2
- Async lanes: async, nrt
- Included paths: /content/fluffy-products
- Query paths: /content/fluffy-products
- Path restrictions evaluated: yes
- Index rule: nt:unstructured
- Included property types: String
h2. Query:
SELECT [jcr:path], [searchScore], [title], [jcr:score]
FROM [nt:unstructured] AS p
WHERE ISDESCENDANTNODE(p, '/content/fluffy-products')
AND CONTAINS(p.[title], 'alpha')
ORDER BY [searchScore] DESC, [jcr:score] DESC
Related Adobe issue:
GRANITE-63308
Related/follow-up Adobe issue:
GRANITE-65722
Reporter: David Scherrer
h3. Summary
Add test coverage for Lucene full-text ordering with an ordered property
followed by jcr:score
h3. Context
A client reported an issue involving a JCR-SQL2 query that orders results first
by an application-specific property and then by jcr:score:
{noformat}
ORDER BY [searchScore] DESC, [jcr:score] DESC
{noformat}
We were not able to reproduce the client's reported failure.
The purpose of this issue is to add a minimal Oak-level test covering this
query shape and to verify that the currently observed behavior remains stable.
The test should also make the expected ordering behavior explicit.
h3. Test scenario
The test creates a Lucene index for nt:unstructured nodes with:
* an analyzed and boosted title property;
* a numeric searchScore property configured for property indexing and ordering;
* a path restriction covering the test content;
* full-text matching on the title property.
The test data contains multiple matching nodes with the same highest
searchScore value. The nodes in that tied bucket have different full-text
relevance scores, allowing the test to verify whether jcr:score affects their
relative order.
Example tied bucket:
||Path||searchScore||Title||
|/test/fluffy-products/product-c|200|Alpha Training Course|
|/test/fluffy-products/product-g|200|General Training Course|
Additional nodes use lower searchScore values to verify the primary ordering.
h3. Index configuration
The test index is a Lucene index with the following relevant configuration:
{noformat}
Index name: custom.fluffyProducts
Index type: lucene
compatVersion: 2
Included path: /test/fluffy-products
Query path: /test/fluffy-products
Path restrictions evaluated: true
Async lanes: async, nrt
title:
- analyzed: true
- boost: 10
- Lucene field name: str:title
searchScore:
- propertyIndex: true
- ordered: true
- numeric property
allStrings:
- regular expression: .*
- nodeScopeIndex: true
{noformat}
The complete index definition is attached to this issue.
h3. Queries
The test compares the following JCR-SQL2 queries.
{noformat}
-- Baseline: full-text score ordering
SELECT [jcr:path], [searchScore], [title], [jcr:score]
FROM [nt:unstructured] AS p
WHERE ISDESCENDANTNODE(p, '/test/fluffy-products')
AND CONTAINS(p.[title], 'alpha')
ORDER BY [jcr:score] DESC
{noformat}
{noformat}
-- Primary property ordering followed by score ordering
SELECT [jcr:path], [searchScore], [title], [jcr:score]
FROM [nt:unstructured] AS p
WHERE ISDESCENDANTNODE(p, '/test/fluffy-products')
AND CONTAINS(p.[title], 'alpha')
ORDER BY [searchScore] DESC, [jcr:score] DESC
{noformat}
{noformat}
-- Reverse score direction
SELECT [jcr:path], [searchScore], [title], [jcr:score]
FROM [nt:unstructured] AS p
WHERE ISDESCENDANTNODE(p, '/test/fluffy-products')
AND CONTAINS(p.[title], 'alpha')
ORDER BY [searchScore] DESC, [jcr:score] ASC
{noformat}
h3. Expected behavior
The test should verify that:
# Results are grouped by searchScore in descending order.
# Nodes with equal searchScore values are ordered consistently with the
requested jcr:score direction, when their calculated jcr:score values differ.
# Reversing the secondary jcr:score direction changes the relative order within
a tied searchScore group, if Oak supports this ordering combination.
# The score-only query returns results in full-text relevance order.
# The query executes using the intended Lucene index.
If Oak does not guarantee secondary ordering by jcr:score after an ordered
property, the test should instead document the observed behavior and the
limitation rather than assert an unsupported ordering guarantee.
h3. Current observation
The client's reported failure could not be reproduced.
With the current test setup:
* the query executes successfully;
* the primary searchScore ordering works;
* two matching nodes are present in the highest searchScore bucket;
* the configured title boost is present;
* the intended Lucene index is selected.
The test is being added to preserve this coverage and to detect future changes
in the interaction between property ordering and full-text score ordering.
h3. Verification
The test should record or assert the following:
* the selected index name;
* the effective index configuration;
* the numeric type of searchScore;
* the fact that searchScore is ordered;
* the title boost;
* the result paths;
* the searchScore values;
* the jcr:score values;
* the relative order of nodes in the tied highest bucket.
The index must be reindexed after any changes to the index definition.
h3. Question
Is the ordering expressed by:
{noformat}
ORDER BY [searchScore] DESC, [jcr:score] DESC
{noformat}
a supported Oak behavior?
If it is supported, this issue adds a regression test for the behavior. If it
is not supported, please advise whether the test should document the limitation
instead of asserting secondary ordering by jcr:score.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)