maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r426380 [1/2] - in /maven/repository-manager/trunk/maven-repository-indexer/src: main/java/org/apache/maven/repository/indexing/ main/java/org/apache/maven/repository/indexing/lucene/ main/java/org/apache/maven/repository/indexing/record/ s...
Date Fri, 28 Jul 2006 04:34:39 GMT
Author: brett
Date: Thu Jul 27 21:34:37 2006
New Revision: 426380

URL: http://svn.apache.org/viewvc?rev=426380&view=rev
Log:
[MNG-127] add search interface

Added:
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexSearchTest.java   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/
      - copied from r425953, maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0/
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.jar
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.pom   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/
      - copied from r425935, maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0/
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1-jdk14.jar
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.jar
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0-jdk14.jar
Removed:
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0/
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0.jar
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0.pom
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0/
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0.jar
    maven/repository-manager/trunk/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0.pom
Modified:
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java
    maven/repository-manager/trunk/maven-repository-indexer/src/site/apt/design.apt
    maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java
    maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java
    maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java
    maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java Thu Jul 27 21:34:37 2006
@@ -16,6 +16,9 @@
  * limitations under the License.
  */
 
+import org.apache.maven.repository.indexing.query.Query;
+
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -32,8 +35,19 @@
      * @param records the artifacts to index
      * @throws RepositoryIndexException if there is a problem indexing the records
      */
-    void indexRecords( List records )
+    void indexRecords( Collection records )
         throws RepositoryIndexException;
+
+    /**
+     * Search the index based on the search criteria specified. Returns a list of index records.
+     *
+     * @param query The query that contains the search criteria
+     * @return the index records found
+     * @throws RepositoryIndexSearchException if there is a problem searching
+     * @todo should it return "SearchResult" instances that contain the index record and other search data (like score?)
+     */
+    List search( Query query )
+        throws RepositoryIndexSearchException;
 
     /**
      * Check if the index already exists.

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java Thu Jul 27 21:34:37 2006
@@ -19,6 +19,8 @@
 import org.apache.lucene.document.Document;
 import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
 
+import java.text.ParseException;
+
 /**
  * Converts repository records to Lucene documents.
  *
@@ -33,4 +35,13 @@
      * @return the document
      */
     Document convert( RepositoryIndexRecord record );
+
+    /**
+     * Convert a Lucene document to an index record.
+     *
+     * @param document the document
+     * @return the record
+     */
+    RepositoryIndexRecord convert( Document document )
+        throws ParseException;
 }

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java Thu Jul 27 21:34:37 2006
@@ -21,9 +21,13 @@
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.NumberTools;
 import org.apache.maven.repository.indexing.record.MinimalArtifactIndexRecord;
+import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields;
 import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.text.ParseException;
+import java.util.Arrays;
+
 /**
  * Convert the minimal index record to a Lucene document.
  *
@@ -32,37 +36,41 @@
 public class LuceneMinimalIndexRecordConverter
     implements LuceneIndexRecordConverter
 {
-    private static final String FLD_FILENAME = "j";
-
-    private static final String FLD_LAST_MODIFIED = "d";
-
-    private static final String FLD_FILE_SIZE = "s";
-
-    private static final String FLD_MD5 = "m";
-
-    private static final String FLD_CLASSES = "c";
-
     public Document convert( RepositoryIndexRecord record )
     {
-        MinimalArtifactIndexRecord standardIndexRecord = (MinimalArtifactIndexRecord) record;
+        MinimalArtifactIndexRecord rec = (MinimalArtifactIndexRecord) record;
 
         Document document = new Document();
-        addTokenizedField( document, FLD_FILENAME, standardIndexRecord.getFilename() );
-        addUntokenizedField( document, FLD_LAST_MODIFIED, DateTools.timeToString( standardIndexRecord.getLastModified(),
-                                                                                  DateTools.Resolution.SECOND ) );
-        addUntokenizedField( document, FLD_FILE_SIZE, NumberTools.longToString( standardIndexRecord.getSize() ) );
-        addUntokenizedField( document, FLD_MD5, standardIndexRecord.getMd5Checksum() );
-        addTokenizedField( document, FLD_CLASSES,
-                           StringUtils.join( standardIndexRecord.getClasses().iterator(), "\n" ) );
+        addTokenizedField( document, MinimalIndexRecordFields.FILENAME, rec.getFilename() );
+        addUntokenizedField( document, MinimalIndexRecordFields.LAST_MODIFIED,
+                             DateTools.timeToString( rec.getLastModified(), DateTools.Resolution.SECOND ) );
+        addUntokenizedField( document, MinimalIndexRecordFields.FILE_SIZE, NumberTools.longToString( rec.getSize() ) );
+        addUntokenizedField( document, MinimalIndexRecordFields.MD5, rec.getMd5Checksum() );
+        addTokenizedField( document, MinimalIndexRecordFields.CLASSES,
+                           StringUtils.join( rec.getClasses().iterator(), "\n" ) );
 
         return document;
     }
 
+    public RepositoryIndexRecord convert( Document document )
+        throws ParseException
+    {
+        MinimalArtifactIndexRecord record = new MinimalArtifactIndexRecord();
+
+        record.setFilename( document.get( MinimalIndexRecordFields.FILENAME ) );
+        record.setLastModified( DateTools.stringToTime( document.get( MinimalIndexRecordFields.LAST_MODIFIED ) ) );
+        record.setSize( NumberTools.stringToLong( document.get( MinimalIndexRecordFields.FILE_SIZE ) ) );
+        record.setMd5Checksum( document.get( MinimalIndexRecordFields.MD5 ) );
+        record.setClasses( Arrays.asList( document.get( MinimalIndexRecordFields.CLASSES ).split( "\n" ) ) );
+
+        return record;
+    }
+
     private static void addUntokenizedField( Document document, String name, String value )
     {
         if ( value != null )
         {
-            document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) );
+            document.add( new Field( name, value, Field.Store.YES, Field.Index.UN_TOKENIZED ) );
         }
     }
 

Added: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java?rev=426380&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java Thu Jul 27 21:34:37 2006
@@ -0,0 +1,40 @@
+package org.apache.maven.repository.indexing.lucene;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.repository.indexing.query.Query;
+
+/**
+ * TODO [!]: Description.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class LuceneQuery
+    implements Query
+{
+    private final org.apache.lucene.search.Query query;
+
+    public LuceneQuery( org.apache.lucene.search.Query query )
+    {
+        this.query = query;
+    }
+
+    org.apache.lucene.search.Query getLuceneQuery()
+    {
+        return query;
+    }
+}

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java Thu Jul 27 21:34:37 2006
@@ -23,13 +23,19 @@
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
 import org.apache.maven.repository.indexing.RepositoryIndexException;
+import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
+import org.apache.maven.repository.indexing.query.Query;
 import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
 
 import java.io.File;
 import java.io.IOException;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
@@ -53,14 +59,13 @@
 
     private static final String FLD_PK = "pk";
 
-    public LuceneRepositoryArtifactIndex( File indexPath, ArtifactRepository repository,
-                                          LuceneIndexRecordConverter converter )
+    public LuceneRepositoryArtifactIndex( File indexPath, LuceneIndexRecordConverter converter )
     {
         this.indexLocation = indexPath;
         this.converter = converter;
     }
 
-    public void indexRecords( List records )
+    public void indexRecords( Collection records )
         throws RepositoryIndexException
     {
         try
@@ -75,7 +80,7 @@
         addRecords( records );
     }
 
-    private void addRecords( List records )
+    private void addRecords( Collection records )
         throws RepositoryIndexException
     {
         IndexWriter indexWriter;
@@ -136,7 +141,7 @@
         return new StandardAnalyzer();
     }
 
-    private void deleteRecords( List records )
+    private void deleteRecords( Collection records )
         throws IOException, RepositoryIndexException
     {
         if ( exists() )
@@ -193,6 +198,65 @@
         else
         {
             throw new RepositoryIndexException( indexLocation + " is not a directory." );
+        }
+    }
+
+    public List search( Query query )
+        throws RepositoryIndexSearchException
+    {
+        LuceneQuery lQuery = (LuceneQuery) query;
+
+        org.apache.lucene.search.Query luceneQuery = lQuery.getLuceneQuery();
+
+        IndexSearcher searcher;
+        try
+        {
+            searcher = new IndexSearcher( indexLocation.getAbsolutePath() );
+        }
+        catch ( IOException e )
+        {
+            throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e );
+        }
+
+        List records = new ArrayList();
+        try
+        {
+            Hits hits = searcher.search( luceneQuery );
+            for ( int i = 0; i < hits.length(); i++ )
+            {
+                Document doc = hits.doc( i );
+
+                records.add( converter.convert( doc ) );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );
+        }
+        catch ( ParseException e )
+        {
+            throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e );
+        }
+        finally
+        {
+            closeQuietly( searcher );
+        }
+
+        return records;
+    }
+
+    private static void closeQuietly( IndexSearcher searcher )
+    {
+        try
+        {
+            if ( searcher != null )
+            {
+                searcher.close();
+            }
+        }
+        catch ( IOException e )
+        {
+            // ignore
         }
     }
 }

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java Thu Jul 27 21:34:37 2006
@@ -33,11 +33,11 @@
 {
     public RepositoryArtifactIndex createStandardIndex( File indexPath, ArtifactRepository repository )
     {
-        return new LuceneRepositoryArtifactIndex( indexPath, repository, new LuceneStandardIndexRecordConverter() );
+        return new LuceneRepositoryArtifactIndex( indexPath, new LuceneStandardIndexRecordConverter() );
     }
 
     public RepositoryArtifactIndex createMinimalIndex( File indexPath, ArtifactRepository repository )
     {
-        return new LuceneRepositoryArtifactIndex( indexPath, repository, new LuceneMinimalIndexRecordConverter() );
+        return new LuceneRepositoryArtifactIndex( indexPath, new LuceneMinimalIndexRecordConverter() );
     }
 }

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java Thu Jul 27 21:34:37 2006
@@ -22,100 +22,116 @@
 import org.apache.lucene.document.NumberTools;
 import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
 import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord;
+import org.apache.maven.repository.indexing.record.StandardIndexRecordFields;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.text.ParseException;
+import java.util.Arrays;
+
 /**
  * Convert the standard index record to a Lucene document.
  *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @todo use enum for field names
  */
 public class LuceneStandardIndexRecordConverter
     implements LuceneIndexRecordConverter
 {
-    private static final String FLD_FILENAME = "filename";
-
-    private static final String FLD_GROUPID = "groupId";
-
-    private static final String FLD_ARTIFACTID = "artifactId";
-
-    private static final String FLD_VERSION = "version";
-
-    private static final String FLD_TYPE = "type";
-
-    private static final String FLD_CLASSIFIER = "classifier";
-
-    private static final String FLD_PACKAGING = "packaging";
-
-    private static final String FLD_REPOSITORY = "repo";
-
-    private static final String FLD_LAST_MODIFIED = "lastModified";
-
-    private static final String FLD_FILE_SIZE = "fileSize";
-
-    private static final String FLD_MD5 = "md5";
-
-    private static final String FLD_SHA1 = "sha1";
-
-    private static final String FLD_CLASSES = "classes";
-
-    private static final String FLD_PLUGINPREFIX = "pluginPrefix";
-
-    private static final String FLD_FILES = "files";
-
-    private static final String FLD_INCEPTION_YEAR = "inceptionYear";
-
-    private static final String FLD_PROJECT_NAME = "projectName";
-
-    private static final String FLD_PROJECT_DESCRIPTION = "projectDesc";
-
     public Document convert( RepositoryIndexRecord record )
     {
-        StandardArtifactIndexRecord standardIndexRecord = (StandardArtifactIndexRecord) record;
+        StandardArtifactIndexRecord rec = (StandardArtifactIndexRecord) record;
 
         Document document = new Document();
-        addTokenizedField( document, FLD_FILENAME, standardIndexRecord.getFilename() );
-        addTokenizedField( document, FLD_GROUPID, standardIndexRecord.getGroupId() );
-        addTokenizedField( document, FLD_ARTIFACTID, standardIndexRecord.getArtifactId() );
-        addTokenizedField( document, FLD_VERSION, standardIndexRecord.getVersion() );
-        addUntokenizedField( document, FLD_TYPE, standardIndexRecord.getType() );
-        addTokenizedField( document, FLD_CLASSIFIER, standardIndexRecord.getClassifier() );
-        addUntokenizedField( document, FLD_PACKAGING, standardIndexRecord.getPackaging() );
-        addTokenizedField( document, FLD_REPOSITORY, standardIndexRecord.getRepository() );
-        addUntokenizedField( document, FLD_LAST_MODIFIED, DateTools.timeToString( standardIndexRecord.getLastModified(),
-                                                                                  DateTools.Resolution.SECOND ) );
-        addUntokenizedField( document, FLD_FILE_SIZE, NumberTools.longToString( standardIndexRecord.getSize() ) );
-        addUntokenizedField( document, FLD_MD5, standardIndexRecord.getMd5Checksum() );
-        addUntokenizedField( document, FLD_SHA1, standardIndexRecord.getSha1Checksum() );
-        if ( standardIndexRecord.getClasses() != null )
+        addTokenizedField( document, StandardIndexRecordFields.FILENAME, rec.getFilename() );
+        addTokenizedField( document, StandardIndexRecordFields.GROUPID, rec.getGroupId() );
+        addExactField( document, StandardIndexRecordFields.GROUPID_EXACT, rec.getGroupId() );
+        addTokenizedField( document, StandardIndexRecordFields.ARTIFACTID, rec.getArtifactId() );
+        addExactField( document, StandardIndexRecordFields.ARTIFACTID_EXACT, rec.getArtifactId() );
+        addTokenizedField( document, StandardIndexRecordFields.VERSION, rec.getVersion() );
+        addExactField( document, StandardIndexRecordFields.VERSION_EXACT, rec.getVersion() );
+        addTokenizedField( document, StandardIndexRecordFields.BASE_VERSION, rec.getBaseVersion() );
+        addExactField( document, StandardIndexRecordFields.BASE_VERSION_EXACT, rec.getBaseVersion() );
+        addUntokenizedField( document, StandardIndexRecordFields.TYPE, rec.getType() );
+        addTokenizedField( document, StandardIndexRecordFields.CLASSIFIER, rec.getClassifier() );
+        addUntokenizedField( document, StandardIndexRecordFields.PACKAGING, rec.getPackaging() );
+        addUntokenizedField( document, StandardIndexRecordFields.REPOSITORY, rec.getRepository() );
+        addUntokenizedField( document, StandardIndexRecordFields.LAST_MODIFIED,
+                             DateTools.timeToString( rec.getLastModified(), DateTools.Resolution.SECOND ) );
+        addUntokenizedField( document, StandardIndexRecordFields.FILE_SIZE, NumberTools.longToString( rec.getSize() ) );
+        addUntokenizedField( document, StandardIndexRecordFields.MD5, rec.getMd5Checksum() );
+        addUntokenizedField( document, StandardIndexRecordFields.SHA1, rec.getSha1Checksum() );
+        if ( rec.getClasses() != null )
         {
-            addTokenizedField( document, FLD_CLASSES,
-                               StringUtils.join( standardIndexRecord.getClasses().iterator(), "\n" ) );
+            addTokenizedField( document, StandardIndexRecordFields.CLASSES,
+                               StringUtils.join( rec.getClasses().iterator(), "\n" ) );
         }
-        if ( standardIndexRecord.getFiles() != null )
+        if ( rec.getFiles() != null )
         {
-            addTokenizedField( document, FLD_FILES,
-                               StringUtils.join( standardIndexRecord.getFiles().iterator(), "\n" ) );
+            addTokenizedField( document, StandardIndexRecordFields.FILES,
+                               StringUtils.join( rec.getFiles().iterator(), "\n" ) );
         }
-        addTokenizedField( document, FLD_PLUGINPREFIX, standardIndexRecord.getPluginPrefix() );
-        addUntokenizedField( document, FLD_INCEPTION_YEAR, standardIndexRecord.getInceptionYear() );
-        addTokenizedField( document, FLD_PROJECT_NAME, standardIndexRecord.getProjectName() );
-        addTokenizedField( document, FLD_PROJECT_DESCRIPTION, standardIndexRecord.getProjectDescription() );
+        addUntokenizedField( document, StandardIndexRecordFields.PLUGIN_PREFIX, rec.getPluginPrefix() );
+        addUntokenizedField( document, StandardIndexRecordFields.INCEPTION_YEAR, rec.getInceptionYear() );
+        addTokenizedField( document, StandardIndexRecordFields.PROJECT_NAME, rec.getProjectName() );
+        addTokenizedField( document, StandardIndexRecordFields.PROJECT_DESCRIPTION, rec.getProjectDescription() );
 /* TODO: add later
-        document.add( Field.Keyword( FLD_LICENSE_URLS, "" ) );
-        document.add( Field.Keyword( FLD_DEPENDENCIES, "" ) );
-        document.add( Field.Keyword( FLD_PLUGINS_REPORT, "" ) );
-        document.add( Field.Keyword( FLD_PLUGINS_BUILD, "" ) );
+        document.add( Field.Keyword( StandardIndexRecordFields.FLD_LICENSE_URLS, "" ) );
+        document.add( Field.Keyword( StandardIndexRecordFields.FLD_DEPENDENCIES, "" ) );
+        document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_REPORT, "" ) );
+        document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_BUILD, "" ) );
 */
 
         return document;
     }
 
+    public RepositoryIndexRecord convert( Document document )
+        throws ParseException
+    {
+        StandardArtifactIndexRecord record = new StandardArtifactIndexRecord();
+
+        record.setFilename( document.get( StandardIndexRecordFields.FILENAME ) );
+        record.setGroupId( document.get( StandardIndexRecordFields.GROUPID ) );
+        record.setArtifactId( document.get( StandardIndexRecordFields.ARTIFACTID ) );
+        record.setVersion( document.get( StandardIndexRecordFields.VERSION ) );
+        record.setBaseVersion( document.get( StandardIndexRecordFields.BASE_VERSION ) );
+        record.setType( document.get( StandardIndexRecordFields.TYPE ) );
+        record.setClassifier( document.get( StandardIndexRecordFields.CLASSIFIER ) );
+        record.setPackaging( document.get( StandardIndexRecordFields.PACKAGING ) );
+        record.setRepository( document.get( StandardIndexRecordFields.REPOSITORY ) );
+        record.setLastModified( DateTools.stringToTime( document.get( StandardIndexRecordFields.LAST_MODIFIED ) ) );
+        record.setSize( NumberTools.stringToLong( document.get( StandardIndexRecordFields.FILE_SIZE ) ) );
+        record.setMd5Checksum( document.get( StandardIndexRecordFields.MD5 ) );
+        record.setSha1Checksum( document.get( StandardIndexRecordFields.SHA1 ) );
+        String classes = document.get( StandardIndexRecordFields.CLASSES );
+        if ( classes != null )
+        {
+            record.setClasses( Arrays.asList( classes.split( "\n" ) ) );
+        }
+        String files = document.get( StandardIndexRecordFields.FILES );
+        if ( files != null )
+        {
+            record.setFiles( Arrays.asList( files.split( "\n" ) ) );
+        }
+        record.setPluginPrefix( document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) );
+        record.setInceptionYear( document.get( StandardIndexRecordFields.INCEPTION_YEAR ) );
+        record.setProjectName( document.get( StandardIndexRecordFields.PROJECT_NAME ) );
+        record.setProjectDescription( document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) );
+
+        return record;
+    }
+
     private static void addUntokenizedField( Document document, String name, String value )
     {
         if ( value != null )
         {
-            document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) );
+            document.add( new Field( name, value, Field.Store.YES, Field.Index.UN_TOKENIZED ) );
+        }
+    }
+
+    private static void addExactField( Document document, String name, String value )
+    {
+        if ( value != null )
+        {
+            document.add( new Field( name, value, Field.Store.NO, Field.Index.UN_TOKENIZED ) );
         }
     }
 

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java Thu Jul 27 21:34:37 2006
@@ -43,7 +43,7 @@
     private String filename;
 
     /**
-     * The timestamp that the artifact file was last modified.
+     * The timestamp that the artifact file was last modified. Granularity is seconds.
      */
     private long lastModified;
 
@@ -52,6 +52,8 @@
      */
     private long size;
 
+    private static final int MS_PER_SEC = 1000;
+
     public void setClasses( List classes )
     {
         this.classes = classes;
@@ -69,7 +71,7 @@
 
     public void setLastModified( long lastModified )
     {
-        this.lastModified = lastModified;
+        this.lastModified = lastModified - lastModified % MS_PER_SEC;
     }
 
     public void setSize( long size )

Added: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java?rev=426380&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java Thu Jul 27 21:34:37 2006
@@ -0,0 +1,41 @@
+package org.apache.maven.repository.indexing.record;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * The fields in a minimal artifact index record.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @todo should be an enum
+ */
+public class MinimalIndexRecordFields
+{
+    public static final String FILENAME = "j";
+
+    public static final String LAST_MODIFIED = "d";
+
+    public static final String FILE_SIZE = "s";
+
+    public static final String MD5 = "m";
+
+    public static final String CLASSES = "c";
+
+    private MinimalIndexRecordFields()
+    {
+        // No touchy!
+    }
+}

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java Thu Jul 27 21:34:37 2006
@@ -91,6 +91,11 @@
      */
     private String projectName;
 
+    /**
+     * The base version (before the snapshot is determined).
+     */
+    private String baseVersion;
+
     public void setSha1Checksum( String sha1Checksum )
     {
         this.sha1Checksum = sha1Checksum;
@@ -183,6 +188,10 @@
         {
             return false;
         }
+        if ( !baseVersion.equals( that.baseVersion ) )
+        {
+            return false;
+        }
         if ( packaging != null ? !packaging.equals( that.packaging ) : that.packaging != null )
         {
             return false;
@@ -215,6 +224,7 @@
         result = 31 * result + groupId.hashCode();
         result = 31 * result + artifactId.hashCode();
         result = 31 * result + version.hashCode();
+        result = 31 * result + baseVersion.hashCode();
         result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 );
         result = 31 * result + ( type != null ? type.hashCode() : 0 );
         result = 31 * result + ( files != null ? files.hashCode() : 0 );
@@ -315,5 +325,15 @@
     public String getProjectName()
     {
         return projectName;
+    }
+
+    public void setBaseVersion( String baseVersion )
+    {
+        this.baseVersion = baseVersion;
+    }
+
+    public String getBaseVersion()
+    {
+        return baseVersion;
     }
 }

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java Thu Jul 27 21:34:37 2006
@@ -88,9 +88,13 @@
             String sha1 = readChecksum( file, Digester.SHA1 );
 
             List files = null;
+            boolean archive = ARCHIVE_TYPES.contains( artifact.getType() );
             try
             {
-                files = readFilesInArchive( file );
+                if ( archive )
+                {
+                    files = readFilesInArchive( file );
+                }
             }
             catch ( IOException e )
             {
@@ -98,12 +102,13 @@
             }
 
             // If it's an archive with no files, don't create a record
-            if ( !ARCHIVE_TYPES.contains( artifact.getType() ) || files != null )
+            if ( !archive || files != null )
             {
                 record = new StandardArtifactIndexRecord();
 
                 record.setGroupId( artifact.getGroupId() );
                 record.setArtifactId( artifact.getArtifactId() );
+                record.setBaseVersion( artifact.getBaseVersion() );
                 record.setVersion( artifact.getVersion() );
                 record.setClassifier( artifact.getClassifier() );
                 record.setType( artifact.getType() );
@@ -123,6 +128,7 @@
                     Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(),
                                                                                   artifact.getArtifactId(),
                                                                                   artifact.getVersion() );
+                    pomArtifact.isSnapshot(); // gross hack around bug in maven-artifact
                     File pomFile = new File( artifact.getRepository().getBasedir(),
                                              artifact.getRepository().pathOf( pomArtifact ) );
                     if ( pomFile.exists() )

Added: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java?rev=426380&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java Thu Jul 27 21:34:37 2006
@@ -0,0 +1,77 @@
+package org.apache.maven.repository.indexing.record;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * The fields in a minimal artifact index record.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @todo should be an enum
+ */
+public class StandardIndexRecordFields
+{
+    public static final String FILENAME = "filename";
+
+    public static final String GROUPID = "groupId";
+
+    public static final String GROUPID_EXACT = GROUPID + "_u";
+
+    public static final String ARTIFACTID = "artifactId";
+
+    public static final String ARTIFACTID_EXACT = ARTIFACTID + "_u";
+
+    public static final String VERSION = "version";
+
+    public static final String VERSION_EXACT = VERSION + "_u";
+
+    public static final String BASE_VERSION = "baseVersion";
+
+    public static final String BASE_VERSION_EXACT = BASE_VERSION + "_u";
+
+    public static final String TYPE = "type";
+
+    public static final String CLASSIFIER = "classifier";
+
+    public static final String PACKAGING = "packaging";
+
+    public static final String REPOSITORY = "repo";
+
+    public static final String LAST_MODIFIED = "lastModified";
+
+    public static final String FILE_SIZE = "fileSize";
+
+    public static final String MD5 = "md5";
+
+    public static final String SHA1 = "sha1";
+
+    public static final String CLASSES = "classes";
+
+    public static final String PLUGIN_PREFIX = "pluginPrefix";
+
+    public static final String FILES = "files";
+
+    public static final String INCEPTION_YEAR = "inceptionYear";
+
+    public static final String PROJECT_NAME = "projectName";
+
+    public static final String PROJECT_DESCRIPTION = "projectDesc";
+
+    private StandardIndexRecordFields()
+    {
+        // No touchy!
+    }
+}

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/site/apt/design.apt
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/site/apt/design.apt?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/site/apt/design.apt (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/site/apt/design.apt Thu Jul 27 21:34:37 2006
@@ -105,6 +105,8 @@
 
     * <<<m>>>: md5 checksum of the JAR
 
+    * <<<pk>>>: the primary key of the artifact
+
   Only JARs are indexed at present. The JAR filename is used as the key for later deleting entries.
 
 * Searching
@@ -128,3 +130,7 @@
   reasons. It should not have to read any metadata files or properties of files such as size and checksum from the disk.
   This enables searching a repository remotely without having the physical repository available, which is useful for
   IDE integration among other things.
+
+  Note that to be able to do an exact match search, a field must be stored untokenized. For fields where it makes sense
+  to search both tokenized and untokenized, they will be stored twice. This currently includes: artifact ID, group ID,
+  and version.

Added: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java?rev=426380&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java Thu Jul 27 21:34:37 2006
@@ -0,0 +1,218 @@
+package org.apache.maven.repository.indexing.lucene;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
+import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
+import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields;
+import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Test the Lucene implementation of the artifact index search.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @todo would be nice to abstract some of the query away, but for now passing in a Lucene query directly is good enough
+ */
+public class LuceneMinimalArtifactIndexSearchTest
+    extends PlexusTestCase
+{
+    private RepositoryArtifactIndex index;
+
+    private ArtifactRepository repository;
+
+    private ArtifactFactory artifactFactory;
+
+    private File indexLocation;
+
+    private RepositoryIndexRecordFactory recordFactory;
+
+    private Map records = new HashMap();
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "minimal" );
+
+        artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+
+        ArtifactRepositoryFactory repositoryFactory =
+            (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+
+        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
+
+        File file = getTestFile( "src/test/managed-repository" );
+        repository =
+            repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null );
+
+        RepositoryArtifactIndexFactory factory =
+            (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" );
+
+        indexLocation = getTestFile( "target/test-index" );
+
+        FileUtils.deleteDirectory( indexLocation );
+
+        index = factory.createMinimalIndex( indexLocation, repository );
+
+        records.put( "test-jar", recordFactory.createRecord( createArtifact( "test-jar" ) ) );
+        records.put( "test-jar-jdk14",
+                     recordFactory.createRecord( createArtifact( "test-jar", "1.0", "jar", "jdk14" ) ) );
+        records.put( "test-jar-and-pom",
+                     recordFactory.createRecord( createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ) ) );
+        records.put( "test-jar-and-pom-jdk14", recordFactory.createRecord(
+            createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ) ) );
+        records.put( "test-child-pom",
+                     recordFactory.createRecord( createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" ) ) );
+        records.put( "test-archetype", recordFactory.createRecord( createArtifact( "test-archetype" ) ) );
+        records.put( "test-plugin", recordFactory.createRecord( createArtifact( "test-plugin" ) ) );
+        records.put( "test-pom", recordFactory.createRecord( createArtifact( "test-pom", "1.0", "pom" ) ) );
+        records.put( "parent-pom", recordFactory.createRecord( createArtifact( "parent-pom", "1", "pom" ) ) );
+        records.put( "test-dll", recordFactory.createRecord( createArtifact( "test-dll", "1.0.1.34", "dll" ) ) );
+
+        index.indexRecords( records.values() );
+    }
+
+    public void testExactMatchMd5()
+        throws RepositoryIndexSearchException
+    {
+        Query query = new TermQuery( new Term( MinimalIndexRecordFields.MD5, "3a0adc365f849366cd8b633cad155cb7" ) );
+        List results = index.search( new LuceneQuery( query ) );
+
+        assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
+        assertEquals( "Check results size", 5, results.size() );
+
+        // test non-match fails
+        query = new TermQuery( new Term( MinimalIndexRecordFields.MD5, "foo" ) );
+        results = index.search( new LuceneQuery( query ) );
+
+        assertTrue( "Check results size", results.isEmpty() );
+    }
+
+    public void testMatchFilename()
+        throws RepositoryIndexSearchException
+    {
+        Query query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "maven" ) );
+        List results = index.search( new LuceneQuery( query ) );
+
+        assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) );
+        assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) );
+        assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) );
+        assertEquals( "Check results size", 7, results.size() );
+
+/* TODO: if this is a result we want, we need to change the analyzer. Currently, it is tokenizing it as plugin-1.0 and plugin/1.0 in the path
+        query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "plugin" ) );
+        results = index.search( new LuceneQuery( query ) );
+
+        assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
+        assertEquals( "Check results size", 1, results.size() );
+*/
+        query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "test" ) );
+        results = index.search( new LuceneQuery( query ) );
+
+        assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) );
+        assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) );
+        assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) );
+        assertEquals( "Check results size", 7, results.size() );
+
+        // test non-match fails
+        query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "foo" ) );
+        results = index.search( new LuceneQuery( query ) );
+
+        assertTrue( "Check results size", results.isEmpty() );
+    }
+
+    public void testMatchClass()
+        throws RepositoryIndexSearchException
+    {
+        // TODO: should be preserving case!
+        Query query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "b.c.c" ) );
+        List results = index.search( new LuceneQuery( query ) );
+
+        assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
+        assertEquals( "Check results size", 5, results.size() );
+
+/* TODO!: need to change the analyzer if we want partial classes (split on '.')
+        query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "C" ) );
+        results = index.search( new LuceneQuery( query ) );
+
+        assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) );
+        assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) );
+        assertEquals( "Check results size", 4, results.size() );
+
+        query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "MyMojo" ) );
+        results = index.search( new LuceneQuery( query ) );
+
+        assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) );
+        assertEquals( "Check results size", 1, results.size() );
+*/
+
+        // test non-match fails
+        query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "foo" ) );
+        results = index.search( new LuceneQuery( query ) );
+
+        assertTrue( "Check results size", results.isEmpty() );
+    }
+
+    private Artifact createArtifact( String artifactId )
+    {
+        return createArtifact( artifactId, "1.0", "jar", null );
+    }
+
+    private Artifact createArtifact( String artifactId, String version, String type )
+    {
+        return createArtifact( artifactId, version, type, null );
+    }
+
+    private Artifact createArtifact( String artifactId, String version, String type, String classifier )
+    {
+        Artifact artifact = artifactFactory.createDependencyArtifact( "org.apache.maven.repository.record", artifactId,
+                                                                      VersionRange.createFromVersion( version ), type,
+                                                                      classifier, Artifact.SCOPE_RUNTIME );
+        artifact.isSnapshot();
+        artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
+        artifact.setRepository( repository );
+        return artifact;
+    }
+}

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java
URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java?rev=426380&r1=426379&r2=426380&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java Thu Jul 27 21:34:37 2006
@@ -29,6 +29,7 @@
 import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
 import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
 import org.apache.maven.repository.indexing.RepositoryIndexException;
+import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields;
 import org.apache.maven.repository.indexing.record.RepositoryIndexRecord;
 import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
 import org.codehaus.plexus.PlexusTestCase;
@@ -134,7 +135,8 @@
         try
         {
             Document document = reader.document( 0 );
-            assertEquals( "Check document", repository.pathOf( artifact ), document.get( "j" ) );
+            assertEquals( "Check document", repository.pathOf( artifact ),
+                          document.get( MinimalIndexRecordFields.FILENAME ) );
             assertEquals( "Check index size", 1, reader.numDocs() );
         }
         finally
@@ -274,12 +276,14 @@
 
     private void assertRecord( Document document, Artifact artifact, String expectedChecksum, String expectedClasses )
     {
-        assertEquals( "Check document filename", repository.pathOf( artifact ), document.get( "j" ) );
-        assertEquals( "Check document timestamp", getLastModified( artifact.getFile() ), document.get( "d" ) );
-        assertEquals( "Check document checksum", expectedChecksum, document.get( "m" ) );
+        assertEquals( "Check document filename", repository.pathOf( artifact ),
+                      document.get( MinimalIndexRecordFields.FILENAME ) );
+        assertEquals( "Check document timestamp", getLastModified( artifact.getFile() ),
+                      document.get( MinimalIndexRecordFields.LAST_MODIFIED ) );
+        assertEquals( "Check document checksum", expectedChecksum, document.get( MinimalIndexRecordFields.MD5 ) );
         assertEquals( "Check document size", artifact.getFile().length(),
-                      NumberTools.stringToLong( document.get( "s" ) ) );
-        assertEquals( "Check document classes", expectedClasses, document.get( "c" ) );
+                      NumberTools.stringToLong( document.get( MinimalIndexRecordFields.FILE_SIZE ) ) );
+        assertEquals( "Check document classes", expectedClasses, document.get( MinimalIndexRecordFields.CLASSES ) );
     }
 
     private String getLastModified( File file )



Mime
View raw message