in SphinxQL get largest matching value from JSON MVA field

215 views Asked by At

With SphinxQL, I would like to sort the results by a JSON MVA property that has a filter criteria associated with it.

For example, I have an Index that contains:

event_id,    
tickets

where tickets is a JSON array like:

[{"type":"Child","price":10.00},
 {"type":"Adult","price":20.00},
  ...  
 {"type":"VIP"  ,"price":50.00}
]

The entries in the JSON array are sorted by price which allows sorting filtered data in ascending order like this:

SELECT event_id, 
       tickets, 
       tickets[INDEXOF(any(t.price >= 20.00 and 
                           t.price <= 30.00 
                           for t in tickets)
                      )
              ].price * 1.0 as from_price,
       any(t.price >= 20.00 and 
           t.price <= 30.00 
           for t in tickets) as found_price_range 
FROM   <index_name>
WHERE  found_price_range = 1
ORDER BY from_price ASC

But, how can I sort in DESCENDING order? I need to pull out the largest tickets.price element within the requested price range and I don't see any way to do that with SphinxQL. tickets[LENGTH(tickets)-1].price will get me the biggest ticket price at the event, but it will not respect the price range filter.

The solution needs to be in pure SphinxQL in order to preserve the ability for external pagination tools to work properly.

0

There are 0 answers