/** * Getter for the Limit calculated bye on the limit defined by the query * and the configuration of the default results (for queries that do not * define a limit) and the maximum number of Results.<p> * Configurations for defaultResults and maxResults <= 0 are ignored. Return * values < = 0 should be interpreted as no constraints. * @param query the query * @param defaultResults the default number of results * @param maxResults the maximum number of queries * @return if > 0, than the value represents the number of results for the * query. Otherwise no constraint. */ public static int getLimit(Query query,int defaultResults, int maxResults){ int limit = query.getLimit() != null?query.getLimit():-1; if(defaultResults > 0){ limit = Math.min(limit, defaultResults); } if(maxResults > 0){ limit = Math.min(limit,maxResults); } return limit; }
private SolrQuery initSolrQuery(Query entityhubQuery) { SolrQuery query = new SolrQuery(); // first add a filterquery for the domain if present if (domain != null) { query.addFilterQuery(String.format("%s:%s", fieldMapper.getDocumentDomainField(), SolrUtil.escapeSolrSpecialChars(domain))); } // than add the offset query.setStart(entityhubQuery.getOffset()); // and the limit if (entityhubQuery.getLimit() != null) { if (entityhubQuery.getLimit().compareTo(MAX_QUERY_RESULTS) <= 0) { query.setRows(entityhubQuery.getLimit()); } else { log.warn(String.format( "Parsed Number of QueryResults {} is greater than the allowed maximum of {}!", entityhubQuery.getLimit(), MAX_QUERY_RESULTS)); entityhubQuery.setLimit(MAX_QUERY_RESULTS); } } else { // maybe remove that to prevent to many results! But for now I would // rather like to have a default value within the FieldQuery! // e.g. set by the FieldQueryFactory when creating new queries! query.setRows(DEFAULT_QUERY_RESULTS); entityhubQuery.setLimit(DEFAULT_QUERY_RESULTS); } return query; }
private SolrQuery initSolrQuery(Query entityhubQuery) { SolrQuery query = new SolrQuery(); // first add a filterquery for the domain if present if (domain != null) { query.addFilterQuery(String.format("%s:%s", fieldMapper.getDocumentDomainField(), SolrUtil.escapeSolrSpecialChars(domain))); } // than add the offset query.setStart(entityhubQuery.getOffset()); // and the limit if (entityhubQuery.getLimit() != null) { if (entityhubQuery.getLimit().compareTo(MAX_QUERY_RESULTS) <= 0) { query.setRows(entityhubQuery.getLimit()); } else { log.warn(String.format( "Parsed Number of QueryResults {} is greater than the allowed maximum of {}!", entityhubQuery.getLimit(), MAX_QUERY_RESULTS)); entityhubQuery.setLimit(MAX_QUERY_RESULTS); } } else { // maybe remove that to prevent to many results! But for now I would // rather like to have a default value within the FieldQuery! // e.g. set by the FieldQueryFactory when creating new queries! query.setRows(DEFAULT_QUERY_RESULTS); entityhubQuery.setLimit(DEFAULT_QUERY_RESULTS); } return query; }
/** * Getter for the Limit calculated bye on the limit defined by the query * and the configuration of the default results (for queries that do not * define a limit) and the maximum number of Results.<p> * Configurations for defaultResults and maxResults <= 0 are ignored. Return * values < = 0 should be interpreted as no constraints. * @param query the query * @param defaultResults the default number of results * @param maxResults the maximum number of queries * @return if > 0, than the value represents the number of results for the * query. Otherwise no constraint. */ public static int getLimit(Query query,int defaultResults, int maxResults){ int limit = query.getLimit() != null?query.getLimit():-1; if(defaultResults > 0){ limit = Math.min(limit, defaultResults); } if(maxResults > 0){ limit = Math.min(limit,maxResults); } return limit; }