0
|
1 package nabble.model.lucene;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import org.slf4j.Logger;
|
|
5 import org.slf4j.LoggerFactory;
|
|
6 import org.apache.lucene.document.Document;
|
|
7 import org.apache.lucene.index.CorruptIndexException;
|
|
8 import org.apache.lucene.search.Query;
|
|
9 import org.apache.lucene.search.Filter;
|
|
10 import org.apache.lucene.search.Collector;
|
|
11 import org.apache.lucene.search.TopDocs;
|
|
12 import org.apache.lucene.search.TopFieldDocs;
|
|
13 import org.apache.lucene.search.Sort;
|
|
14
|
|
15
|
|
16 final class LuceneSearcherImpl implements LuceneSearcher {
|
|
17 private static final Logger logger = LoggerFactory.getLogger(LuceneSearcherImpl.class);
|
|
18
|
|
19 private final LuceneSearcher searcher;
|
|
20 private boolean isClosed = false;
|
|
21
|
|
22 LuceneSearcherImpl(LuceneSearcher searcher) {
|
|
23 this.searcher = searcher;
|
|
24 }
|
|
25
|
|
26 public void close() throws IOException {
|
|
27 if( !isClosed ) {
|
|
28 searcher.close();
|
|
29 isClosed = true;
|
|
30 }
|
|
31 }
|
|
32
|
|
33 @Override protected void finalize() throws Throwable {
|
|
34 if( !isClosed ) {
|
|
35 logger.error("didn't close IndexSearcher"/*,initException*/);
|
|
36 close();
|
|
37 }
|
|
38 super.finalize();
|
|
39 }
|
|
40
|
|
41 public void search(Query query,Collector results) throws IOException {
|
|
42 searcher.search(query,results);
|
|
43 }
|
|
44
|
|
45 public void search(Query query,Filter filter,Collector results) throws IOException {
|
|
46 searcher.search(query,filter,results);
|
|
47 }
|
|
48
|
|
49 public TopDocs search(Query query,int n) throws IOException {
|
|
50 return searcher.search(query,n);
|
|
51 }
|
|
52
|
|
53 public TopDocs search(Query query,Filter filter,int n) throws IOException {
|
|
54 return searcher.search(query,filter,n);
|
|
55 }
|
|
56
|
|
57 public TopFieldDocs search(Query query,Filter filter,int n,Sort sort) throws IOException {
|
|
58 return searcher.search(query,filter,n,sort);
|
|
59 }
|
|
60
|
|
61 public Document doc(int i) throws CorruptIndexException, IOException {
|
|
62 return searcher.doc(i);
|
|
63 }
|
|
64 }
|