jaybe78
jaybe78

Reputation: 371

SOLR : How to make solr filter on collapsed result set

I have a problem using SOLR Collapse which gives me unexpected result.

Assuming travellers:

{ traveller_id: 1, geo_hash: 4_u3bu, start_time: 2016-07-14T23:59:00Z },
{ traveller_id: 1, geo_hash: 4_de5f, start_time: 2018-07-14T23:59:00Z },
{ traveller_id: 2, geo_hash: 4_u3bu, start_time: 2018-07-14T23:59:00Z },

Basically I got 2 fq in my query like the followings...

The first one groups document by traveller id having most recent start time.

fq={!collapse field=traveller_id min=ms(now,start_time) }

At this point, when I only add that filter in my query, I get the following result:

 { traveller_id: 1, geo_hash: 4_de5f, start_time: 2018-07-14T23:59:00Z},
 { traveller_id: 2, geo_hash: 4_u3bu, start_time: 2018-07-14T23:59:00Z},

Looks good... But, wait!

If I also add an extra fq to only get the documents with a particular geohash, within the latter below:

fq=geohash: (4_u3bu)

Then the results becomes incorrect:

{ traveller_id: 1, geo_hash: 4_u3bu, start_time: 2016-07-14T23:59:00Z },
{ traveller_id: 2, geo_hash: 4_u3bu, start_time: 2018-07-14T23:59:00Z },

Looks like solr started by picking up the traveller with geohash: 4_u3bu and only then does the grouping.

Why is that ? I expected Solr to first group by most recent traveller and then applying the geohash filter...

Result expected is:

{ traveller_id: 2, geo_hash: 4_u3bu, start_time: 2018-07-14T23:59:00Z },

Is there anyway to solve that ??

Thanks

Upvotes: 0

Views: 1385

Answers (2)

jaybe78
jaybe78

Reputation: 371

The only way to solve this is to use a custom plug in which will do the filtering after the grouping is done.

Upvotes: 0

Persimmonium
Persimmonium

Reputation: 15791

even though it is used in a fq, the collapsing query parser it is not actually filtering out any document out, it just groups them by traveller_id, and then selects a single doc from each group as head of the group.

So this result is expected, when you apply fq=geohash: (4_u3bu), only two docs are returned by this, and then collapse does nothing at all on this result, as the two docs each form a group, there is nothing to collapse...

To do what you want try this: it might work by making the second fq exectute later (dont have much time now to test)

fq={!collapse field=traveller_id min=ms(now,start_time)}&fq={cache=false cost=200}geohash: (4_u3bu)

Upvotes: 1

Related Questions