001: package org.apache.lucene.search;
002:
003: /**
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: import org.apache.lucene.document.Document;
021: import org.apache.lucene.document.FieldSelector;
022: import org.apache.lucene.index.Term;
023: import org.apache.lucene.index.CorruptIndexException;
024:
025: import java.io.IOException;
026: import java.rmi.Naming;
027: import java.rmi.RMISecurityManager;
028: import java.rmi.RemoteException;
029: import java.rmi.server.UnicastRemoteObject;
030:
031: /**
032: * A remote searchable implementation.
033: *
034: * @version $Id: RemoteSearchable.java 514675 2007-03-05 14:28:01Z gsingers $
035: */
036: public class RemoteSearchable extends UnicastRemoteObject implements
037: Searchable {
038:
039: private Searchable local;
040:
041: /** Constructs and exports a remote searcher. */
042: public RemoteSearchable(Searchable local) throws RemoteException {
043: super ();
044: this .local = local;
045: }
046:
047: public void search(Weight weight, Filter filter,
048: HitCollector results) throws IOException {
049: local.search(weight, filter, results);
050: }
051:
052: public void close() throws IOException {
053: local.close();
054: }
055:
056: public int docFreq(Term term) throws IOException {
057: return local.docFreq(term);
058: }
059:
060: public int[] docFreqs(Term[] terms) throws IOException {
061: return local.docFreqs(terms);
062: }
063:
064: public int maxDoc() throws IOException {
065: return local.maxDoc();
066: }
067:
068: public TopDocs search(Weight weight, Filter filter, int n)
069: throws IOException {
070: return local.search(weight, filter, n);
071: }
072:
073: public TopFieldDocs search(Weight weight, Filter filter, int n,
074: Sort sort) throws IOException {
075: return local.search(weight, filter, n, sort);
076: }
077:
078: public Document doc(int i) throws CorruptIndexException,
079: IOException {
080: return local.doc(i);
081: }
082:
083: public Document doc(int i, FieldSelector fieldSelector)
084: throws CorruptIndexException, IOException {
085: return local.doc(i, fieldSelector);
086: }
087:
088: public Query rewrite(Query original) throws IOException {
089: return local.rewrite(original);
090: }
091:
092: public Explanation explain(Weight weight, int doc)
093: throws IOException {
094: return local.explain(weight, doc);
095: }
096:
097: /** Exports a searcher for the index in args[0] named
098: * "//localhost/Searchable". */
099: public static void main(String args[]) throws Exception {
100: String indexName = null;
101:
102: if (args != null && args.length == 1)
103: indexName = args[0];
104:
105: if (indexName == null) {
106: System.out
107: .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(indexName);
117: RemoteSearchable impl = new RemoteSearchable(local);
118:
119: // bind the implementation to "Searchable"
120: Naming.rebind("//localhost/Searchable", impl);
121: }
122:
123: }
|