Jinson George
Jinson George

Reputation: 139

Is it possible to compare element values of a document on search in marklogic

I want to understand if marklogic has the ability to compare element values within a single document while performing a search i.e. cts:search.

For eg:

Consider a document as below

<root>
    <someTags></someTags>
    .
    .
    .
    <effectivePeriod>
        <dateTimeBegin>2009-01-16T00:00:00-05:00
        </dateTimeBegin>
        <dateTimeEnd>2009-01-16T00:00:00-05:00
        </dateTimeEnd>
    </effectivePeriod>
    .
    .
    .
    <otherTags></otherTags>
</root>

Let's imagine that there are a hundred thousand documents like the one above. How can I make a search that ensures I only pick up documents where the effectivePeriod.dateTimeEnd > effectivePeriod.dateTimeBegin?

Upvotes: 2

Views: 123

Answers (2)

Mads Hansen
Mads Hansen

Reputation: 66714

Construct your cts:search() with as specific criteria as possible, and then filter the results with a predicate:

cts:search(collection(), 
           cts:and-query())[root/effectivePeriod[dateTimeEnd gt dateTimeBegin]]

Upvotes: 1

Sam Mefford
Sam Mefford

Reputation: 2475

Have you taken a look at cts.periodCompareQuery?

Upvotes: 0

Related Questions