1
votes

I have a set of documents similar to parent child relation, except that they are not indexed as nested - they are denormalized. below are the set of records

id,parent_id,,author

1,0,a1

2,1,a2

3,1,a3

4,1,a4

5,0,a5

6,5,a6

7,5,a7

8,0,a8

9,8,a9

10,0,a10

The above records with id 1,5,8,10 are parent records(parent_id=0) and others are child(their parent_id value is their parent)

My solr query should facet based on parent_id for child records, use that pivot parent_id and match it with id to get the author of parent

Need to combine below two queries into one

query 1: fq=-parent_id:0&facet=true;facet.pivot=parent_id

From above query if get three parent ids as result of faceting - 1,5,8,10

query 2: fl=author&fq=parent_id IN {1,5,8,10}

Finally output should be a1,a5,a8,a10 - Ideally I need top author which is a1 as they have 4 children

I tried local parameters option, faceting etc. But not able to find way to combine the output of facet query, and use it in another query - all in one go.

Restrictions are - not able to nest documents to use block join. Any help would be greatly appreciated. Thank you

1
can you accept the answer if it solved your problem?Sumeet Sharma

1 Answers

1
votes
fq={!join from=parent_id to=id}-parent_id:0&facet=true&facet.field=author

So the -parent_id:0 : will give all the results apart from 1,5,8,10 and the join will return documents corresponding to the 1,5,8,10 . Join returns only the documents to which the join is done, so when you apply facet the resultant facets will be on the 1,5,8,10 docs giving you your required resultset.