xquery - Compare two elements of the same document in Mark Logic -


i have marklogic 8 database in there documents have 2 date time fields:

  1. created-on
  2. active-since

i trying write xquery search documents value of active-since is less than value of created-on

currently using following flwor exression:

    $entity in fn:collection("entities")      let $id := fn:data($entity//id)     let $created-on := fn:data($entity//created-on)     let $active-since := fn:data($entity//active-since)      $active-since < $created-on      return        (         $id,         $created-on,         $active-since       ) 

the above query takes long execute , increase in number of documents execution time of query increase.

also, have element-range-index both above mentioned datetime fields not getting used here. cts-element-query function compares 1 element set of atomic values. in case trying compare 2 elements of same document.

i think there should better , optimized solution problem.

please let me know in case there search function or other approach suitable in scenario.

thanks.

you might try using cts:tuple-values(). pass in 3 references: active-since, created-on, , uri reference. iterate results looking ones active-since less created-on, , you'll have uri of doc.

it's not prettiest code, let data come ram, should scale nicely.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -