Author: cstamas Date: Thu Mar 31 13:51:12 2011 New Revision: 1087297 URL: http://svn.apache.org/viewvc?rev=1087297&view=rev Log: MINDEXER-14: fix.
* HitLimit as "feature" dropped. API calls in place but deprecated and return always "not-hit-limited" values. * To limit result set size, use Count. Works on IteratorSearch and FlatSearch, but not on GroupedSearch (TODO) * smaller fixes regarding API deprecation and better method namings Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchPageableRequest.java (with props) maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java (with props) Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchRequest.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchResponse.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchRequest.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchResponse.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchRequest.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchResponse.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchRequest.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchResponse.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/archetype/NexusArchetypeDataSource.java maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus3177HitLimitChecks.java Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchPageableRequest.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchPageableRequest.java?rev=1087297&view=auto ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchPageableRequest.java (added) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchPageableRequest.java Thu Mar 31 13:51:12 2011 @@ -0,0 +1,94 @@ +package org.apache.maven.index; + +import java.util.List; + +import org.apache.lucene.search.Query; +import org.apache.maven.index.context.IndexingContext; + +public class AbstractSearchPageableRequest + extends AbstractSearchRequest +{ + /** + * Constant for denoting undefined value for result count. + */ + protected static final int UNDEFINED = -1; + + /** + * The number of hit we want to skip from result set. Defaults to 0. + */ + private int start; + + /** + * The page size, actually count of items in one page. Different than limit, because this will _cut_ the response to + * the requested count. + */ + private int count; + + public AbstractSearchPageableRequest( Query query ) + { + super( query, null ); + + this.start = 0; + + this.count = UNDEFINED; + } + + public AbstractSearchPageableRequest( Query query, List<IndexingContext> contexts ) + { + super( query, contexts ); + + this.start = 0; + + this.count = UNDEFINED; + } + + /** + * Returns the "start" of wanted results calculated from result set window. Simply, the count of documents to skip. + * + * @return + */ + public int getStart() + { + return start; + } + + /** + * Sets the "start" of wanted results calculated from result set window. Simply, the count of documents to skip. + * + * @param start + */ + public void setStart( int start ) + { + if ( start < 0 ) + { + throw new IllegalArgumentException( "Start cannot be less than 0!" ); + } + + this.start = start; + } + + /** + * Returns the "count" of wanted results. See {@link #UNDEFINED}. + * + * @return + */ + public int getCount() + { + return count; + } + + /** + * Sets the "count" of wanted results. See {@link #UNDEFINED}. + * + * @param count + */ + public void setCount( int count ) + { + if ( UNDEFINED != count && count < 1 ) + { + throw new IllegalArgumentException( "Count cannot be less than 1!" ); + } + + this.count = count; + } +} Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchPageableRequest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchPageableRequest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchRequest.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchRequest.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchRequest.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchRequest.java Thu Mar 31 13:51:12 2011 @@ -26,29 +26,10 @@ import org.apache.maven.index.context.In public class AbstractSearchRequest { - public static final int UNDEFINED = -1; - - public static final int UNDEFINED_HIT_LIMIT = 1000; - private Query query; private List<IndexingContext> contexts; - private int start; - - /** - * The page size, actually count of items in one page. Different than limit, because this will _cut_ the response to - * the requested count. - */ - private int count; - - /** - * The limit size, the maximum possible count of items in response. Different than count above, since if this is - * set, and the search funds more then this number, the response will be _empty_ and a flag will be set on response - * about this. - */ - private int resultHitLimit; - /** * The filter to be used while executing the search request. */ @@ -84,13 +65,6 @@ public class AbstractSearchRequest { getContexts().addAll( contexts ); } - - this.start = UNDEFINED; - - this.count = UNDEFINED; - - // TODO: rethink use cases and find better way to provide this value! - this.resultHitLimit = UNDEFINED_HIT_LIMIT; } public Query getQuery() @@ -118,51 +92,40 @@ public class AbstractSearchRequest this.contexts = contexts; } - public boolean isHitLimited() - { - return getResultHitLimit() != UNDEFINED_HIT_LIMIT; - } - - public int getStart() - { - return start; - } - - public void setStart( int start ) - { - this.start = start; - } - - public int getCount() - { - return count; - } - - @Deprecated - public int getAiCount() - { - return getCount(); - } - - public void setCount( int count ) - { - this.count = count; - } - - @Deprecated - public void setAiCount( int count ) + /** + * Returns true if hits are limited. + * + * @return + * @deprecated always returns false, since 4.1.0 there is no notion of hit limit + * @see http://jira.codehaus.org/browse/MINDEXER-14 + */ + public boolean _isHitLimited() { - setCount( count ); + return false; } - public int getResultHitLimit() + /** + * Gets the hit limit. Since 4.1.0 does nothing, always returns 0. + * + * @return + * @deprecated always returns false, since 4.1.0 there is no notion of hit limit + * @see http://jira.codehaus.org/browse/MINDEXER-14 + */ + public int _getResultHitLimit() { - return resultHitLimit; + return -1; } - public void setResultHitLimit( int resultHitLimit ) + /** + * Sets the hit limit. Since 4.1.0 does nothing. + * + * @param resultHitLimit + * @deprecated always returns false, since 4.1.0 there is no notion of hit limit + * @see http://jira.codehaus.org/browse/MINDEXER-14 + */ + public void _setResultHitLimit( int resultHitLimit ) { - this.resultHitLimit = resultHitLimit; + // noop } public ArtifactInfoFilter getArtifactInfoFilter() Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchResponse.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchResponse.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchResponse.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/AbstractSearchResponse.java Thu Mar 31 13:51:12 2011 @@ -18,21 +18,27 @@ */ package org.apache.maven.index; +import java.io.Closeable; +import java.io.IOException; + import org.apache.lucene.search.Query; public class AbstractSearchResponse + implements Closeable { - public static int LIMIT_EXCEEDED = -1; - private final Query query; - private final int totalHits; + private final int totalHitsCount; - public AbstractSearchResponse( Query query, int totalHits ) + private final int returnedHitsCount; + + public AbstractSearchResponse( final Query query, final int totalHitsCount, final int returnedHitsCount ) { this.query = query; - this.totalHits = totalHits; + this.totalHitsCount = totalHitsCount; + + this.returnedHitsCount = returnedHitsCount; } public Query getQuery() @@ -40,13 +46,63 @@ public class AbstractSearchResponse return query; } + /** + * Returns the number of total hits found. This may be different that actual hits returned (is usually more). + * + * @return + * @deprecated use {@link #getTotalHitsCount()} instead. + */ public int getTotalHits() { - return totalHits; + return getTotalHitsCount(); + } + + /** + * Returns the number of total hits found by this query (total number of potential hits as reported by Lucene + * index). This is the number of existing AIs matching your query, and does not represent the count of hits + * delivered, which is returned by {@link #getHitsCount()}. + * + * @return + */ + public int getTotalHitsCount() + { + return totalHitsCount; } + /** + * Returns the number of hits returned by this search response. This number is affected by various input parameters + * (like count set on request) and filtering, paging, etc. Warning: this number's meaning depends on actual search + * response (for flat response number of actual AIs, for grouped response number of actual groups), and also, might + * be not precise at all (see {@link IteratorSearchResponse}). + * + * @return + */ + public int getReturnedHitsCount() + { + return returnedHitsCount; + } + + /** + * Returns true if hit limit exceeded. + * + * @return + * @deprecated always returns false, since 4.1.0 there is no notion of hit limit + * @see http://jira.codehaus.org/browse/MINDEXER-14 + */ public boolean isHitLimitExceeded() { - return getTotalHits() == LIMIT_EXCEEDED; + return false; + } + + /** + * Frees any resource associated with this response. Should be called as last method on this response, when it's not + * used anymore. + * + * @throws IOException + */ + public void close() + throws IOException + { + // noop } } Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java Thu Mar 31 13:51:12 2011 @@ -49,15 +49,6 @@ import org.apache.maven.index.creator.Ja public class DefaultIteratorResultSet implements IteratorResultSet { - /** - * This is "hard limit", a possible maximum count of hits that Nexus Indexer will _serve_ even if asked for more. - * Thus, it prevents some malicious attacks like forcing Nexus (or underlying IO to it's knees) but asking for huuge - * count of hits. If anyone needs more than 1000 of hits, it should download the index and use Indexer API instead - * to perform searches locally. - */ - // TODO: inspect is this limit actually needed or not. - private static final int HARD_HIT_COUNT_LIMIT = Integer.MAX_VALUE; - private final IteratorSearchRequest searchRequest; private final IndexSearcher indexSearcher; @@ -115,11 +106,11 @@ public class DefaultIteratorResultSet this.hits = hits; - this.from = ( request.getStart() == AbstractSearchRequest.UNDEFINED ? 0 : request.getStart() ); + this.from = request.getStart(); this.count = - ( request.getCount() == AbstractSearchRequest.UNDEFINED ? HARD_HIT_COUNT_LIMIT : Math.min( - request.getCount(), HARD_HIT_COUNT_LIMIT ) ); + ( request.getCount() == AbstractSearchPageableRequest.UNDEFINED ? hits.scoreDocs.length : Math.min( + request.getCount(), hits.scoreDocs.length ) ); this.pointer = from; Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java Thu Mar 31 13:51:12 2011 @@ -60,7 +60,6 @@ public class DefaultNexusIndexer extends AbstractLogEnabled implements NexusIndexer { - @Requirement private Scanner scanner; @@ -437,6 +436,7 @@ public class DefaultNexusIndexer // Query construction // ---------------------------------------------------------------------------- + @Deprecated public Query constructQuery( Field field, String query, SearchType type ) throws IllegalArgumentException { @@ -528,7 +528,7 @@ public class DefaultNexusIndexer try { - ArrayList<ArtifactInfo> ais = new ArrayList<ArtifactInfo>( result.getTotalHits() ); + ArrayList<ArtifactInfo> ais = new ArrayList<ArtifactInfo>( result.getTotalHitsCount() ); for ( ArtifactInfo ai : result ) { Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java Thu Mar 31 13:51:12 2011 @@ -20,8 +20,10 @@ package org.apache.maven.index; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Comparator; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -56,7 +58,8 @@ public class DefaultSearchEngine IndexingContext indexingContext, Query query ) throws IOException { - return searchFlatPaged( new FlatSearchRequest( query, artifactInfoComparator, indexingContext ) ).getResults(); + return searchFlatPaged( new FlatSearchRequest( query, artifactInfoComparator, indexingContext ), + Arrays.asList( indexingContext ), true ).getResults(); } @Deprecated @@ -67,22 +70,6 @@ public class DefaultSearchEngine return searchFlatPaged( new FlatSearchRequest( query, artifactInfoComparator ), indexingContexts ).getResults(); } - public FlatSearchResponse searchFlatPaged( FlatSearchRequest request ) - throws IOException - { - TreeSet<ArtifactInfo> result = new TreeSet<ArtifactInfo>( request.getArtifactInfoComparator() ); - - int totalHits = 0; - - for ( IndexingContext context : request.getContexts() ) - { - totalHits += - searchFlat( request, result, context, request.getQuery(), request.getStart(), request.getCount() ); - } - - return new FlatSearchResponse( request.getQuery(), totalHits, result ); - } - public FlatSearchResponse searchFlatPaged( FlatSearchRequest request, Collection<IndexingContext> indexingContexts ) throws IOException { @@ -102,35 +89,25 @@ public class DefaultSearchEngine { TreeSet<ArtifactInfo> result = new TreeSet<ArtifactInfo>( request.getArtifactInfoComparator() ); - int totalHits = 0; + List<IndexingContext> contexts = getParticipatingContexts( indexingContexts, ignoreContext ); - for ( IndexingContext ctx : indexingContexts ) + try { - if ( ignoreContext || ctx.isSearchable() ) + for ( IndexingContext ctx : contexts ) { - int hitCount = - searchFlat( request, result, ctx, request.getQuery(), request.getStart(), request.getCount() ); - - if ( hitCount == AbstractSearchResponse.LIMIT_EXCEEDED ) - { - totalHits = hitCount; - } - else - { - totalHits += hitCount; - } + ctx.lock(); } - if ( request.isHitLimited() && ( totalHits > request.getResultHitLimit() ) - || totalHits == AbstractSearchResponse.LIMIT_EXCEEDED ) + return new FlatSearchResponse( request.getQuery(), searchFlat( request, result, contexts, + request.getQuery() ), result ); + } + finally + { + for ( IndexingContext ctx : contexts ) { - totalHits = AbstractSearchResponse.LIMIT_EXCEEDED; - result = new TreeSet<ArtifactInfo>( request.getArtifactInfoComparator() ); - break; + ctx.unlock(); } } - - return new FlatSearchResponse( request.getQuery(), totalHits, result ); } public GroupedSearchResponse searchGrouped( GroupedSearchRequest request, @@ -154,45 +131,37 @@ public class DefaultSearchEngine TreeMap<String, ArtifactInfoGroup> result = new TreeMap<String, ArtifactInfoGroup>( request.getGroupKeyComparator() ); - int totalHits = 0; + List<IndexingContext> contexts = getParticipatingContexts( indexingContexts, ignoreContext ); - for ( IndexingContext ctx : indexingContexts ) + try { - if ( ignoreContext || ctx.isSearchable() ) + for ( IndexingContext ctx : contexts ) { - int hitCount = searchGrouped( request, result, request.getGrouping(), ctx, request.getQuery() ); - - if ( hitCount == AbstractSearchResponse.LIMIT_EXCEEDED ) - { - totalHits = hitCount; - } - else - { - totalHits += hitCount; - } + ctx.lock(); } - if ( request.isHitLimited() && ( totalHits > request.getResultHitLimit() ) - || totalHits == AbstractSearchResponse.LIMIT_EXCEEDED ) + return new GroupedSearchResponse( request.getQuery(), searchGrouped( request, result, + request.getGrouping(), contexts, request.getQuery() ), result ); + + } + finally + { + for ( IndexingContext ctx : contexts ) { - totalHits = AbstractSearchResponse.LIMIT_EXCEEDED; - result = new TreeMap<String, ArtifactInfoGroup>( request.getGroupKeyComparator() ); - break; + ctx.unlock(); } } - - return new GroupedSearchResponse( request.getQuery(), totalHits, result ); } - protected int searchFlat( AbstractSearchRequest req, Collection<ArtifactInfo> result, IndexingContext context, - Query query, int from, int aiCount ) + protected int searchFlat( FlatSearchRequest req, Collection<ArtifactInfo> result, + List<IndexingContext> participatingContexts, Query query ) throws IOException { - context.lock(); + int hitCount = 0; - try + for ( IndexingContext context : participatingContexts ) { - TopScoreDocCollector collector = TopScoreDocCollector.create( req.getResultHitLimit(), true ); + TopScoreDocCollector collector = TopScoreDocCollector.create( getTopDocsCollectorHitNum( req ), true ); context.getIndexSearcher().search( query, collector ); @@ -201,14 +170,9 @@ public class DefaultSearchEngine return 0; } - if ( req.isHitLimited() && collector.getTotalHits() > req.getResultHitLimit() ) - { - return AbstractSearchResponse.LIMIT_EXCEEDED; - } - ScoreDoc[] scoreDocs = collector.topDocs().scoreDocs; - int hitCount = scoreDocs.length; + hitCount += collector.getTotalHits(); int start = 0; // from == FlatSearchRequest.UNDEFINED ? 0 : from; @@ -226,45 +190,30 @@ public class DefaultSearchEngine artifactInfo.context = context.getId(); result.add( artifactInfo ); - - if ( req.isHitLimited() && result.size() > req.getResultHitLimit() ) - { - // we hit limit, back out now !! - return AbstractSearchResponse.LIMIT_EXCEEDED; - } } } - - return hitCount; - } - finally - { - context.unlock(); } + + return hitCount; } - protected int searchGrouped( AbstractSearchRequest req, Map<String, ArtifactInfoGroup> result, Grouping grouping, - IndexingContext context, Query query ) + protected int searchGrouped( GroupedSearchRequest req, Map<String, ArtifactInfoGroup> result, Grouping grouping, + List<IndexingContext> participatingContexts, Query query ) throws IOException { - context.lock(); + int hitCount = 0; - try + for ( IndexingContext context : participatingContexts ) { - TopScoreDocCollector collector = TopScoreDocCollector.create( req.getResultHitLimit(), true ); + TopScoreDocCollector collector = TopScoreDocCollector.create( getTopDocsCollectorHitNum( req ), true ); context.getIndexSearcher().search( query, collector ); if ( collector.getTotalHits() > 0 ) { - if ( req.isHitLimited() && collector.getTotalHits() > req.getResultHitLimit() ) - { - return AbstractSearchResponse.LIMIT_EXCEEDED; - } - ScoreDoc[] scoreDocs = collector.topDocs().scoreDocs; - int hitCount = scoreDocs.length; + hitCount += collector.getTotalHits(); for ( int i = 0; i < scoreDocs.length; i++ ) { @@ -285,18 +234,10 @@ public class DefaultSearchEngine } } } - - return hitCount; - } - else - { - return 0; } } - finally - { - context.unlock(); - } + + return hitCount; } // == NG Search @@ -320,63 +261,108 @@ public class DefaultSearchEngine boolean ignoreContext ) throws IOException { - // manage defaults! - if ( request.getStart() < 0 ) - { - request.setStart( IteratorSearchRequest.UNDEFINED ); - } - if ( request.getCount() < 0 ) - { - request.setCount( IteratorSearchRequest.UNDEFINED ); - } - try { - // to not change the API all away, but we need stable ordering here - // filter for those 1st, that take part in here - ArrayList<IndexingContext> contexts = new ArrayList<IndexingContext>( indexingContexts.size() ); + List<IndexingContext> contexts = getParticipatingContexts( indexingContexts, ignoreContext ); + final IndexReader multiReader = getMergedIndexReader( indexingContexts, ignoreContext ); + + IndexSearcher indexSearcher = new NexusIndexSearcher( multiReader ); + + // NEXUS-3482 made us to NOT use reverse ordering (it is a fix I wanted to implement, but user contributed + // patch did come in faster! -- Thanks) + TopScoreDocCollector hits = TopScoreDocCollector.create( getTopDocsCollectorHitNum( request ), true ); + + indexSearcher.search( request.getQuery(), hits ); + + return new IteratorSearchResponse( request.getQuery(), hits.getTotalHits(), new DefaultIteratorResultSet( + request, indexSearcher, contexts, hits.topDocs() ) ); + } + catch ( Throwable e ) + { + // perform cleaup, otherwise DefaultIteratorResultSet will do it for ( IndexingContext ctx : indexingContexts ) { if ( ignoreContext || ctx.isSearchable() ) { - contexts.add( ctx ); - - ctx.lock(); + ctx.unlock(); } } - ArrayList<IndexReader> contextsToSearch = new ArrayList<IndexReader>( contexts.size() ); + if ( e instanceof IOException ) + { + throw (IOException) e; + } + else + { + // wrap it + IOException ex = new IOException( e.getMessage() ); + ex.initCause( e ); + throw ex; + } + } + } + + // == + + /** + * Returns the list of participating contexts. Does not locks them, just builds a list of them. + */ + protected List<IndexingContext> getParticipatingContexts( final Collection<IndexingContext> indexingContexts, + final boolean ignoreContext ) + { + // to not change the API all away, but we need stable ordering here + // filter for those 1st, that take part in here + final ArrayList<IndexingContext> contexts = new ArrayList<IndexingContext>( indexingContexts.size() ); + + for ( IndexingContext ctx : indexingContexts ) + { + if ( ignoreContext || ctx.isSearchable() ) + { + contexts.add( ctx ); + } + } + + return contexts; + } + + /** + * Locks down participating contexts, and returns a "merged" reader of them. In case of error, unlocks as part of + * cleanup and re-throws exception. Without error, it is the duty of caller to unlock contexts! + * + * @param indexingContexts + * @param ignoreContext + * @return + * @throws IOException + */ + protected IndexReader getMergedIndexReader( final Collection<IndexingContext> indexingContexts, + final boolean ignoreContext ) + throws IOException + { + final List<IndexingContext> contexts = getParticipatingContexts( indexingContexts, ignoreContext ); + + try + { + final ArrayList<IndexReader> contextsToSearch = new ArrayList<IndexReader>( contexts.size() ); for ( IndexingContext ctx : contexts ) { + ctx.lock(); + contextsToSearch.add( ctx.getIndexReader() ); } MultiReader multiReader = new MultiReader( contextsToSearch.toArray( new IndexReader[contextsToSearch.size()] ) ); - IndexSearcher indexSearcher = new NexusIndexSearcher( multiReader ); - - // NEXUS-3482 made us to NOT use reverse ordering (it is a fix I wanted to implement, but user contributed - // patch - // did come in faster! -- Thanks) - TopScoreDocCollector hits = TopScoreDocCollector.create( request.getResultHitLimit(), true ); - - indexSearcher.search( request.getQuery(), hits ); - - return new IteratorSearchResponse( request.getQuery(), hits.getTotalHits(), new DefaultIteratorResultSet( - request, indexSearcher, contexts, hits.topDocs() ) ); + return multiReader; } catch ( Throwable e ) { // perform cleaup, otherwise DefaultIteratorResultSet will do it - for ( IndexingContext ctx : indexingContexts ) + for ( IndexingContext ctx : contexts ) { - if ( ignoreContext || ctx.isSearchable() ) - { - ctx.unlock(); - } + ctx.unlock(); } if ( e instanceof IOException ) @@ -392,4 +378,21 @@ public class DefaultSearchEngine } } } + + protected int getTopDocsCollectorHitNum( AbstractSearchRequest request ) + { + if ( request instanceof AbstractSearchPageableRequest ) + { + final AbstractSearchPageableRequest prequest = (AbstractSearchPageableRequest) request; + + if ( AbstractSearchPageableRequest.UNDEFINED != prequest.getCount() ) + { + // easy, user knows how many results he want + return prequest.getCount() + prequest.getStart(); + } + } + + // TODO: ??? + return 10000; + } } Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchRequest.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchRequest.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchRequest.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchRequest.java Thu Mar 31 13:51:12 2011 @@ -30,7 +30,7 @@ import org.apache.maven.index.context.In * @see NexusIndexer#searchFlat(FlatSearchRequest) */ public class FlatSearchRequest - extends AbstractSearchRequest + extends AbstractSearchPageableRequest { private Comparator<ArtifactInfo> artifactInfoComparator; Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchResponse.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchResponse.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchResponse.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/FlatSearchResponse.java Thu Mar 31 13:51:12 2011 @@ -34,7 +34,7 @@ public class FlatSearchResponse public FlatSearchResponse( Query query, int totalHits, Set<ArtifactInfo> results ) { - super( query, totalHits ); + super( query, totalHits, results.size() ); this.results = results; } Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchRequest.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchRequest.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchRequest.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchRequest.java Thu Mar 31 13:51:12 2011 @@ -25,7 +25,8 @@ import org.apache.lucene.search.Query; import org.apache.maven.index.context.IndexingContext; /** - * A grouped search request. + * A grouped search request. This kinds of request is not pageable, since order of incoming hits are not defined, hence + * paging between Document hits makes no sense, would produce unpredictable (and probably not meaningful) results. * * @see NexusIndexer#searchGrouped(GroupedSearchRequest) */ Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchResponse.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchResponse.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchResponse.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/GroupedSearchResponse.java Thu Mar 31 13:51:12 2011 @@ -23,7 +23,7 @@ import java.util.Map; import org.apache.lucene.search.Query; /** - * A grouped search response. + * A grouped search response. For hitsCount, it reports the number of groups found. * * @see NexusIndexer#searchGrouped(GroupedSearchRequest) */ @@ -34,7 +34,7 @@ public class GroupedSearchResponse public GroupedSearchResponse( Query query, int totalHits, Map<String, ArtifactInfoGroup> results ) { - super( query, totalHits ); + super( query, totalHits, results.size() ); this.results = results; } Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchRequest.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchRequest.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchRequest.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchRequest.java Thu Mar 31 13:51:12 2011 @@ -30,7 +30,7 @@ import org.apache.maven.index.context.In * @author cstamas */ public class IteratorSearchRequest - extends AbstractSearchRequest + extends AbstractSearchPageableRequest { public IteratorSearchRequest( Query query ) { Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchResponse.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchResponse.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchResponse.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/IteratorSearchResponse.java Thu Mar 31 13:51:12 2011 @@ -25,8 +25,9 @@ import java.util.Iterator; import org.apache.lucene.search.Query; /** - * A Search Response for the "iterator-like" search request. The totalHits reports _total_ hits found on index, even if - * the set of ArtifactInfos are usually limited! + * A Search Response for the "iterator-like" search request. The totalHitsCount reports <em>total</em> hits found on + * index, even if the set of ArtifactInfos are usually limited! On the flipside, the hitsCount is actually unknown, + * since this instance performs filtering on the fly, hence it does not know how many hits it will return ahead of time. * * @author cstamas */ @@ -38,7 +39,7 @@ public class IteratorSearchResponse public IteratorSearchResponse( Query query, int totalHits, IteratorResultSet results ) { - super( query, totalHits ); + super( query, totalHits, -1 ); this.results = results; } @@ -53,6 +54,7 @@ public class IteratorSearchResponse return getResults(); } + @Override public void close() throws IOException { @@ -104,10 +106,8 @@ public class IteratorSearchResponse } }; - public static final IteratorSearchResponse EMPTY_ITERATOR_SEARCH_RESPONSE = new IteratorSearchResponse( null, 0, - EMPTY_ITERATOR_RESULT_SET ); - - public static final IteratorSearchResponse TOO_MANY_HITS_ITERATOR_SEARCH_RESPONSE = new IteratorSearchResponse( - null, LIMIT_EXCEEDED, EMPTY_ITERATOR_RESULT_SET ); - + public static final IteratorSearchResponse empty( final Query q ) + { + return new IteratorSearchResponse( q, 0, EMPTY_ITERATOR_RESULT_SET ); + } } Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/archetype/NexusArchetypeDataSource.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/archetype/NexusArchetypeDataSource.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/archetype/NexusArchetypeDataSource.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/archetype/NexusArchetypeDataSource.java Thu Mar 31 13:51:12 2011 @@ -32,8 +32,8 @@ import org.apache.maven.index.FlatSearch import org.apache.maven.index.FlatSearchResponse; import org.apache.maven.index.MAVEN; import org.apache.maven.index.NexusIndexer; -import org.apache.maven.index.SearchType; import org.apache.maven.index.context.IndexingContext; +import org.apache.maven.index.expr.SourcedSearchExpression; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -58,7 +58,7 @@ public class NexusArchetypeDataSource { Map<String, String> repositories = getRepositoryMap(); - Query pq = indexer.constructQuery( MAVEN.PACKAGING, "maven-archetype", SearchType.EXACT ); + Query pq = indexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression( "maven-archetype" ) ); FlatSearchRequest searchRequest = new FlatSearchRequest( pq ); Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java (original) +++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java Thu Mar 31 13:51:12 2011 @@ -33,7 +33,7 @@ import org.apache.maven.index.IteratorSe import org.apache.maven.index.IteratorSearchResponse; import org.apache.maven.index.MAVEN; import org.apache.maven.index.NexusIndexer; -import org.apache.maven.index.SearchType; +import org.apache.maven.index.expr.SourcedSearchExpression; import org.apache.maven.index.treeview.TreeNode.Type; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -377,7 +377,7 @@ public class DefaultIndexTreeView result = getArtifactsByG( g, request ); - if ( result.getTotalHits() > 0 ) + if ( result.getTotalHitsCount() > 0 ) { return result; } @@ -399,7 +399,7 @@ public class DefaultIndexTreeView result = getArtifactsByGA( g, a, request ); - if ( result.getTotalHits() > 0 ) + if ( result.getTotalHitsCount() > 0 ) { return result; } @@ -425,7 +425,7 @@ public class DefaultIndexTreeView result = getArtifactsByGAV( g, a, v, request ); - if ( result.getTotalHits() > 0 ) + if ( result.getTotalHitsCount() > 0 ) { return result; } @@ -441,7 +441,7 @@ public class DefaultIndexTreeView } // if we are here, no hits found - return IteratorSearchResponse.EMPTY_ITERATOR_SEARCH_RESPONSE; + return IteratorSearchResponse.empty( result.getQuery() ); } protected IteratorSearchResponse getHintedArtifacts( TreeNode root, TreeViewRequest request ) @@ -465,7 +465,7 @@ public class DefaultIndexTreeView else { // if we are here, no hits found or something horribly went wrong? - return IteratorSearchResponse.EMPTY_ITERATOR_SEARCH_RESPONSE; + return IteratorSearchResponse.empty( null ); } } @@ -497,16 +497,16 @@ public class DefaultIndexTreeView Query versionQ = null; // minimum must have - groupIdQ = getNexusIndexer().constructQuery( MAVEN.GROUP_ID, g, SearchType.EXACT ); + groupIdQ = getNexusIndexer().constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( g ) ); if ( StringUtils.isNotBlank( a ) ) { - artifactIdQ = getNexusIndexer().constructQuery( MAVEN.ARTIFACT_ID, a, SearchType.EXACT ); + artifactIdQ = getNexusIndexer().constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( a ) ); } if ( StringUtils.isNotBlank( v ) ) { - versionQ = getNexusIndexer().constructQuery( MAVEN.VERSION, v, SearchType.EXACT ); + versionQ = getNexusIndexer().constructQuery( MAVEN.VERSION, new SourcedSearchExpression( v ) ); } BooleanQuery q = new BooleanQuery(); Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java?rev=1087297&view=auto ============================================================================== --- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java (added) +++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java Thu Mar 31 13:51:12 2011 @@ -0,0 +1,131 @@ +package org.apache.maven.index; + +import java.io.File; +import java.io.IOException; + +import org.apache.lucene.search.Query; +import org.apache.maven.index.expr.SourcedSearchExpression; +import org.apache.maven.index.search.grouping.GAGrouping; + +public class Mindexer14HitLimitTest + extends AbstractNexusIndexerTest +{ + protected File repo = new File( getBasedir(), "target/repo/mindexer14" ); + + @Override + protected void prepareNexusIndexer( NexusIndexer nexusIndexer ) + throws Exception + { + repo.mkdirs(); + + context = + nexusIndexer.addIndexingContext( "mindexer14", "mindexer14", repo, indexDir, null, null, MIN_CREATORS ); + + nexusIndexer.scan( context, false ); + } + + protected void createDummyAis( final String gid, final String aid, final int count ) + throws IOException + { + int version = 0; + + for ( int i = 0; i < count; i++ ) + { + final ArtifactInfo ai = new ArtifactInfo( "mindexer14", gid, aid, String.valueOf( version++ ), null ); + + final ArtifactContext ac = new ArtifactContext( null, null, null, ai, ai.calculateGav() ); + + nexusIndexer.addArtifactToIndex( ac, context ); + } + + } + + public void testFlatSearchTotalHitsLie1k() + throws Exception + { + createDummyAis( "org.test", "mindexer14", 1010 ); + + Query query = nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.test" ) ); + + FlatSearchRequest request = new FlatSearchRequest( query ); + + FlatSearchResponse response = nexusIndexer.searchFlat( request ); + + assertEquals( 1010, response.getTotalHitsCount() ); + + response.close(); + } + + public void testFlatSearchUnlimited() + throws Exception + { + createDummyAis( "org.test", "mindexer14", 1010 ); + + Query query = nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.test" ) ); + + FlatSearchRequest request = new FlatSearchRequest( query ); + + FlatSearchResponse response = nexusIndexer.searchFlat( request ); + + assertEquals( 1010, response.getTotalHitsCount() ); + assertEquals( 1010, response.getReturnedHitsCount() ); + assertEquals( 1010, response.getResults().size() ); + + response.close(); + } + + public void testFlatSearchLimited() + throws Exception + { + createDummyAis( "org.test", "mindexer14", 1010 ); + + Query query = nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.test" ) ); + + FlatSearchRequest request = new FlatSearchRequest( query ); + request.setCount( 234 ); + + FlatSearchResponse response = nexusIndexer.searchFlat( request ); + + assertEquals( 1010, response.getTotalHitsCount() ); + assertEquals( 234, response.getReturnedHitsCount() ); + assertEquals( 234, response.getResults().size() ); + + response.close(); + } + + public void testGroupedSearchTotalHitsLie1k() + throws Exception + { + createDummyAis( "org.test", "mindexer14", 1010 ); + + Query query = nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.test" ) ); + + GroupedSearchRequest request = new GroupedSearchRequest( query, new GAGrouping() ); + + GroupedSearchResponse response = nexusIndexer.searchGrouped( request ); + + assertEquals( 1010, response.getTotalHitsCount() ); + // in case of GroupedSearch, grouping is the one that defines count + // we have 1010 dummies with same GA, and GA grouping, hence count is 1 just like the map has 1 entry + assertEquals( 1, response.getReturnedHitsCount() ); + assertEquals( 1, response.getResults().size() ); + + response.close(); + } + + public void testIteratorSearchTotalHitsLie1k() + throws Exception + { + createDummyAis( "org.test", "mindexer14", 1010 ); + + Query query = nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.test" ) ); + + IteratorSearchRequest request = new IteratorSearchRequest( query ); + + IteratorSearchResponse response = nexusIndexer.searchIterator( request ); + + assertEquals( 1010, response.getTotalHitsCount() ); + + response.close(); + } +} Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus3177HitLimitChecks.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus3177HitLimitChecks.java?rev=1087297&r1=1087296&r2=1087297&view=diff ============================================================================== --- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus3177HitLimitChecks.java (original) +++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus3177HitLimitChecks.java Thu Mar 31 13:51:12 2011 @@ -25,11 +25,6 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; -import org.apache.maven.index.AbstractSearchResponse; -import org.apache.maven.index.ArtifactInfo; -import org.apache.maven.index.FlatSearchRequest; -import org.apache.maven.index.FlatSearchResponse; -import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexingContext; public class Nexus3177HitLimitChecks @@ -65,19 +60,28 @@ public class Nexus3177HitLimitChecks nexusIndexer.removeIndexingContext( secondContext, false ); } + // =================================================================== + // NOTE: This test, with testing search limits lost it's original meaning, + // since version 4.1.0 there is no notion of hit limit. + // See http://jira.codehaus.org/browse/MINDEXER-14 + + // Hence, some of the tests, that can keep still original semantics were updated and left in place + // but the two test explicitly testing LIMIT_EXCEEDED were just removed/commented out. + public void testHitLimitNotReachedSingleContext() throws Exception { WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) ); FlatSearchRequest request = new FlatSearchRequest( q ); - request.setResultHitLimit( 5 ); + request.setCount( 5 ); + // request.setResultHitLimit( 5 ); request.getContexts().add( context ); FlatSearchResponse response = nexusIndexer.searchFlat( request ); Set<ArtifactInfo> r = response.getResults(); assertEquals( r.toString(), 4, r.size() ); - assertEquals( r.toString(), 4, response.getTotalHits() ); + assertEquals( r.toString(), 4, response.getTotalHitsCount() ); } public void testHitLimitEqualSingleContext() @@ -86,29 +90,31 @@ public class Nexus3177HitLimitChecks WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) ); FlatSearchRequest request = new FlatSearchRequest( q ); - request.setResultHitLimit( 4 ); + request.setCount( 4 ); + // request.setResultHitLimit( 4 ); request.getContexts().add( context ); FlatSearchResponse response = nexusIndexer.searchFlat( request ); Set<ArtifactInfo> r = response.getResults(); assertEquals( r.toString(), 4, r.size() ); - assertEquals( r.toString(), 4, response.getTotalHits() ); + assertEquals( r.toString(), 4, response.getTotalHitsCount() ); } - public void testHitLimitExceededSingleContext() - throws Exception - { - WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) ); - - FlatSearchRequest request = new FlatSearchRequest( q ); - request.setResultHitLimit( 3 ); - request.getContexts().add( context ); - - FlatSearchResponse response = nexusIndexer.searchFlat( request ); - Set<ArtifactInfo> r = response.getResults(); - assertEquals( r.toString(), 0, r.size() ); - assertEquals( r.toString(), AbstractSearchResponse.LIMIT_EXCEEDED, response.getTotalHits() ); - } + // See NOTE above + // public void testHitLimitExceededSingleContext() + // throws Exception + // { + // WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) ); + // + // FlatSearchRequest request = new FlatSearchRequest( q ); + // request.setResultHitLimit( 3 ); + // request.getContexts().add( context ); + // + // FlatSearchResponse response = nexusIndexer.searchFlat( request ); + // Set<ArtifactInfo> r = response.getResults(); + // assertEquals( r.toString(), 0, r.size() ); + // assertEquals( r.toString(), AbstractSearchResponse.LIMIT_EXCEEDED, response.getTotalHits() ); + // } public void testHitLimitNotReachedMultipleContexts() throws Exception @@ -116,7 +122,8 @@ public class Nexus3177HitLimitChecks WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) ); FlatSearchRequest request = new FlatSearchRequest( q ); - request.setResultHitLimit( 9 ); + request.setCount( 9 ); + // request.setResultHitLimit( 9 ); request.setArtifactInfoComparator( ArtifactInfo.REPOSITORY_VERSION_COMPARATOR ); request.getContexts().add( context ); request.getContexts().add( secondContext ); @@ -124,7 +131,7 @@ public class Nexus3177HitLimitChecks FlatSearchResponse response = nexusIndexer.searchFlat( request ); Set<ArtifactInfo> r = response.getResults(); assertEquals( r.toString(), 8, r.size() ); - assertEquals( r.toString(), 8, response.getTotalHits() ); + assertEquals( r.toString(), 8, response.getTotalHitsCount() ); } public void testHitLimitEqualMultipleContexts() @@ -133,7 +140,8 @@ public class Nexus3177HitLimitChecks WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) ); FlatSearchRequest request = new FlatSearchRequest( q ); - request.setResultHitLimit( 8 ); + request.setCount( 8 ); + // request.setResultHitLimit( 8 ); request.setArtifactInfoComparator( ArtifactInfo.REPOSITORY_VERSION_COMPARATOR ); request.getContexts().add( context ); request.getContexts().add( secondContext ); @@ -141,23 +149,24 @@ public class Nexus3177HitLimitChecks FlatSearchResponse response = nexusIndexer.searchFlat( request ); Set<ArtifactInfo> r = response.getResults(); assertEquals( r.toString(), 8, r.size() ); - assertEquals( r.toString(), 8, response.getTotalHits() ); + assertEquals( r.toString(), 8, response.getTotalHitsCount() ); } - public void testHitLimitExceededMultipleContexts() - throws Exception - { - WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) ); - - FlatSearchRequest request = new FlatSearchRequest( q ); - request.setResultHitLimit( 7 ); - request.setArtifactInfoComparator( ArtifactInfo.REPOSITORY_VERSION_COMPARATOR ); - request.getContexts().add( context ); - request.getContexts().add( secondContext ); - - FlatSearchResponse response = nexusIndexer.searchFlat( request ); - Set<ArtifactInfo> r = response.getResults(); - assertEquals( r.toString(), 0, r.size() ); - assertEquals( r.toString(), AbstractSearchResponse.LIMIT_EXCEEDED, response.getTotalHits() ); - } + // See NOTE above + // public void testHitLimitExceededMultipleContexts() + // throws Exception + // { + // WildcardQuery q = new WildcardQuery( new Term( ArtifactInfo.UINFO, "*testng*" ) ); + // + // FlatSearchRequest request = new FlatSearchRequest( q ); + // request.setResultHitLimit( 7 ); + // request.setArtifactInfoComparator( ArtifactInfo.REPOSITORY_VERSION_COMPARATOR ); + // request.getContexts().add( context ); + // request.getContexts().add( secondContext ); + // + // FlatSearchResponse response = nexusIndexer.searchFlat( request ); + // Set<ArtifactInfo> r = response.getResults(); + // assertEquals( r.toString(), 0, r.size() ); + // assertEquals( r.toString(), AbstractSearchResponse.LIMIT_EXCEEDED, response.getTotalHits() ); + // } }