marklogic - Custom sort-order in Xquery search options -


i writing rest extension search, , takes in parameters search in json nested document. able writing custom constraint, , custom constraint parse search text , build query..

can same sort-order well? way, mean build sort-order search options based on parameters passed..

i saw in 1 of examples, following

let $options := <search:options>   <search:operator name="sort">     <search:state name="relevance">       <search:sort-order>         <search:score/>       </search:sort-order>     </search:state>     <search:state name="year">       <search:sort-order direction="descending" type="xs:gyear"             collation="">         <search:attribute ns="" name="year"/>         <search:element ns="http://marklogic.com/wikipedia"           name="nominee"/>       </search:sort-order>       <search:sort-order>         <search:score/>       </search:sort-order>     </search:state>   </search:operator> </search:options> return search:search("lange sort:year", $options) 

but here there kind of hard-coding fields sort. want custom-constraint, @ run time determine sort-order columns..

is possible ??

well, example give, mention it's sort of hard coded. @ state, xml. can use programming logic before step decide elements , sort-order , build xml accordingly. tiny example below make sort ascending or descending title element. tiny example should understand might on larger scale.

let $sort-direction := "descending"  let $options :=     <search:options>       <search:operator name="sort">         <search:state name="relevance">           <search:sort-order>             <search:score/>           </search:sort-order>         </search:state>         <search:state name="year">           <search:sort-order direction="{$sort-direction}" type="xs:gyear"                 collation="">             <search:attribute ns="" name="year"/>             <search:element ns="http://marklogic.com/wikipedia"               name="nominee"/>           </search:sort-order>           <search:sort-order>             <search:score/>           </search:sort-order>         </search:state>       </search:operator>     </search:options>     return     search:search("lange sort:year", $options) 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -