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 static java.lang.annotation.RetentionPolicy.RUNTIME;
022: import java.lang.annotation.Target;
023:
024: /**
025: * Specifies a searchable id on property or field of the {@link Searchable} class.
026: * <p/>
027: * Each searchable class must have at least one id annotation. The type
028: * of the field/property can be a simple type, or a custom class. In case
029: * of a custom class, there should be a specialized converter associtaed
030: * with it, with the preferable way of defining the converter is to use
031: * the {@link SearchableClassConverter} annotating the custom class.
032: * <p/>
033: * A searchable class can have more than one searchable id associated with it.
034: * <p/>
035: * For simple usage, the annotation can create a {@link SearchableMetaData} automatically
036: * (without explicitly defining one on the field/property).
037: * It will only be created if the {@link #name()} is set to a value. Most of
038: * the attributes that can control the meta-data are provided in the searchable
039: * id as well, they are marked in the java doc.
040: * <p/>
041: * Note, that if the {@link #name()} is not set, no defined {@link SearchableMetaData}
042: * will be created, and Compass will end up generating an internal meta-data for it.
043: * For additional meta-datas, use the {@link SearchableMetaData} or {@link SearchableMetaDatas}.
044: * <p/>
045: * Compass might require an internal meta-data to be created, so it can identify the correct
046: * value that match the property/field. Controlling the creation and specifics of the intenal
047: * meta-data id can be done using {@link #managedId()} and {@link #managedIdIndex()}.
048: *
049: * @author kimchy
050: * @see Searchable
051: * @see SearchableClassConverter
052: * @see SearchableMetaData
053: * @see SearchableMetaDatas
054: */
055: @Target({ElementType.METHOD,ElementType.FIELD})
056: @Retention(RUNTIME)
057: public @interface SearchableId {
058:
059: /**
060: * Controls if the internal meta-data id creation.
061: */
062: ManagedId managedId() default ManagedId.AUTO;
063:
064: /**
065: * If the internal meta-data id is created, controls it's
066: * index parameter.
067: */
068: ManagedIdIndex managedIdIndex() default ManagedIdIndex.NA;
069:
070: /**
071: * If there is already an existing id with the same field/property name defined,
072: * will override it.
073: */
074: boolean override() default true;
075:
076: /**
077: * Converter that will apply to the id mapping
078: * ({@link org.compass.core.mapping.osem.ClassIdPropertyMapping}).
079: * Defaults to the {@link org.compass.core.mapping.osem.ClassPropertyMapping}.
080: */
081: String idConverter() default "";
082:
083: /**
084: * The property accessor that will be fetch and write the property value.
085: * <p/>
086: * It is automatically set based on where the annotation is used, but can be
087: * explicitly set. Compass also supports custom property accessors, registered
088: * under a custom name, which can then be used here as well.
089: */
090: String accessor() default "";
091:
092: // Generated MetaData definitions
093:
094: /**
095: * The name of the auto generated {@link SearchableMetaData}. Maps to
096: * {@link org.compass.annotations.SearchableMetaData#name()}.
097: * <p/>
098: * The meta-data will be auto generated only if the name has a value.
099: */
100: String name() default "";
101:
102: /**
103: * The boost of the auto generated {@link SearchableMetaData}. Maps to
104: * {@link org.compass.annotations.SearchableMetaData#boost()}.
105: * <p/>
106: * The meta-data will be auto generated only if the name has a value.
107: */
108: float boost() default 1.0f;
109:
110: /**
111: * The store of the auto generated {@link SearchableMetaData}. Maps to
112: * {@link org.compass.annotations.SearchableMetaData#store()}.
113: * <p/>
114: * The meta-data will be auto generated only if the name has a value.
115: */
116: Store store() default Store.YES;
117:
118: /**
119: * The index of the auto generated {@link SearchableMetaData}. Maps to
120: * {@link org.compass.annotations.SearchableMetaData#index()}.
121: * <p/>
122: * The meta-data will be auto generated only if the name has a value.
123: */
124: Index index() default Index.UN_TOKENIZED;
125:
126: /**
127: * The termVector of the auto generated {@link SearchableMetaData}. Maps to
128: * {@link org.compass.annotations.SearchableMetaData#termVector()}.
129: *
130: * <p>The meta-data will be auto generated only if the name has a value.
131: */
132: TermVector termVector() default TermVector.NO;
133:
134: /**
135: * The termVector of the auto generated {@link SearchableMetaData}. Maps to
136: * {@link SearchableMetaData#omitNorms()}.
137: *
138: * <p>The meta-data will be auto generated only if the name has a value.
139: */
140: boolean omitNorms() default true;
141:
142: /**
143: * The reverse of the auto generated {@link SearchableMetaData}. Maps to
144: * {@link org.compass.annotations.SearchableMetaData#reverse()}.
145: * <p/>
146: * The meta-data will be auto generated only if the name has a value.
147: */
148: Reverse reverse() default Reverse.NO;
149:
150: /**
151: * The analyzer of the auto generated {@link SearchableMetaData}. Maps to
152: * {@link org.compass.annotations.SearchableMetaData#analyzer()}.
153: * <p/>
154: * The meta-data will be auto generated only if the name has a value.
155: */
156: String analyzer() default "";
157:
158: /**
159: * The execlude from all of the auto generated {@link SearchableMetaData}. Maps to
160: * {@link org.compass.annotations.SearchableMetaData#excludeFromAll()}.
161: * <p/>
162: * The meta-data will be auto generated only if the name has a value.
163: */
164: ExcludeFromAll excludeFromAll() default ExcludeFromAll.NO;
165:
166: /**
167: * The converter of the auto generated {@link SearchableMetaData}. Maps to
168: * {@link org.compass.annotations.SearchableMetaData#converter()}.
169: * The meta-data will be auto generated only if the name has a value.
170: * <p>
171: * This converter will also be used for an internal meta-data id (if required to be
172: * generated).
173: */
174: String converter() default "";
175:
176: /**
177: * The format of the auto generated {@link SearchableMetaData}. Maps to
178: * {@link org.compass.annotations.SearchableMetaData#format()}.
179: * The meta-data will be auto generated only if the name has a value.
180: * <p>
181: * This format will also be used for an internal meta-data id (if required to be
182: * generated).
183: */
184: String format() default "";
185:
186: /**
187: * Should this propety be included in the spell check index.
188: *
189: * <p>Note, most times this is not requried to be configured, since by default, the
190: * spell check index uses the "all" property.
191: */
192: SpellCheck spellCheck() default SpellCheck.EXCLUDE;
193: }
|