You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/02/28 11:05:45 UTC

svn commit: r381621 - in /maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing: AbstractRepositoryIndex.java ArtifactRepositoryIndexAnalyzer.java

Author: epunzalan
Date: Tue Feb 28 02:05:43 2006
New Revision: 381621

URL: http://svn.apache.org/viewcvs?rev=381621&view=rev
Log:
Demoted the analyzer into an inner class

Removed:
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexAnalyzer.java
Modified:
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java?rev=381621&r1=381620&r2=381621&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java Tue Feb 28 02:05:43 2006
@@ -18,6 +18,8 @@
 
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.SimpleAnalyzer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.CharTokenizer;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
@@ -25,6 +27,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.Reader;
 import java.util.Collection;
 
 /**
@@ -288,5 +291,72 @@
     public boolean isKeywordField( String field )
     {
         return KEYWORD_FIELDS.contains( field );
+    }
+
+    private class ArtifactRepositoryIndexAnalyzer
+        extends Analyzer
+    {
+        private Analyzer defaultAnalyzer;
+
+        /**
+         * constructor to for this analyzer
+         *
+         * @param defaultAnalyzer the analyzer to use as default for the general fields of the artifact indeces
+         */
+        public ArtifactRepositoryIndexAnalyzer( Analyzer defaultAnalyzer )
+        {
+            this.defaultAnalyzer = defaultAnalyzer;
+        }
+
+        /**
+         * Method called by lucence during indexing operations
+         *
+         * @param fieldName the field name that the lucene object is currently processing
+         * @param reader    a Reader object to the index stream
+         * @return an analyzer to specific to the field name or the default analyzer if none is present
+         */
+        public TokenStream tokenStream( String fieldName, Reader reader )
+        {
+            TokenStream tokenStream;
+
+            if ( RepositoryIndex.FLD_VERSION.equals( fieldName ) || RepositoryIndex.FLD_LASTUPDATE.equals( fieldName ) )
+            {
+                tokenStream = new VersionTokenizer( reader );
+            }
+            else
+            {
+                tokenStream = defaultAnalyzer.tokenStream( fieldName, reader );
+            }
+
+            return tokenStream;
+        }
+
+        /**
+         * Class used to tokenize an artifact's version.
+         */
+        private class VersionTokenizer
+            extends CharTokenizer
+        {
+            /**
+             * Constructor with the required reader to the index stream
+             *
+             * @param reader the Reader object of the index stream
+             */
+            VersionTokenizer( Reader reader )
+            {
+                super( reader );
+            }
+
+            /**
+             * method that lucene calls to check tokenization of a stream character
+             *
+             * @param character char currently being processed
+             * @return true if the char is a token, false if the char is a stop char
+             */
+            protected boolean isTokenChar( char character )
+            {
+                return character != '.' && character != '-';
+            }
+        }
     }
 }