01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/search/tags/sakai_2-4-1/search-impl/impl/src/java/org/sakaiproject/search/index/impl/StandardAnalyzerFactory.java $
03: * $Id: StandardAnalyzerFactory.java 29315 2007-04-20 14:28:12Z ajpoland@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
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: **********************************************************************************/package org.sakaiproject.search.index.impl;
21:
22: import java.io.BufferedReader;
23: import java.io.InputStreamReader;
24: import java.util.ArrayList;
25:
26: import org.apache.commons.logging.Log;
27: import org.apache.commons.logging.LogFactory;
28: import org.apache.lucene.analysis.Analyzer;
29: import org.apache.lucene.analysis.standard.StandardAnalyzer;
30: import org.sakaiproject.search.index.AnalyzerFactory;
31:
32: /**
33: * @author ieb
34: *
35: */
36: public class StandardAnalyzerFactory implements AnalyzerFactory {
37:
38: private static final Log log = LogFactory
39: .getLog(SnowballAnalyzerFactory.class);
40:
41: private static String[] stopWords = null;
42: static {
43: try {
44: ArrayList<String> al = new ArrayList<String>();
45: BufferedReader br = new BufferedReader(
46: new InputStreamReader(
47: SnowballAnalyzerFactory.class
48: .getResourceAsStream("/org/sakaiproject/search/component/bundle/stopwords.txt")));
49: for (String line = br.readLine(); line != null; line = br
50: .readLine()) {
51: al.add(line.trim());
52: }
53: br.close();
54: stopWords = al.toArray(new String[0]);
55: } catch (Exception ex) {
56: log.error("Failed to load Stop words into Analyzer", ex);
57: }
58: }
59:
60: public Analyzer newAnalyzer() {
61: return new StandardAnalyzer(stopWords);
62: }
63:
64: }
|