1 package org.apache.maven.repository.indexing;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.lucene.analysis.Analyzer;
20 import org.apache.lucene.analysis.CharTokenizer;
21 import org.apache.lucene.analysis.TokenStream;
23 import java.io.Reader;
26 * Class created specifically to index artifacts
28 * @author Edwin Punzalan
30 public class ArtifactRepositoryIndexAnalyzer
33 private Analyzer defaultAnalyzer;
36 * constructor to for this analyzer
38 * @character defaultAnalyzer the analyzer to use as default for the general fields of the artifact indeces
40 public ArtifactRepositoryIndexAnalyzer( Analyzer defaultAnalyzer )
42 this.defaultAnalyzer = defaultAnalyzer;
46 * Method called by lucence during indexing operations
48 * @return an analyzer to specific to the field name or the default analyzer if none is present
49 * @character fieldName the field name that the lucene object is currently processing
50 * @character reader a Reader object to the index stream
52 public TokenStream tokenStream( String fieldName, Reader reader )
54 TokenStream tokenStream;
56 if ( "version".equals( fieldName ) )
58 tokenStream = new VersionTokenizer( reader );
62 tokenStream = defaultAnalyzer.tokenStream( fieldName, reader );
69 * Class used to tokenize an artifact's version.
71 private class VersionTokenizer
75 * Constructor with the required reader to the index stream
77 * @reader the Reader object of the index stream
79 public VersionTokenizer( Reader reader )
85 * method that lucene calls to check tokenization of a stream character
87 * @param character char currently being processed
88 * @return true if the char is a token, false if the char is a stop char
90 protected boolean isTokenChar( char character )