1 package org.apache.maven.repository.indexing;
4 * Copyright 2001-2005 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
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.Reader;
21 import java.util.HashMap;
23 import org.apache.lucene.analysis.Analyzer;
24 import org.apache.lucene.analysis.CharTokenizer;
25 import org.apache.lucene.analysis.TokenStream;
28 * Class created specifically to index artifacts
30 * @author Edwin Punzalan
32 public class ArtifactRepositoryIndexAnalyzer
35 private Analyzer defaultAnalyzer;
38 * constructor to for this analyzer
40 * @character defaultAnalyzer the analyzer to use as default for the general fields of the artifact indeces
42 public ArtifactRepositoryIndexAnalyzer( Analyzer defaultAnalyzer )
44 this.defaultAnalyzer = defaultAnalyzer;
48 * Method called by lucence during indexing operations
50 * @character fieldName the field name that the lucene object is currently processing
51 * @character reader a Reader object to the index stream
53 * @return an analyzer to specific to the field name or the default analyzer if none is present
55 public TokenStream tokenStream( String fieldName, Reader reader )
57 TokenStream tokenStream;
59 if ( "version".equals( fieldName ) )
61 tokenStream = new VersionTokenizer( reader );
65 tokenStream = defaultAnalyzer.tokenStream( fieldName, reader );
72 * Class used to tokenize an artifact's version.
74 private class VersionTokenizer
78 * Constructor with the required reader to the index stream
80 * @reader the Reader object of the index stream
82 public VersionTokenizer( Reader reader )
88 * method that lucene calls to check tokenization of a stream character
90 * @param character char currently being processed
92 * @return true if the char is a token, false if the char is a stop char
94 protected boolean isTokenChar( char character )
102 token = false; break;