001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.annotations;
018:
019: import java.lang.annotation.ElementType;
020: import java.lang.annotation.Retention;
021: import java.lang.annotation.RetentionPolicy;
022: import java.lang.annotation.Target;
023:
024: import org.apache.lucene.analysis.Analyzer;
025:
026: /**
027: * Configure {@link Analyzer} to be used within Compass.
028: * Set on package definition (<code>package-info.java</code>).
029: * <p/>
030: * The {@link Analyzer} is registed under a lookup name ({@link #name()}), which can then
031: * be reference in the different mapping definitions.
032: * <p/>
033: * Allows for simple configuration of all analyzers that come with Compass using {@link #type()}.
034: * If the {@link #type()} is set to {@link AnalyzerType#Snowball}, the {@link #snowballType()}
035: * can be used to further configure the snowball analyzer. If a custom converter needs to be
036: * registered with Compass, the {@link AnalyzerType#CustomAnalyzer} needs to be set on {@link #type()},
037: * and the {@link #analyzerClass()} needs to be configured with the class that implements it.
038: * <p/>
039: * A set of stop words can be added/replace the stop words the internal analyzers are configured
040: * with. The stop words will be added if the {@link #addStopWords()} is set to <code>true</code>.
041: * <p/>
042: * Further settings can be set for a specialized analyzer using {@link #settings()}. If the
043: * specialized {@link Analyzer} requires settings to be injected, it needs to implement the
044: * {@link org.compass.core.config.CompassConfigurable} interface.
045: * <p/>
046: * To replace Compas default analyzer, the {@link #name()} should be set
047: * {@link org.compass.core.lucene.LuceneEnvironment.Analyzer#DEFAULT_GROUP}.
048: * <p/>
049: * To replace Compass search analyzer (which defaults to the default analyzer if not set), the
050: * {@link #name()} should be set to {@link org.compass.core.lucene.LuceneEnvironment.Analyzer#SEARCH_GROUP}.
051: * <p/>
052: * Multiple analyzers can be defined using the {@link SearchAnalyzers} annotation.
053: * <p/>
054: * Note, that Analyzers can also be conifugred using Compass configuration mechanism.
055: *
056: * @author kimchy
057: */
058: @Target(ElementType.PACKAGE)
059: @Retention(RetentionPolicy.RUNTIME)
060: public @interface SearchAnalyzer {
061:
062: /**
063: * The name the analyzer will be registered under.
064: */
065: String name();
066:
067: /**
068: * The type of the analyzer. For custom {@link Analyzer} implementation
069: * the {@link AnalyzerType#CustomAnalyzer} should be set, and the {@link #analyzerClass()}
070: * should have the custom {@link Analyzer} class set.
071: */
072: AnalyzerType type();
073:
074: /**
075: * If the {@link #type()} is set to {@link AnalyzerType#Snowball}, controls
076: * the snowball analyzer type.
077: */
078: SnowballType snowballType() default SnowballType.Porter;
079:
080: /**
081: * The custom {@link Analyzer} implementation. Used when the {@link #type()}
082: * is set to {@link AnalyzerType#CustomAnalyzer}.
083: */
084: Class<? extends Analyzer> analyzerClass() default Analyzer.class;
085:
086: /**
087: * A set of {@link org.compass.core.lucene.engine.analyzer.LuceneAnalyzerTokenFilterProvider}s
088: * lookup names to be used with the {@link Analyzer}.
089: * <p/>
090: * Filters can be configured using {@link SearchAnalyzerFilter} or using Compass configuration.
091: */
092: String[] filters() default {};
093:
094: /**
095: * A set of stop words that will be added/replace the stop words that comes with Compass intenral
096: * analyzers.
097: * <p/>
098: * Only applies when using one of Compass internal analyzer types, and not the {@link AnalyzerType#CustomAnalyzer}.
099: */
100: String[] stopWords() default {};
101:
102: /**
103: * Add the set of {@link #stopWords()} to the default set of stop words if set to <code>true</code>.
104: * Replaces them if set to <code>false</code>.
105: * <p/>
106: * Only applies when using one of Compass internal analyzer types, and not the {@link AnalyzerType#CustomAnalyzer}.
107: */
108: boolean addStopWords() default true;
109:
110: /**
111: * Futher settings for a custom {@link Analyzer} implementation.
112: */
113: SearchSetting[] settings() default {};
114: }
|