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.impl;
18:
19: import java.io.Reader;
20:
21: import org.compass.core.CompassAnalyzerHelper;
22: import org.compass.core.CompassException;
23: import org.compass.core.CompassToken;
24: import org.compass.core.Resource;
25: import org.compass.core.engine.SearchEngineAnalyzerHelper;
26: import org.compass.core.mapping.ResourcePropertyLookup;
27: import org.compass.core.spi.InternalCompassSession;
28:
29: /**
30: * @author kimchy
31: */
32: public class DefaultCompassAnalyzerHelper implements
33: CompassAnalyzerHelper {
34:
35: private InternalCompassSession session;
36:
37: private SearchEngineAnalyzerHelper analyzerHelper;
38:
39: public DefaultCompassAnalyzerHelper(
40: SearchEngineAnalyzerHelper analyzerHelper,
41: InternalCompassSession session) {
42: this .session = session;
43: this .analyzerHelper = analyzerHelper;
44: }
45:
46: public CompassAnalyzerHelper setAnalyzer(String analyzerName)
47: throws CompassException {
48: analyzerHelper.setAnalyzer(analyzerName);
49: return this ;
50: }
51:
52: public CompassAnalyzerHelper setAnalyzer(Resource resource)
53: throws CompassException {
54: analyzerHelper.setAnalyzer(resource);
55: return this ;
56: }
57:
58: public CompassAnalyzerHelper setAnalyzerByAlias(String alias)
59: throws CompassException {
60: analyzerHelper.setAnalyzerByAlias(alias);
61: return this ;
62: }
63:
64: public CompassToken analyzeSingle(String text)
65: throws CompassException {
66: return analyzerHelper.analyzeSingle(text);
67: }
68:
69: public CompassToken[] analyze(String text) throws CompassException {
70: return analyzerHelper.analyze(text);
71: }
72:
73: public CompassToken[] analyze(String propertyName, String text)
74: throws CompassException {
75: ResourcePropertyLookup lookup = session.getMapping()
76: .getResourcePropertyLookup(propertyName);
77: return analyzerHelper.analyze(lookup.getPath(), text);
78: }
79:
80: public CompassToken[] analyze(Reader textReader)
81: throws CompassException {
82: return analyzerHelper.analyze(textReader);
83: }
84:
85: public CompassToken[] analyze(String propertyName, Reader textReader)
86: throws CompassException {
87: ResourcePropertyLookup lookup = session.getMapping()
88: .getResourcePropertyLookup(propertyName);
89: return analyzerHelper.analyze(lookup.getPath(), textReader);
90: }
91: }
|