Search code examples
solrlucenefieldcollapsing

SOLR Collapse field - range filter where MIN


I have a problem with SOLR Collapse I cannot move with.

Assuming documents

{ id: 1, parent_id: x, value: 3 },
{ id: 2, parent_id: y, value: 5 },
{ id: 3, parent_id: x, value: 7 },
{ id: 4, parent_id: y, value: 10 }

now let's say I want to collapse on parent_id and minimum value doc:

{!collapse field=parent_id min=value }

what I get from SOLR is expected:

GROUP x: { id: 1, parent_id: x, value: 3 },
GROUP y: { id: 2, parent_id: y, value: 5 }

but let's say I want to get results where minimum value is 4, so I apply a filter.

{!collapse field=parent_id min=value } {value:[4 TO *]}

What I get is understandable but not exactly what I want:

GROUP x: { id: 3, parent_id: x, value: 7 },
GROUP y: { id: 2, parent_id: y, value: 5 }

So the results are filtered then collapsed on the parent_id and minimum value is selected but what I really want is to get only those groups which MINIMUM value is within the range:

GROUP y: { id: 2, parent_id: y, value: 5 }
GROUP x is not in result as minimum value is 3

If I understand correctly from docs - collapsing happens after the request but is there any way how to retrieve what I am trying?

Thanks a lot


Solution

  • as you said, the other query is run first, then collapse post filter runs.

    I would try this with Streaming Expressions, you should be able to:

    • group by parent_id
    • take min of value
    • filter the tuples whose value > your range

    Take a look at the things you can do in the page above