001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/search/tags/sakai_2-4-1/search-impl/impl/src/java/org/sakaiproject/search/index/impl/SearchAnalyzerFactory.java $
003: * $Id: SearchAnalyzerFactory.java 10080 2006-05-30 05:24:18Z ian@caret.cam.ac.uk $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.search.index.impl;
021:
022: import java.util.Map;
023:
024: import org.apache.lucene.analysis.Analyzer;
025: import org.sakaiproject.search.index.AnalyzerFactory;
026:
027: /**
028: * A Factory to generate search analyzers based on a configurable type setting.
029: * The type of analyzer produced is selected by setting the analyzerFactory name that will
030: * select one of the same name ijected into the currentAnalyzers Map.
031: * @author ieb
032: *
033: */
034: public class SearchAnalyzerFactory implements AnalyzerFactory {
035: private AnalyzerFactory runningAnalyzerFactory = null;
036: private Map currentAnalyzers = null;
037: private AnalyzerFactory defaultAnalyzerFactory;
038: private String analyzerFactoryName;
039:
040: public void init() {
041: runningAnalyzerFactory = (AnalyzerFactory) currentAnalyzers
042: .get(analyzerFactoryName);
043: if (runningAnalyzerFactory == null) {
044: runningAnalyzerFactory = defaultAnalyzerFactory;
045: }
046: }
047:
048: public Analyzer newAnalyzer() {
049: return defaultAnalyzerFactory.newAnalyzer();
050: }
051:
052: /**
053: * @return Returns the analyzerFactoryName.
054: */
055: public String getAnalyzerFactoryName() {
056: return analyzerFactoryName;
057: }
058:
059: /**
060: * @param analyzerFactoryName The analyzerFactoryName to set.
061: */
062: public void setAnalyzerFactoryName(String analyzerFactoryName) {
063: this .analyzerFactoryName = analyzerFactoryName;
064: }
065:
066: /**
067: * @return Returns the currentAnalyzers.
068: */
069: public Map getCurrentAnalyzers() {
070: return currentAnalyzers;
071: }
072:
073: /**
074: * @param currentAnalyzers The currentAnalyzers to set.
075: */
076: public void setCurrentAnalyzers(Map currentAnalyzers) {
077: this .currentAnalyzers = currentAnalyzers;
078: }
079:
080: /**
081: * @return Returns the defaultAnalyzerFactory.
082: */
083: public AnalyzerFactory getDefaultAnalyzerFactory() {
084: return defaultAnalyzerFactory;
085: }
086:
087: /**
088: * @param defaultAnalyzerFactory The defaultAnalyzerFactory to set.
089: */
090: public void setDefaultAnalyzerFactory(
091: AnalyzerFactory defaultAnalyzerFactory) {
092: this .defaultAnalyzerFactory = defaultAnalyzerFactory;
093: }
094:
095: /**
096: * @return Returns the runningAnalyzerFactory.
097: */
098: public AnalyzerFactory getRunningAnalyzerFactory() {
099: return runningAnalyzerFactory;
100: }
101:
102: /**
103: * @param runningAnalyzerFactory The runningAnalyzerFactory to set.
104: */
105: public void setRunningAnalyzerFactory(
106: AnalyzerFactory runningAnalyzerFactory) {
107: this.runningAnalyzerFactory = runningAnalyzerFactory;
108: }
109:
110: }
|