View Javadoc

1   /* Copyright (c) 2008 Sascha Kohlmann
2    *
3    * This program is free software: you can redistribute it and/or modify
4    * it under the terms of the GNU Affero General Public License as published by
5    * the Free Software Foundation, either version 3 of the License, or
6    * (at your option) any later version.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Affero General Public License for more details.
12   *
13   * You should have received a copy of the GNU Affero General Public License
14   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15   */
16  package net.sf.eos.lucene;
17  
18  import net.sf.eos.EosException;
19  import net.sf.eos.config.Configuration;
20  import net.sf.eos.config.ConfigurationException;
21  import net.sf.eos.config.Service;
22  
23  import org.apache.lucene.index.CorruptIndexException;
24  import org.apache.lucene.search.IndexSearcher;
25  import org.apache.lucene.search.Searcher;
26  import org.apache.lucene.store.Directory;
27  
28  import java.io.IOException;
29  
30  /**
31   * Based on {@link DirectorySupplier}.
32   * @author Sascha Kohlmann
33   */
34  @Service(
35      factory=DirectorySupplier.class
36  )
37  public class IndexSearcherSupplier extends SearcherSupplier {
38  
39      @Override
40      public Searcher get(final Configuration conf) {
41          try {
42              final DirectorySupplier provider = DirectorySupplier.newInstance(conf);
43              final Directory directory = provider.get(conf);
44              return new IndexSearcher(directory);
45          } catch (final CorruptIndexException e) {
46              final String message = e.getMessage();
47              throw new ConfigurationException(message, e);
48          } catch (final IOException e) {
49              final String message = e.getMessage();
50              throw new ConfigurationException(message, e);
51          } catch (final EosException e) {
52              final String message = e.getMessage();
53              throw new ConfigurationException(message, e);
54          }
55      }
56  }