private Document getOldDocument(ArtifactContext ac) throws IOException { final TopDocs result = contextIndexSearcher.search( new TermQuery(new Term(ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo())), 2); if (result.totalHits == 1) { return contextIndexSearcher.doc(result.scoreDocs[0].doc); } return null; } }
@Override public String toString() { final StringBuilder result = new StringBuilder( getUinfo() ); if ( !Strings.isNullOrEmpty( getPackaging() ) ) { result.append( "[" ).append( getPackaging() ).append( "]" ); } return result.toString(); }
@Override public String toString() { final StringBuilder result = new StringBuilder( getUinfo() ); if ( !Strings.isNullOrEmpty( getPackaging() ) ) { result.append( "[" ).append( getPackaging() ).append( "]" ); } return result.toString(); }
@Override public String toString() { final StringBuilder result = new StringBuilder( getUinfo() ); if ( !Strings.isNullOrEmpty( getPackaging() ) ) { result.append( "[" ).append( getPackaging() ).append( "]" ); } return result.toString(); }
private IndexOp remove(final ArtifactContext ac) throws IOException { if (ac != null) { final String uinfo = ac.getArtifactInfo().getUinfo(); // add artifact deletion marker final Document doc = new Document(); doc.add(new Field(ArtifactInfo.DELETED, uinfo, Field.Store.YES, Field.Index.NO)); doc.add(new Field(ArtifactInfo.LAST_MODIFIED, // Long.toString(System.currentTimeMillis()), Field.Store.YES, Field.Index.NO)); IndexWriter w = context.getIndexWriter(); w.addDocument(doc); w.deleteDocuments(new Term(ArtifactInfo.UINFO, uinfo)); return IndexOp.DELETED; } return IndexOp.NOOP; }
public void remove( IndexingContext context, ArtifactContext ac ) throws IOException { if ( ac != null ) { final String uinfo = ac.getArtifactInfo().getUinfo(); // add artifact deletion marker final Document doc = new Document(); doc.add( new Field( ArtifactInfo.DELETED, uinfo, Field.Store.YES, Field.Index.NO ) ); doc.add( new Field( ArtifactInfo.LAST_MODIFIED, // Long.toString( System.currentTimeMillis() ), Field.Store.YES, Field.Index.NO ) ); IndexWriter w = context.getIndexWriter(); w.addDocument( doc ); w.deleteDocuments( new Term( ArtifactInfo.UINFO, uinfo ) ); context.updateTimestamp(); } }
public void remove( IndexingContext context, ArtifactContext ac ) throws IOException { if ( ac != null ) { final String uinfo = ac.getArtifactInfo().getUinfo(); // add artifact deletion marker final Document doc = new Document(); doc.add( new Field( ArtifactInfo.DELETED, uinfo, Field.Store.YES, Field.Index.NO ) ); doc.add( new Field( ArtifactInfo.LAST_MODIFIED, // Long.toString( System.currentTimeMillis() ), Field.Store.YES, Field.Index.NO ) ); IndexWriter w = context.getIndexWriter(); w.addDocument( doc ); w.deleteDocuments( new Term( ArtifactInfo.UINFO, uinfo ) ); context.updateTimestamp(); } }
public void remove( IndexingContext context, ArtifactContext ac ) throws IOException { if ( ac != null ) { final String uinfo = ac.getArtifactInfo().getUinfo(); // add artifact deletion marker final Document doc = new Document(); doc.add( new Field( ArtifactInfo.DELETED, uinfo, Field.Store.YES, Field.Index.NO ) ); doc.add( new Field( ArtifactInfo.LAST_MODIFIED, // Long.toString( System.currentTimeMillis() ), Field.Store.YES, Field.Index.NO ) ); IndexWriter w = context.getIndexWriter(); w.addDocument( doc ); w.deleteDocuments( new Term( ArtifactInfo.UINFO, uinfo ) ); context.updateTimestamp(); } }
private Document getOldDocument( IndexingContext context, ArtifactContext ac ) { try { final IndexSearcher indexSearcher = context.acquireIndexSearcher(); try { TopDocs result = indexSearcher.search( new TermQuery( new Term( ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo() ) ), 2 ); if ( result.totalHits == 1 ) { return indexSearcher.doc( result.scoreDocs[0].doc ); } } finally { context.releaseIndexSearcher( indexSearcher ); } } catch ( IOException e ) { // huh? throw new IllegalStateException( e ); } return null; }
private Document getOldDocument( IndexingContext context, ArtifactContext ac ) { try { final IndexSearcher indexSearcher = context.acquireIndexSearcher(); try { TopDocs result = indexSearcher.search( new TermQuery( new Term( ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo() ) ), 2 ); if ( result.totalHits == 1 ) { return indexSearcher.doc( result.scoreDocs[0].doc ); } } finally { context.releaseIndexSearcher( indexSearcher ); } } catch ( IOException e ) { // huh? throw new IllegalStateException( e ); } return null; }
private Document getOldDocument( IndexingContext context, ArtifactContext ac ) { try { final IndexSearcher indexSearcher = context.acquireIndexSearcher(); try { TopDocs result = indexSearcher.search( new TermQuery( new Term( ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo() ) ), 2 ); if ( result.totalHits == 1 ) { return indexSearcher.doc( result.scoreDocs[0].doc ); } } finally { context.releaseIndexSearcher( indexSearcher ); } } catch ( IOException e ) { // huh? throw new IllegalStateException( e ); } return null; }
public static Document updateDocument( Document doc, IndexingContext context, boolean updateLastModified ) { ArtifactInfo ai = constructArtifactInfo( doc, context ); if ( ai == null ) { return doc; } Document document = new Document(); // unique key document.add( new Field( ArtifactInfo.UINFO, ai.getUinfo(), Field.Store.YES, Field.Index.NOT_ANALYZED ) ); if ( updateLastModified || doc.getField( ArtifactInfo.LAST_MODIFIED ) == null ) { document.add( new Field( ArtifactInfo.LAST_MODIFIED, // Long.toString( System.currentTimeMillis() ), Field.Store.YES, Field.Index.NO ) ); } else { document.add( doc.getField( ArtifactInfo.LAST_MODIFIED ) ); } for ( IndexCreator ic : context.getIndexCreators() ) { ic.updateDocument( ai, document ); } return document; }
public static Document updateDocument( Document doc, IndexingContext context, boolean updateLastModified, ArtifactInfo ai ) { if ( ai == null ) { ai = constructArtifactInfo( doc, context ); if ( ai == null ) { return doc; } } Document document = new Document(); // unique key document.add( new Field( ArtifactInfo.UINFO, ai.getUinfo(), Field.Store.YES, Field.Index.NOT_ANALYZED ) ); if ( updateLastModified || doc.getField( ArtifactInfo.LAST_MODIFIED ) == null ) { document.add( new Field( ArtifactInfo.LAST_MODIFIED, // Long.toString( System.currentTimeMillis() ), Field.Store.YES, Field.Index.NO ) ); } else { document.add( doc.getField( ArtifactInfo.LAST_MODIFIED ) ); } for ( IndexCreator ic : context.getIndexCreators() ) { ic.updateDocument( ai, document ); } return document; }
public static Document updateDocument( Document doc, IndexingContext context, boolean updateLastModified, ArtifactInfo ai ) { if ( ai == null ) { ai = constructArtifactInfo( doc, context ); if ( ai == null ) { return doc; } } Document document = new Document(); // unique key document.add( new Field( ArtifactInfo.UINFO, ai.getUinfo(), Field.Store.YES, Field.Index.NOT_ANALYZED ) ); if ( updateLastModified || doc.getField( ArtifactInfo.LAST_MODIFIED ) == null ) { document.add( new Field( ArtifactInfo.LAST_MODIFIED, // Long.toString( System.currentTimeMillis() ), Field.Store.YES, Field.Index.NO ) ); } else { document.add( doc.getField( ArtifactInfo.LAST_MODIFIED ) ); } for ( IndexCreator ic : context.getIndexCreators() ) { ic.updateDocument( ai, document ); } return document; }
public void addArtifactToIndex( String repository, File artifactFile, String groupId, String artifactId, String version, String extension, String classifier ) throws IOException { ArtifactInfo artifactInfo = new ArtifactInfo( repository, groupId, artifactId, version, classifier, extension ); if ( extension != null ) { artifactInfo.setFieldValue( MAVEN.EXTENSION, extension ); } LOGGER.debug( "Adding artifact: {}; repo: {}; type: {}", new String[]{ artifactInfo.getUinfo(), repository, extension } ); getIndexer().addArtifactsToIndex( asList( new ArtifactContext( null, artifactFile, null, artifactInfo, artifactInfo.calculateGav() ) ), indexingContext ); }
private IndexOp update(final ArtifactContext ac) throws IOException { if (ac != null && ac.getGav() != null) { final Document d = ac.createDocument(context); if (d != null) { final Document old = getOldDocument(ac); if (old == null) { context.getIndexWriter().addDocument(d); return IndexOp.ADDED; } else if (!equals(d, old)) { context.getIndexWriter().updateDocument( new Term(ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo()), d); return IndexOp.UPDATED; } } } return IndexOp.NOOP; }
public Set<ArtifactInfo> search( final String queryText ) throws ParseException, IOException { final Query query = new MultiFieldQueryParser( LUCENE_FIELDS, LUCENE_ANALYZER ).parse( queryText ); LOGGER.debug( "Executing search query: {}; ctx id: {}; idx dir: {}", new String[]{ query.toString(), indexingContext.getId(), indexingContext.getIndexDirectory().toString() } ); final FlatSearchResponse response = getIndexer().searchFlat( new FlatSearchRequest( query, indexingContext ) ); final Set<ArtifactInfo> results = response.getResults(); if ( LOGGER.isDebugEnabled() ) { LOGGER.debug( "Hit count: {}", response.getReturnedHitsCount() ); for ( final ArtifactInfo result : results ) { LOGGER.debug( "Found artifact: {}; uinfo: {}", result.toString(), result.getUinfo() ); } } return results; }
public void update( IndexingContext context, ArtifactContext ac ) throws IOException { if ( ac != null && ac.getGav() != null ) { Document d = ac.createDocument( context ); if ( d != null ) { Document old = getOldDocument( context, ac ); if ( !equals( d, old ) ) { IndexWriter w = context.getIndexWriter(); w.updateDocument( new Term( ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo() ), d ); updateGroups( context, ac ); context.updateTimestamp(); } } } }
public void update( IndexingContext context, ArtifactContext ac ) throws IOException { if ( ac != null && ac.getGav() != null ) { Document d = ac.createDocument( context ); if ( d != null ) { Document old = getOldDocument( context, ac ); if ( !equals( d, old ) ) { IndexWriter w = context.getIndexWriter(); w.updateDocument( new Term( ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo() ), d ); updateGroups( context, ac ); context.updateTimestamp(); } } } }
public void update( IndexingContext context, ArtifactContext ac ) throws IOException { if ( ac != null && ac.getGav() != null ) { Document d = ac.createDocument( context ); if ( d != null ) { Document old = getOldDocument( context, ac ); if ( !equals( d, old ) ) { IndexWriter w = context.getIndexWriter(); w.updateDocument( new Term( ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo() ), d ); updateGroups( context, ac ); context.updateTimestamp(); } } } }