public NexusIndexSearcher( final IndexingContext indexingContext ) throws IOException { this( indexingContext, indexingContext.getIndexReader() ); }
private void initialize( IndexingContext ctx ) throws IOException, CorruptIndexException { IndexReader r = ctx.getIndexReader(); for ( int i = 0; i < r.maxDoc(); i++ ) { if ( !r.isDeleted( i ) ) { Document d = r.document( i ); String uinfo = d.get( ArtifactInfo.UINFO ); if ( uinfo != null ) { uinfos.add( uinfo ); // add all existing groupIds to the lists, as they will // not be "discovered" and would be missing from the new list.. String groupId = uinfo.substring( 0, uinfo.indexOf( '|' ) ); int n = groupId.indexOf( '.' ); groups.add( n == -1 ? groupId : groupId.substring( 0, n ) ); allGroups.add( groupId ); } } } }
IndexReader r = request.getContext().getIndexReader();
public IndexingContext getRepositoryBestIndexContext( String repositoryId ) throws NoSuchRepositoryException { IndexingContext bestContext = getRepositoryLocalIndexContext( repositoryId ); IndexingContext remoteContext = getRepositoryRemoteIndexContext( repositoryId ); if ( remoteContext != null ) { try { // if remote is here and is downloaded, it is the best (it is always the superset of local cache) if ( bestContext.getIndexReader().numDocs() < remoteContext.getIndexReader().numDocs() ) { bestContext = remoteContext; } } catch ( IOException e ) { // silent } } return bestContext; }
public int write( IndexingContext context, List<Integer> docIndexes ) throws IOException { writeHeader( context ); int n = writeDocuments( context.getIndexReader(), docIndexes ); close(); return n; }
/** * Pack legacy index archive into a specified output stream */ public static void packIndexArchive( IndexingContext context, OutputStream os ) throws IOException { File indexArchive = File.createTempFile( "nexus-index", "" ); File indexDir = new File( indexArchive.getAbsoluteFile().getParentFile(), indexArchive.getName() + ".dir" ); indexDir.mkdirs(); FSDirectory fdir = FSDirectory.getDirectory( indexDir ); try { // force the timestamp update IndexUtils.updateTimestamp( context.getIndexDirectory(), context.getTimestamp() ); IndexUtils.updateTimestamp( fdir, context.getTimestamp() ); copyLegacyDocuments( context.getIndexReader(), fdir, context ); packDirectory( fdir, os ); } finally { IndexUtils.close( fdir ); indexArchive.delete(); IndexUtils.delete( indexDir ); } }
/** * Used to rebuild group information, for example on context which were merged, since merge() of contexts * only merges the Documents with UINFO record (Artifacts). */ public static void rebuildGroups( IndexingContext context ) throws IOException { IndexReader r = context.getIndexReader(); Set<String> rootGroups = new LinkedHashSet<String>(); Set<String> allGroups = new LinkedHashSet<String>(); int numDocs = r.maxDoc(); for ( int i = 0; i < numDocs; i++ ) { if ( r.isDeleted( i ) ) { continue; } Document d = r.document( i ); String uinfo = d.get( ArtifactInfo.UINFO ); if ( uinfo != null ) { ArtifactInfo info = IndexUtils.constructArtifactInfo( d, context ); rootGroups.add( info.getRootGroup() ); allGroups.add( info.groupId ); } } setRootGroups( context, rootGroups ); setAllGroups( context, allGroups ); context.optimize(); }
protected DefaultIteratorResultSet( final IteratorSearchRequest request, final IndexSearcher indexSearcher, final List<IndexingContext> contexts, final Hits hits ) throws IOException { this.searchRequest = request; this.indexSearcher = indexSearcher; this.contexts = contexts; { int maxDoc = 0; this.starts = new int[contexts.size() + 1]; // build starts array for ( int i = 0; i < contexts.size(); i++ ) { starts[i] = maxDoc; maxDoc += contexts.get( i ).getIndexReader().maxDoc(); // compute maxDocs } starts[contexts.size()] = maxDoc; } this.filter = request.getArtifactInfoFilter(); this.postprocessor = request.getArtifactInfoPostprocessor(); this.matchHighlightRequests = request.getMatchHighlightRequests(); this.hits = hits; this.from = ( request.getStart() == AbstractSearchRequest.UNDEFINED ? 0 : request.getStart() ); this.count = ( request.getCount() == AbstractSearchRequest.UNDEFINED ? HARD_HIT_COUNT_LIMIT : Math.min( request.getCount(), HARD_HIT_COUNT_LIMIT ) ); this.pointer = from; this.processedArtifactInfoCount = 0; this.maxRecPointer = from + count; ai = createNextAi(); }
contextsToSearch.add( ctx.getIndexReader() );
Query rewrittenQuery = hr.getQuery().rewrite( context.getIndexReader() );
&& topdocs.scoreDocs.length > 0 ) Document doc = context.getIndexReader().document( topdocs.scoreDocs[0].doc );