Skip to content

Commit

Permalink
implementation of method getTotalHits
Browse files Browse the repository at this point in the history
Issue #554
  • Loading branch information
rsoika committed Sep 3, 2019
1 parent 565ab24 commit bd1d52d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ public static String getKey(String key, String json) {
result = parser.getString();
break;
}
if (event.name().equals(Event.VALUE_NUMBER.toString())) {
result = parser.getBigDecimal()+"";
break;
}
if (event.name().equals(Event.VALUE_TRUE.toString())) {
result = "true";
break;
}
if (event.name().equals(Event.VALUE_FALSE.toString())) {
result = "false";
break;
}
if (event.name().equals(Event.VALUE_NULL.toString())) {
result = null;
break;
}
if (event.name().equals(Event.START_OBJECT.toString())) {
// just return the next json object here
result = parser.getObject().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ public String query(String searchTerm, int pageSize, int pageIndex, SortOrder so
}
}

// page size
if (pageSize <= 0) {
// page size of 0 is allowed here - this will be used by the getTotalHits method of the SolrSearchService
if (pageSize < 0) {
pageSize = DEFAULT_PAGE_SIZE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.logging.Logger;

import javax.annotation.security.DeclareRoles;
Expand All @@ -46,13 +45,13 @@

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.WorkflowKernel;
import org.imixs.workflow.engine.DocumentService;
import org.imixs.workflow.engine.index.DefaultOperator;
import org.imixs.workflow.engine.index.SchemaService;
import org.imixs.workflow.engine.index.SearchService;
import org.imixs.workflow.engine.index.SortOrder;
import org.imixs.workflow.exceptions.QueryException;
import org.imixs.workflow.util.JSONParser;

/**
* This session ejb provides a service to search the solr index.
Expand Down Expand Up @@ -178,11 +177,10 @@ public List<ItemCollection> search(String searchTerm, int pageSize, int pageInde
* method did not load any data. The provided search term will we extended with
* a users roles to test the read access level of each workitem matching the
* search term.
* <p>
* In Solr we can get the count if we the the query param 'row=0'.
* The the response contains still the numFound but not docs!
*
* The optional param 'maxResult' can be set to overwrite the
* DEFAULT_MAX_SEARCH_RESULT.
*
* @see search(String, int, int, Sort, Operator)
*
* @param sSearchTerm
* @param maxResult
Expand All @@ -194,31 +192,31 @@ public List<ItemCollection> search(String searchTerm, int pageSize, int pageInde
@Override
public int getTotalHits(final String _searchTerm, final int _maxResult, final DefaultOperator defaultOperator)
throws QueryException {

int maxResult = _maxResult;

if (maxResult <= 0) {
maxResult = DEFAULT_MAX_SEARCH_RESULT;
}
long l=System.currentTimeMillis();
int hits=0;
// if (_maxResult!=0) {
// logger.severe("getTotalHits should be called with maxResult==0");
// return 0;
// }

// quey only the $uniqueid
String searchTerm = schemaService.getExtendedSearchTerm(_searchTerm);
// test if searchtem is provided
if (searchTerm == null || "".equals(searchTerm)) {
return 0;
}

// post query....
String result = solarIndexService.query(searchTerm, _maxResult, 0,null,defaultOperator, true);

// TODO now parse the count!!!
//
//
// logger.finest("......Result = " + result);
//
//
// post query with row = 0
String result = solarIndexService.query(searchTerm, 0, 0,null,defaultOperator, true);
try {
String response=JSONParser.getKey("response", result);
hits=Integer.parseInt(JSONParser.getKey("numFound", response));
} catch (NumberFormatException e) {
logger.severe("getTotalHits - failed to parse solr result object! - " + e.getMessage());
hits=0;
}

return 0;
logger.info("......computed totalHits in " +(System.currentTimeMillis()-l) + "ms");
return hits;
}

/**
Expand Down

0 comments on commit bd1d52d

Please sign in to comment.