001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/search/tags/sakai_2-4-1/search-impl/impl/src/java/org/sakaiproject/search/index/impl/SearchIndexStorage.java $
003: * $Id: SearchIndexStorage.java 29635 2007-04-26 14:44:09Z ajpoland@iupui.edu $
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.io.IOException;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.apache.lucene.analysis.Analyzer;
029: import org.apache.lucene.index.IndexReader;
030: import org.apache.lucene.index.IndexWriter;
031: import org.apache.lucene.search.IndexSearcher;
032: import org.sakaiproject.search.index.IndexStorage;
033:
034: /**
035: * A simple multiplex class to enable configuration of the storage mecahnism in
036: * sakai.properties to use
037: * indexStorageName@org.sakaiproject.search.index.IndexStorage = filesystem
038: * indexStorageName@org.sakaiproject.search.index.IndexStorage = cluster
039: * indexStorageName@org.sakaiproject.search.index.IndexStorage = db
040: * recoverCorruptedIndex@org.sakaiproject.search.index.IndexStorage = false
041: * location@org.sakaiproject.search.index.IndexStorage =
042: * tableName|localDirectory Default is to use the local filesystem These values
043: * may cahnge, and it is worth looking in the components for the real values.
044: *
045: * @author ieb
046: */
047: public class SearchIndexStorage implements IndexStorage {
048: private final static Log log = LogFactory
049: .getLog(SearchIndexStorage.class);
050:
051: private IndexStorage runningIndexStorage = null;
052:
053: private Map currentStores = null;
054:
055: private IndexStorage defaultIndexStorage;
056:
057: private String indexStorageName;
058:
059: private boolean recover;
060:
061: private String location;
062:
063: public void init() {
064: log.info("init()");
065: try {
066: runningIndexStorage = (IndexStorage) currentStores
067: .get(indexStorageName.trim());
068:
069: if (runningIndexStorage == null) {
070: runningIndexStorage = defaultIndexStorage;
071: }
072: } catch (Exception ex) {
073: log.warn("Failed to init SearchIndexStorage ", ex);
074: }
075: log.info("init() Ok");
076: }
077:
078: public IndexReader getIndexReader() throws IOException {
079: return runningIndexStorage.getIndexReader();
080: }
081:
082: public IndexWriter getIndexWriter(boolean create)
083: throws IOException {
084: return runningIndexStorage.getIndexWriter(create);
085: }
086:
087: public IndexSearcher getIndexSearcher() throws IOException {
088: return runningIndexStorage.getIndexSearcher();
089: }
090:
091: public void doPostIndexUpdate() throws IOException {
092: runningIndexStorage.doPostIndexUpdate();
093: }
094:
095: public void doPreIndexUpdate() throws IOException {
096: runningIndexStorage.doPreIndexUpdate();
097: }
098:
099: public boolean indexExists() {
100: return runningIndexStorage.indexExists();
101: }
102:
103: public Analyzer getAnalyzer() {
104: return runningIndexStorage.getAnalyzer();
105: }
106:
107: /**
108: * @return Returns the currentStores.
109: */
110: public Map getCurrentStores() {
111: return currentStores;
112: }
113:
114: /**
115: * @param currentStores
116: * The currentStores to set.
117: */
118: public void setCurrentStores(Map currentStores) {
119: this .currentStores = currentStores;
120: }
121:
122: /**
123: * @return Returns the defaultIndexStorage.
124: */
125: public IndexStorage getDefaultIndexStorage() {
126: return defaultIndexStorage;
127: }
128:
129: /**
130: * @param defaultIndexStorage
131: * The defaultIndexStorage to set.
132: */
133: public void setDefaultIndexStorage(IndexStorage defaultIndexStorage) {
134: this .defaultIndexStorage = defaultIndexStorage;
135: }
136:
137: /**
138: * @return Returns the indexStorageName.
139: */
140: public String getIndexStorageName() {
141: return indexStorageName;
142: }
143:
144: /**
145: * @param indexStorageName
146: * The indexStorageName to set.
147: */
148: public void setIndexStorageName(String indexStorageName) {
149: this .indexStorageName = indexStorageName;
150: }
151:
152: /**
153: * @return Returns the runningIndexStorage.
154: */
155: public IndexStorage getRunningIndexStorage() {
156: return runningIndexStorage;
157: }
158:
159: /**
160: * @param runningIndexStorage
161: * The runningIndexStorage to set.
162: */
163: public void setRunningIndexStorage(IndexStorage runningIndexStorage) {
164: this .runningIndexStorage = runningIndexStorage;
165: }
166:
167: public void setRecoverCorruptedIndex(boolean recover) {
168: this .recover = recover;
169:
170: }
171:
172: public void setLocation(String location) {
173: this .location = location;
174:
175: }
176:
177: public long getLastUpdate() {
178: return runningIndexStorage.getLastUpdate();
179: }
180:
181: public List getSegmentInfoList() {
182: return runningIndexStorage.getSegmentInfoList();
183: }
184:
185: public void closeIndexReader(IndexReader indexReader)
186: throws IOException {
187: runningIndexStorage.closeIndexReader(indexReader);
188: }
189:
190: public void closeIndexWriter(IndexWriter indexWrite)
191: throws IOException {
192: runningIndexStorage.closeIndexWriter(indexWrite);
193: }
194:
195: public boolean isMultipleIndexers() {
196: return runningIndexStorage.isMultipleIndexers();
197: }
198:
199: public void closeIndexSearcher(IndexSearcher indexSearcher) {
200: runningIndexStorage.closeIndexSearcher(indexSearcher);
201:
202: }
203:
204: /* (non-Javadoc)
205: * @see org.sakaiproject.search.api.Diagnosable#disableDiagnostics()
206: */
207: public void disableDiagnostics() {
208: runningIndexStorage.disableDiagnostics();
209: }
210:
211: /* (non-Javadoc)
212: * @see org.sakaiproject.search.api.Diagnosable#enableDiagnostics()
213: */
214: public void enableDiagnostics() {
215: runningIndexStorage.enableDiagnostics();
216: }
217:
218: /* (non-Javadoc)
219: * @see org.sakaiproject.search.api.Diagnosable#hasDiagnostics()
220: */
221: public boolean hasDiagnostics() {
222: return runningIndexStorage.hasDiagnostics();
223: }
224:
225: /* (non-Javadoc)
226: * @see org.sakaiproject.search.index.IndexStorage#centralIndexExists()
227: */
228: public boolean centralIndexExists() {
229: return runningIndexStorage.centralIndexExists();
230: }
231:
232: }
|