diff options
author | Joakim Erdfelt <joakime@apache.org> | 2007-02-23 19:05:21 +0000 |
---|---|---|
committer | Joakim Erdfelt <joakime@apache.org> | 2007-02-23 19:05:21 +0000 |
commit | dee0d5a300ee0ba0240efc1277428b52cdcec9e0 (patch) | |
tree | 0f4c8d3b8b8b0468deac3c8851380a68bfa1744e /archiva-indexer | |
parent | 2b50a18d22ef8972d241f54c20a131e05a584ac4 (diff) | |
download | archiva-dee0d5a300ee0ba0240efc1277428b52cdcec9e0.tar.gz archiva-dee0d5a300ee0ba0240efc1277428b52cdcec9e0.zip |
Merge from archiva-MRM-239 branch to trunk. r506385:HEAD
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@511053 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-indexer')
3 files changed, 47 insertions, 1 deletions
diff --git a/archiva-indexer/pom.xml b/archiva-indexer/pom.xml index 4f004c5a1..10d2c366e 100644 --- a/archiva-indexer/pom.xml +++ b/archiva-indexer/pom.xml @@ -27,7 +27,7 @@ </parent> <modelVersion>4.0.0</modelVersion> <artifactId>archiva-indexer</artifactId> - <name>Archiva Repository Indexer</name> + <name>Archiva Indexer</name> <dependencies> <dependency> <groupId>org.apache.maven</groupId> diff --git a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryArtifactIndex.java b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryArtifactIndex.java index 9535a6c70..b4bdbd4f7 100644 --- a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryArtifactIndex.java +++ b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/RepositoryArtifactIndex.java @@ -21,6 +21,7 @@ package org.apache.maven.archiva.indexer; import org.apache.maven.archiva.indexer.query.Query; import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory; +import org.apache.maven.artifact.Artifact; import java.util.Collection; import java.util.List; @@ -90,6 +91,17 @@ public interface RepositoryArtifactIndex throws RepositoryIndexException; /** + * Indexes the artifact specified. If the artifact is already in the repository they it is updated. + * This method should use less memory than indexRecords as the records can be created and disposed of on the fly. + * + * @param artifact the artifact to index + * @param factory the artifact to record factory + * @throws RepositoryIndexException if there is a problem indexing the artifacts + */ + void indexArtifact( Artifact artifact, RepositoryIndexRecordFactory factory ) + throws RepositoryIndexException; + + /** * Indexes the artifacts found within the specified list. If the artifacts are already in the * repository they are updated. This method should use less memory than indexRecords as the records can be * created and disposed of on the fly. diff --git a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryArtifactIndex.java b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryArtifactIndex.java index 5b5f68bea..c0a02935d 100644 --- a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryArtifactIndex.java +++ b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneRepositoryArtifactIndex.java @@ -351,6 +351,40 @@ public class LuceneRepositoryArtifactIndex lastUpdatedTime = System.currentTimeMillis(); } } + + public void indexArtifact( Artifact artifact, RepositoryIndexRecordFactory factory ) + throws RepositoryIndexException + { + IndexModifier indexModifier = null; + try + { + indexModifier = new IndexModifier( indexLocation, getAnalyzer(), !exists() ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + if ( record != null ) + { + Term term = new Term( FLD_PK, record.getPrimaryKey() ); + + indexModifier.deleteDocuments( term ); + + Document document = converter.convert( record ); + document.add( new Field( FLD_PK, record.getPrimaryKey(), Field.Store.NO, Field.Index.UN_TOKENIZED ) ); + + indexModifier.addDocument( document ); + } + indexModifier.optimize(); + } + catch ( IOException e ) + { + throw new RepositoryIndexException( "Error updating index: " + e.getMessage(), e ); + } + finally + { + closeQuietly( indexModifier ); + lastUpdatedTime = System.currentTimeMillis(); + } + } public List getAllGroupIds() throws RepositoryIndexException |