How to do Selective Sorting by Attribute based on associated Value of Element or other Attribute in MarkLogic

人盡茶涼 提交于 2019-12-11 18:23:38

问题


Requirement:

  1. Resolve directly through Index, don't want to open the documents (Hence, Not considering FLOWR expression).

  2. Search results return a list of purchase order documents

  3. The purchase order may or may not have a line-item (for purposes of example)

  4. There can be thousands of line items for a purchase order, each with a different type
  5. There will only be 1 line-item for a type (no duplicates within the purchase order)
  6. For sorting: Based on one of the many types selected by user at the time of search (sometime chair and sometime lamp etc..) Sort order based on the amount for that specific type Only (for example: chair)

Sample document 1:

<purchase-order>
  <line-items>
    <line-item type="lamp"  amount="3500"></line-item>
    <line-item type="couch"  amount="50000"></line-item>
    <line-item type="chair"  amount="40000"></line-item>
  </line-items>
 <other-stuff></other-stuff>
</purchase-order>


Sample document 2:

<purchase-order>
  <line-items>
  <line-item type="couch"  amount="10000"> </line-item>
  <line-item type="chair"  amount="80000"></line-item>
 </line-items>
 <other-stuff></other-stuff>
</purchase-order>   

Expected Result sequence:

  • Request to sort doc by the amount desc for type chair should return the sequence of doc 2 and 1
  • Request to sort doc by the amount desc for type couch should return the sequence of doc 1 and 2

来源:https://stackoverflow.com/questions/55183482/how-to-do-selective-sorting-by-attribute-based-on-associated-value-of-element-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!