int i;
int countModuleHit = 0;
for (i = 0; i < hits.length() && results.size() < RESULTS_PER_PAGE; i++) {
Document doc = hits.doc(i);
String key = doc.get("visibility")+"/"+doc.get("organisation")+"/"+doc.get("module")+"/"+doc.get("fqcn");
Hit hit = (Hit) h.get(key);
if (hit == null) {
hit = new Hit(doc.get("visibility"), doc.get("organisation"), doc.get("module"), doc.get("fqcn"), hits.score(i));
h.put(key, hit);
if (countModuleHit >= startIndex) {
results.add(hit);
}
countModuleHit++;
}
// not stricly necessary, but sometimes lucene doesn't find the revisions in the second step...
hit.addRevision(doc.get("path"), doc.get("revision"));
}
Long nextResults = i == hits.length()?null:new Long(startIndex+RESULTS_PER_PAGE);
Long previousResults = startIndex == 0?null:new Long(startIndex-RESULTS_PER_PAGE);
// then we fill in revisions
for (Iterator iter = results.iterator(); iter.hasNext();) {
Hit hit = (Hit) iter.next();
hits = is.search(query, new QueryFilter(queryParser.parse(
"organisation:"+hit.getOrganisation()
+" AND module:"+hit.getModule()
+" AND fqcn:"+hit.getClassname()
)));
for (i = 0; i < hits.length(); i++) {
Document doc = hits.doc(i);
hit.addRevision(doc.get("path"), doc.get("revision"));
}
}
is.close();