KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > search > RemoteSearchable


1 package org.apache.lucene.search;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.IOException JavaDoc;
20
21 import java.rmi.Naming JavaDoc;
22 import java.rmi.RemoteException JavaDoc;
23 import java.rmi.RMISecurityManager JavaDoc;
24 import java.rmi.server.UnicastRemoteObject JavaDoc;
25
26 import org.apache.lucene.document.Document;
27 import org.apache.lucene.index.Term;
28
29 /**
30  * A remote searchable implementation.
31  *
32  * @version $Id: RemoteSearchable.java 351472 2005-12-01 21:15:53Z bmesser $
33  */

34 public class RemoteSearchable
35   extends UnicastRemoteObject JavaDoc
36   implements Searchable {
37   
38   private Searchable local;
39   
40   /** Constructs and exports a remote searcher. */
41   public RemoteSearchable(Searchable local) throws RemoteException JavaDoc {
42     super();
43     this.local = local;
44   }
45   
46   // this implementation should be removed when the deprecated
47
// Searchable#search(Query,Filter,HitCollector) is removed
48
public void search(Query query, Filter filter, HitCollector results)
49     throws IOException JavaDoc {
50     local.search(query, filter, results);
51   }
52
53   public void search(Weight weight, Filter filter, HitCollector results)
54     throws IOException JavaDoc {
55     local.search(weight, filter, results);
56   }
57
58   public void close() throws IOException JavaDoc {
59     local.close();
60   }
61
62   public int docFreq(Term term) throws IOException JavaDoc {
63     return local.docFreq(term);
64   }
65
66
67   public int[] docFreqs(Term[] terms) throws IOException JavaDoc {
68     return local.docFreqs(terms);
69   }
70
71   public int maxDoc() throws IOException JavaDoc {
72     return local.maxDoc();
73   }
74
75   // this implementation should be removed when the deprecated
76
// Searchable#search(Query,Filter,int) is removed
77
public TopDocs search(Query query, Filter filter, int n) throws IOException JavaDoc {
78     return local.search(query, filter, n);
79   }
80
81   public TopDocs search(Weight weight, Filter filter, int n) throws IOException JavaDoc {
82     return local.search(weight, filter, n);
83   }
84
85   // this implementation should be removed when the deprecated
86
// Searchable#search(Query,Filter,int,Sort) is removed
87
public TopFieldDocs search (Query query, Filter filter, int n, Sort sort)
88     throws IOException JavaDoc {
89     return local.search (query, filter, n, sort);
90   }
91
92   public TopFieldDocs search (Weight weight, Filter filter, int n, Sort sort)
93   throws IOException JavaDoc {
94     return local.search (weight, filter, n, sort);
95   }
96
97   public Document doc(int i) throws IOException JavaDoc {
98     return local.doc(i);
99   }
100
101   public Query rewrite(Query original) throws IOException JavaDoc {
102     return local.rewrite(original);
103   }
104
105   // this implementation should be removed when the deprecated
106
// Searchable#explain(Query,int) is removed
107
public Explanation explain(Query query, int doc) throws IOException JavaDoc {
108     return local.explain(query, doc);
109   }
110
111   public Explanation explain(Weight weight, int doc) throws IOException JavaDoc {
112     return local.explain(weight, doc);
113   }
114
115   /** Exports a searcher for the index in args[0] named
116    * "//localhost/Searchable". */

117   public static void main(String JavaDoc args[]) throws Exception JavaDoc {
118     String JavaDoc indexName = null;
119     
120     if (args != null && args.length == 1)
121       indexName = args[0];
122     
123     if (indexName == null) {
124       System.out.println("Usage: org.apache.lucene.search.RemoteSearchable <index>");
125       return;
126     }
127     
128     // create and install a security manager
129
if (System.getSecurityManager() == null) {
130       System.setSecurityManager(new RMISecurityManager JavaDoc());
131     }
132     
133     Searchable local = new IndexSearcher(indexName);
134     RemoteSearchable impl = new RemoteSearchable(local);
135       
136     // bind the implementation to "Searchable"
137
Naming.rebind("//localhost/Searchable", impl);
138   }
139
140 }
141
Popular Tags