Skip to content

Commit

Permalink
Fixing total result count; #39
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jun 4, 2019
1 parent a8db08b commit 1d4c835
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,19 @@ public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aReque
final int nMaxResults = nLastResultIndex + 1;

// Search all documents
final ICommonsList <PDStoredBusinessEntity> aResultDocs = PDMetaManager.getStorageMgr ()
.getAllDocuments (aLuceneQuery,
nMaxResults);
final PDStorageManager aStorageMgr = PDMetaManager.getStorageMgr ();
final ICommonsList <PDStoredBusinessEntity> aResultDocs = aStorageMgr.getAllDocuments (aLuceneQuery, nMaxResults);

// Also get the total hit count for UI display. May be < 0 in case of
// error
final int nTotalBEs = aStorageMgr.getCount (aLuceneQuery);

LOGGER.info (" Result for <" +
aLuceneQuery +
"> (max=" +
nMaxResults +
") " +
(aResultDocs.size () == 1 ? "is 1 document" : "are " + aResultDocs.size () + " documents"));
(nTotalBEs == 1 ? "is 1 document" : "are " + nTotalBEs + " documents"));

// Filter by index/count
final int nEffectiveLastIndex = Math.min (nLastResultIndex, aResultDocs.size () - 1);
Expand All @@ -301,7 +304,7 @@ public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aReque
final IMicroDocument aDoc = new MicroDocument ();
final IMicroElement eRoot = aDoc.appendElement ("resultlist");
eRoot.setAttribute (RESPONSE_VERSION, eSearchVersion.getVersion ());
eRoot.setAttribute (RESPONSE_TOTAL_RESULT_COUNT, aResultDocs.size ());
eRoot.setAttribute (RESPONSE_TOTAL_RESULT_COUNT, nTotalBEs);
eRoot.setAttribute (RESPONSE_USED_RESULT_COUNT, aResultView.size ());
eRoot.setAttribute (RESPONSE_RESULT_PAGE_INDEX, nResultPageIndex);
eRoot.setAttribute (RESPONSE_RESULT_PAGE_COUNT, nResultPageCount);
Expand Down Expand Up @@ -335,7 +338,7 @@ public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aReque
final JsonWriterSettings aJWS = new JsonWriterSettings ().setIndentEnabled (bBeautify);
final IJsonObject aDoc = new JsonObject ();
aDoc.add (RESPONSE_VERSION, eSearchVersion.getVersion ());
aDoc.add (RESPONSE_TOTAL_RESULT_COUNT, aResultDocs.size ());
aDoc.add (RESPONSE_TOTAL_RESULT_COUNT, nTotalBEs);
aDoc.add (RESPONSE_USED_RESULT_COUNT, aResultView.size ());
aDoc.add (RESPONSE_RESULT_PAGE_INDEX, nResultPageIndex);
aDoc.add (RESPONSE_RESULT_PAGE_COUNT, nResultPageCount);
Expand Down

0 comments on commit 1d4c835

Please # to comment.