Skip to content

[fix] Resolve namespace for prefixed attribute names in range index conditions#6094

Open
joewiz wants to merge 2 commits intoeXist-db:developfrom
joewiz:fix/issue-5189-range-index-prefixed-condition
Open

[fix] Resolve namespace for prefixed attribute names in range index conditions#6094
joewiz wants to merge 2 commits intoeXist-db:developfrom
joewiz:fix/issue-5189-range-index-prefixed-condition

Conversation

@joewiz
Copy link
Member

@joewiz joewiz commented Mar 3, 2026

Summary

  • Fixes namespace resolution for prefixed attribute names (e.g. wwp:field) in range index <condition> elements
  • Updates collection.xconf.xsd to accept prefixed attribute names
  • Adds XQSuite tests for prefixed and unprefixed attribute conditions

Closes #5189

What Changed

RangeIndexConfigAttributeCondition.java — The constructor now accepts a Map<String, String> namespaces parameter (the same namespace map already used by <create qname="..."> resolution). When the @attribute value contains a prefix, the prefix is resolved to a namespace URI. The matches() method now uses getAttributeNS() for namespaced attributes instead of getAttribute() with the raw prefixed string.

ComplexRangeIndexConfigElement.java — Passes the namespaces map through to the RangeIndexConfigAttributeCondition constructor.

collection.xconf.xsd — Changed attributeReq type from xs:NCName to xs:string, consistent with how @qname is typed elsewhere in the schema. (xs:QName is unsuitable here because XSD QName validation requires the prefix to be resolvable in the schema instance context.)

prefixed-conditions.xql — 6 new XQSuite tests verifying that both prefixed (wwp:field) and unprefixed (field) attribute conditions correctly index matching elements and that the query optimizer rewrites predicates on both.

Test Plan

  • Range index XQSuite tests: 351 pass, 0 failures
  • RangeIndexConfigTest unit test passes
  • CI: all checks pass (ubuntu/windows/macOS integration, unit tests, license, XQTS, Codacy)

🤖 Generated with Claude Code

@joewiz joewiz force-pushed the fix/issue-5189-range-index-prefixed-condition branch from 9ddb80f to 9221d28 Compare March 3, 2026 23:43
joewiz and others added 2 commits March 4, 2026 20:40
…x conditions

The range index condition's @Attribute accepted prefixed names like
"wwp:field" but ignored the namespace prefix, binding it to the null
namespace. This caused two bugs:

1. A prefixed attribute (wwp:field) and an unprefixed attribute (field)
   were treated as identical by the indexer.
2. The matches() method used DOM getAttribute() with the raw prefixed
   string instead of getAttributeNS() with the resolved namespace URI.

Fix by resolving the prefix against the namespace map declared on the
<index> element (the same map already used for qname resolution on
<create> elements), and using getAttributeNS() for namespace-aware
attribute lookup.

Also update collection.xconf.xsd to allow xs:string (not xs:NCName)
for the condition @Attribute, consistent with how @Qname is typed
elsewhere in the schema.

Closes eXist-db#5189

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ndex

Tests verify that range index conditions using namespace-prefixed
attribute names (e.g. wwp:field) correctly index matching elements
and that the query optimizer rewrites predicates on prefixed attributes.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@joewiz joewiz force-pushed the fix/issue-5189-range-index-prefixed-condition branch from 9221d28 to b16d534 Compare March 5, 2026 01:40
@joewiz joewiz marked this pull request as ready for review March 5, 2026 04:04
@joewiz joewiz requested a review from a team as a code owner March 5, 2026 04:04
@joewiz
Copy link
Member Author

joewiz commented Mar 5, 2026

Documentation update notes

Suggested additions to the "Conditional Indexes" section of https://exist-db.org/exist/apps/doc/newrangeindex:

  • Namespaced attribute conditions are now supported. The @attribute value in a <condition> element can use a prefixed name (e.g., wwp:field), and the prefix will be resolved against the namespace declarations on the <index> element — the same mechanism already used for @qname on <create> elements.

  • Example showing a prefixed attribute condition:

    <index xmlns:tei="http://www.tei-c.org/ns/1.0"
           xmlns:wwp="http://www.wwp.northeastern.edu/ns/textbase">
        <range>
            <create qname="tei:title">
                <condition attribute="wwp:field" value="title"/>
                <field name="wwp-title" type="xs:string"/>
            </create>
        </range>
    </index>

    This indexes only tei:title elements that have @wwp:field="title", where wwp:field is resolved to the http://www.wwp.northeastern.edu/ns/textbase namespace.

  • Namespace declaration requirement: The prefix used in @attribute must be declared on the <index> element (or an ancestor in the collection.xconf). This is the same requirement as for prefixed @qname values on <create> elements.

  • Prefixed vs. unprefixed: <condition attribute="wwp:field" .../> matches the namespaced attribute @wwp:field, while <condition attribute="field" .../> matches the unprefixed (null namespace) attribute @field — even if both appear on the same element, they are treated as separate attributes and indexed independently.

🤖 Co-authored with Claude Code

@duncdrum duncdrum added the Lucene issue is related to Lucene or its integration label Mar 5, 2026
@duncdrum duncdrum self-assigned this Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Lucene issue is related to Lucene or its integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Inconsistent treatment of prefixed attribute names in range index definitions

2 participants