问题
Requirement:
Resolve directly through Index, don't want to open the documents (Hence, Not considering FLOWR expression).
Search results return a list of purchase order documents
The purchase order may or may not have a line-item (for purposes of example)
- There can be thousands of line items for a purchase order, each with a different type
- There will only be 1 line-item for a type (no duplicates within the purchase order)
- 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