Hello, I am trying to implement a Rollup Search component on a version of SOLR that exists previously to the parent/child additions, so I am trying to implement my own. The searches will be executed exclusively against the child documents, and I want to “rollup” those child documents into the parent documents.
The interface is going to allow the user to add the following parameters to the SOLR query: &rollup=true&rollup.parentField=id&rollup.childField=parentId My code so far is below. What I have works so far, except my second parent query loses the order. I would like to be able to sort my parent query by the score of the previous child search. Perhaps I would take the highest score from all children (haven’t decided yet). My problem however is that I don’t know how I can get the score from all the hits in the original search, just what is returned. If my child query gets 10,000 hits, but only return 100 records, I can’t get all the scores I need. Does anyone have any recommendations? Thanks!! Darin //Loop through all the records and look for the parent reference field Set<String> parentRefs = new HashSet<String>(); DocIterator docSetIterator = rb.getResults().docSet.iterator(); while(docSetIterator.hasNext()){ int docInt = docSetIterator.next(); String fieldValues[] = rb.req.getSearcher().doc(docInt).getValues(childFieldName); for(String fieldValue : fieldValues){ if(fieldValue != null && fieldValue.length() > 0 && !parentRefs.contains(fieldValue)){ parentRefs.add(fieldValue); } } } //Build a boolean query of term queries BooleanQuery parentQuery = new BooleanQuery(); Iterator<String> parentIdIterator = parentRefs.iterator(); while(parentIdIterator.hasNext()){ String parentId = parentIdIterator.next(); TermQuery termQuery = new TermQuery(new Term(parentFieldName, parentId)); parentQuery.add(termQuery, BooleanClause.Occur.SHOULD); } DocList parentList = searcher.getDocList(parentQuery, new ArrayList<Query>(), null, 0, 100, 1); //TODO: use correct start/end/flags later... //Add parent results ResultContext resultContext = new ResultContext(); resultContext.docs = parentList; resultContext.query = parentQuery; rb.rsp.add("parents", resultContext); rb.rsp.getToLog().add("hits", parentList.matches());