01: package org.apache.lucene.document;
02:
03: import java.util.Set;
04:
05: /**
06: * Copyright 2004 The Apache Software Foundation
07: *
08: * Licensed under the Apache License, Version 2.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: */
20:
21: /**
22: * Declare what fields to load normally and what fields to load lazily
23: *
24: **/
25: public class SetBasedFieldSelector implements FieldSelector {
26:
27: private Set fieldsToLoad;
28: private Set lazyFieldsToLoad;
29:
30: /**
31: * Pass in the Set of {@link Field} names to load and the Set of {@link Field} names to load lazily. If both are null, the
32: * Document will not have any {@link Field} on it.
33: * @param fieldsToLoad A Set of {@link String} field names to load. May be empty, but not null
34: * @param lazyFieldsToLoad A Set of {@link String} field names to load lazily. May be empty, but not null
35: */
36: public SetBasedFieldSelector(Set fieldsToLoad, Set lazyFieldsToLoad) {
37: this .fieldsToLoad = fieldsToLoad;
38: this .lazyFieldsToLoad = lazyFieldsToLoad;
39: }
40:
41: /**
42: * Indicate whether to load the field with the given name or not. If the {@link Field#name()} is not in either of the
43: * initializing Sets, then {@link org.apache.lucene.document.FieldSelectorResult#NO_LOAD} is returned. If a Field name
44: * is in both <code>fieldsToLoad</code> and <code>lazyFieldsToLoad</code>, lazy has precedence.
45: *
46: * @param fieldName The {@link Field} name to check
47: * @return The {@link FieldSelectorResult}
48: */
49: public FieldSelectorResult accept(String fieldName) {
50: FieldSelectorResult result = FieldSelectorResult.NO_LOAD;
51: if (fieldsToLoad.contains(fieldName) == true) {
52: result = FieldSelectorResult.LOAD;
53: }
54: if (lazyFieldsToLoad.contains(fieldName) == true) {
55: result = FieldSelectorResult.LAZY_LOAD;
56: }
57: return result;
58: }
59: }
|