1 package org.apache.lucene.search;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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;
26 import java.io.IOException;
28 import java.rmi.Naming;
29 import java.rmi.RMISecurityManager;
30 import java.rmi.RemoteException;
31 import java.rmi.server.UnicastRemoteObject;
34 * A remote searchable implementation.
36 * @deprecated This package (all of contrib/remote) will be
40 public class RemoteSearchable
41 extends UnicastRemoteObject
42 implements RMIRemoteSearchable {
44 private Searchable local;
46 /** Constructs and exports a remote searcher. */
47 public RemoteSearchable(Searchable local) throws RemoteException {
51 public void search(Weight weight, Filter filter, Collector results)
53 local.search(weight, filter, results);
56 public void close() throws IOException {
60 public int docFreq(Term term) throws IOException {
61 return local.docFreq(term);
65 public int[] docFreqs(Term[] terms) throws IOException {
66 return local.docFreqs(terms);
69 public int maxDoc() throws IOException {
70 return local.maxDoc();
73 public TopDocs search(Weight weight, Filter filter, int n) throws IOException {
74 return local.search(weight, filter, n);
77 public TopFieldDocs search(Weight weight, Filter filter, int n, Sort sort)
79 return local.search (weight, filter, n, sort);
82 public Document doc(int i) throws CorruptIndexException, IOException {
86 public Document doc(int i, FieldSelector fieldSelector) throws CorruptIndexException, IOException {
87 return local.doc(i, fieldSelector);
90 public Query rewrite(Query original) throws IOException {
91 return local.rewrite(original);
94 public Explanation explain(Weight weight, int doc) throws IOException {
95 return local.explain(weight, doc);
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;
103 if (args != null && args.length == 1)
106 if (indexName == null) {
107 System.out.println("Usage: org.apache.lucene.search.RemoteSearchable <index>");
111 // create and install a security manager
112 if (System.getSecurityManager() == null) {
113 System.setSecurityManager(new RMISecurityManager());
116 Searchable local = new IndexSearcher(FSDirectory.open(new File(indexName)), true);
117 RemoteSearchable impl = new RemoteSearchable(local);
119 // bind the implementation to "Searchable"
120 Naming.rebind("//localhost/Searchable", impl);