Author: hardy.ferentschik
Date: 2009-05-12 11:21:13 -0400 (Tue, 12 May 2009)
New Revision: 16552
Modified:
search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
Log:
HSEARCH-330 Made sure that calculateTopDocsRetrievalSize will not overrun and that at most
Integer.MAX_VALUE-1 is returned. Using such a high value will, however, on many/most
systems create OutOfMemoryExceptions since Lucene will instantiate an Object array with
the specified size!
Modified: search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
---
search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2009-05-12
13:09:57 UTC (rev 16551)
+++
search/trunk/src/main/java/org/hibernate/search/query/FullTextQueryImpl.java 2009-05-12
15:21:13 UTC (rev 16552)
@@ -33,7 +33,6 @@
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
-import org.hibernate.util.ReflectHelper;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.query.ParameterMetadata;
import org.hibernate.impl.AbstractQueryImpl;
@@ -41,6 +40,7 @@
import org.hibernate.search.FullTextFilter;
import org.hibernate.search.FullTextQuery;
import org.hibernate.search.SearchException;
+import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.engine.DocumentBuilderIndexedEntity;
import org.hibernate.search.engine.DocumentExtractor;
import org.hibernate.search.engine.EntityInfo;
@@ -50,7 +50,6 @@
import org.hibernate.search.engine.ProjectionLoader;
import org.hibernate.search.engine.QueryLoader;
import org.hibernate.search.engine.SearchFactoryImplementor;
-import org.hibernate.search.engine.DocumentBuilder;
import org.hibernate.search.filter.ChainedFilter;
import org.hibernate.search.filter.FilterKey;
import org.hibernate.search.filter.StandardFilterKey;
@@ -62,6 +61,7 @@
import static org.hibernate.search.util.FilterCacheModeTypeHelper.cacheResults;
import org.hibernate.search.util.LoggerFactory;
import org.hibernate.transform.ResultTransformer;
+import org.hibernate.util.ReflectHelper;
/**
* Implementation of {@link org.hibernate.search.FullTextQuery}.
@@ -359,15 +359,22 @@
/**
* @return Calculates the number of <code>TopDocs</code> which should be
retrieved as part of the query. If Hibernate's
- * pagination parameters are set returned value is <code>first +
maxResults</code>. Otherwise <code>null</code> is
- * returned.
+ * pagination parameters are set returned value is <code>first +
maxResults</code>. Otherwise <code>null</code> is
+ * returned.
*/
private Integer calculateTopDocsRetrievalSize() {
if ( maxResults == null ) {
return null;
}
else {
- return first() + maxResults;
+ long tmpMaxResult = (long) first() + maxResults;
+ if ( tmpMaxResult >= Integer.MAX_VALUE ) {
+ // don't return just Integer.MAX_VALUE due to a bug in Lucene - see HSEARCH-330
+ return Integer.MAX_VALUE - 1;
+ }
+ else {
+ return (int) tmpMaxResult;
+ }
}
}
@@ -738,7 +745,9 @@
else {
TopDocs hits;
try {
- hits = getQueryHits( searcher, 1 ).topDocs; // Lucene enforces that at least one top
doc will be retrieved.
+ hits = getQueryHits(
+ searcher, 1
+ ).topDocs; // Lucene enforces that at least one top doc will be retrieved.
resultSize = hits.totalHits;
}
catch ( IOException e ) {
Show replies by date