01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.engine.subindex;
18:
19: import org.compass.core.CompassException;
20: import org.compass.core.Property;
21: import org.compass.core.config.CompassConfigurable;
22: import org.compass.core.config.CompassSettings;
23: import org.compass.core.engine.SearchEngineException;
24:
25: /**
26: * Alwats returns a constant sub index for any hashing.
27: * <p/>
28: * If using configuration, expects <code>subIndex</code> as the setting name,
29: * and the sub index value as the setting value.
30: *
31: * @author kimchy
32: */
33: public class ConstantSubIndexHash implements SubIndexHash,
34: CompassConfigurable {
35:
36: private String subIndex;
37:
38: /**
39: * Construts a new instances, will have to call {@link #configure(org.compass.core.config.CompassSettings)}
40: * in order to configure the sub index.
41: */
42: public ConstantSubIndexHash() {
43: }
44:
45: /**
46: * Constructs a new instance based on the given sub index.
47: *
48: * @param subIndex The constant sub index to use
49: */
50: public ConstantSubIndexHash(String subIndex) {
51: this .subIndex = subIndex.toLowerCase();
52: }
53:
54: /**
55: * Configures the constant sub index hash, expects <code>subIndex</code> as
56: * the setting name, and the sub index value as the setting value.
57: *
58: * @param settings The settings to configure by
59: * @throws CompassException
60: */
61: public void configure(CompassSettings settings)
62: throws CompassException {
63: subIndex = settings.getSetting("subIndex", subIndex)
64: .toLowerCase();
65: }
66:
67: /**
68: * Returns the single constant sub index.
69: */
70: public String[] getSubIndexes() {
71: return new String[] { subIndex };
72: }
73:
74: /**
75: * Returns the single constant sub index. Does not take into account
76: * either the alias, or the ids.
77: */
78: public String mapSubIndex(String alias, Property[] ids)
79: throws SearchEngineException {
80: return subIndex;
81: }
82:
83: public String toString() {
84: return "ConstantSubIndexHash[" + subIndex + "]";
85: }
86: }
|