pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / remote / src / java / org / apache / lucene / search / RemoteSearchable.java
1 package org.apache.lucene.search;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import org.apache.lucene.document.Document;
21 import org.apache.lucene.document.FieldSelector;
22 import org.apache.lucene.index.Term;
23 import org.apache.lucene.index.CorruptIndexException;
24 import org.apache.lucene.store.FSDirectory;
25
26 import java.io.IOException;
27 import java.io.File;
28 import java.rmi.Naming;
29 import java.rmi.RMISecurityManager;
30 import java.rmi.RemoteException;
31 import java.rmi.server.UnicastRemoteObject;
32
33 /**
34  * A remote searchable implementation.
35  *
36  * @deprecated This package (all of contrib/remote) will be
37  * removed in 4.0.
38  */
39 @Deprecated
40 public class RemoteSearchable
41   extends UnicastRemoteObject
42   implements RMIRemoteSearchable {
43   
44   private Searchable local;
45   
46   /** Constructs and exports a remote searcher. */
47   public RemoteSearchable(Searchable local) throws RemoteException {
48     super();
49     this.local = local;
50   }
51   public void search(Weight weight, Filter filter, Collector results)
52   throws IOException {
53     local.search(weight, filter, results);
54   }
55
56   public void close() throws IOException {
57     local.close();
58   }
59
60   public int docFreq(Term term) throws IOException {
61     return local.docFreq(term);
62   }
63
64
65   public int[] docFreqs(Term[] terms) throws IOException {
66     return local.docFreqs(terms);
67   }
68
69   public int maxDoc() throws IOException {
70     return local.maxDoc();
71   }
72
73   public TopDocs search(Weight weight, Filter filter, int n) throws IOException {
74     return local.search(weight, filter, n);
75   }
76   
77   public TopFieldDocs search(Weight weight, Filter filter, int n, Sort sort)
78   throws IOException {
79     return local.search (weight, filter, n, sort);
80   }
81
82   public Document doc(int i) throws CorruptIndexException, IOException {
83     return local.doc(i);
84   }
85
86   public Document doc(int i, FieldSelector fieldSelector) throws CorruptIndexException, IOException {
87             return local.doc(i, fieldSelector);
88   }
89   
90   public Query rewrite(Query original) throws IOException {
91     return local.rewrite(original);
92   }
93
94   public Explanation explain(Weight weight, int doc) throws IOException {
95     return local.explain(weight, doc);
96   }
97
98   /** Exports a searcher for the index in args[0] named
99    * "//localhost/Searchable". */
100   public static void main(String args[]) throws Exception {
101     String indexName = null;
102     
103     if (args != null && args.length == 1)
104       indexName = args[0];
105     
106     if (indexName == null) {
107       System.out.println("Usage: org.apache.lucene.search.RemoteSearchable <index>");
108       return;
109     }
110     
111     // create and install a security manager
112     if (System.getSecurityManager() == null) {
113       System.setSecurityManager(new RMISecurityManager());
114     }
115     
116     Searchable local = new IndexSearcher(FSDirectory.open(new File(indexName)), true);
117     RemoteSearchable impl = new RemoteSearchable(local);
118       
119     // bind the implementation to "Searchable"
120     Naming.rebind("//localhost/Searchable", impl);
121   }
122
123 }