1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
32
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 }