QueryResponses.cs, DumpIndex.cs, IQueryResult.cs, QueryExecutor.cs, QueryResult.cs...
[beagle.git] / beagled / Lucene.Net / Search / RemoteSearchable.cs
blob570b536d3da06f4aaa7b204b7a6de646bf35f598
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using System;
18 using Document = Lucene.Net.Documents.Document;
19 using Term = Lucene.Net.Index.Term;
21 namespace Lucene.Net.Search
24 /// <summary> A remote searchable implementation.
25 ///
26 /// </summary>
27 /// <version> $Id: RemoteSearchable.cs,v 1.4 2006/10/02 17:09:06 joeshaw Exp $
28 /// </version>
29 [Serializable]
30 public class RemoteSearchable : System.MarshalByRefObject, Lucene.Net.Search.Searchable
33 private Lucene.Net.Search.Searchable local;
35 /// <summary>Constructs and exports a remote searcher. </summary>
36 public RemoteSearchable(Lucene.Net.Search.Searchable local) : base()
38 this.local = local;
41 // this implementation should be removed when the deprecated
42 // Searchable#search(Query,Filter,HitCollector) is removed
43 public virtual void Search(Query query, Filter filter, HitCollector results)
45 local.Search(query, filter, results);
48 public virtual void Search(Weight weight, Filter filter, HitCollector results)
50 local.Search(weight, filter, results);
53 public virtual void Close()
55 local.Close();
58 public virtual int DocFreq(Term term)
60 return local.DocFreq(term);
64 public virtual int[] DocFreqs(Term[] terms)
66 return local.DocFreqs(terms);
69 public virtual int MaxDoc()
71 return local.MaxDoc();
74 // this implementation should be removed when the deprecated
75 // Searchable#search(Query,Filter,int) is removed
76 public virtual TopDocs Search(Query query, Filter filter, int n)
78 return local.Search(query, filter, n);
81 public virtual TopDocs Search(Weight weight, Filter filter, int n)
83 return local.Search(weight, filter, n);
86 // this implementation should be removed when the deprecated
87 // Searchable#search(Query,Filter,int,Sort) is removed
88 public virtual TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
90 return local.Search(query, filter, n, sort);
93 public virtual TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort)
95 return local.Search(weight, filter, n, sort);
98 public virtual Document Doc(int i)
100 return local.Doc(i);
103 public virtual Query Rewrite(Query original)
105 return local.Rewrite(original);
108 // this implementation should be removed when the deprecated
109 // Searchable#explain(Query,int) is removed
110 public virtual Explanation Explain(Query query, int doc)
112 return local.Explain(query, doc);
115 public virtual Explanation Explain(Weight weight, int doc)
117 return local.Explain(weight, doc);
120 public override System.Object InitializeLifetimeService()
122 long initialLeaseTime, sponsorshipTimeout, renewOnCallTime;
124 initialLeaseTime = SupportClass.AppSettings.Get("Lucene.Net.Remoting.Lifetime.initialLeaseTime", -1);
125 sponsorshipTimeout = SupportClass.AppSettings.Get("Lucene.Net.Remoting.Lifetime.sponsorshipTimeout", -1);
126 renewOnCallTime = SupportClass.AppSettings.Get("Lucene.Net.Remoting.Lifetime.renewOnCallTime", -1);
128 if ((initialLeaseTime == -1) || (sponsorshipTimeout == -1) || (renewOnCallTime == -1))
130 return null;
132 else
134 System.Runtime.Remoting.Lifetime.ILease lease =
135 (System.Runtime.Remoting.Lifetime.ILease) base.InitializeLifetimeService();
136 if (lease.CurrentState == System.Runtime.Remoting.Lifetime.LeaseState.Initial)
138 lease.InitialLeaseTime = System.TimeSpan.FromMinutes(initialLeaseTime);
139 lease.SponsorshipTimeout = System.TimeSpan.FromMinutes(sponsorshipTimeout);
140 lease.RenewOnCallTime = System.TimeSpan.FromSeconds(renewOnCallTime);
142 return lease;
146 /// <summary>Exports a searcher for the index in args[0] named
147 /// "//localhost/Searchable".
148 /// </summary>
149 [STAThread]
150 public static void Main(System.String[] args)
152 System.Runtime.Remoting.RemotingConfiguration.Configure("Lucene.Net.Search.RemoteSearchable.config");
153 System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Http.HttpChannel(1099));
154 System.String indexName = null;
156 if (args != null && args.Length == 1)
157 indexName = args[0];
159 if (indexName == null)
161 System.Console.Out.WriteLine("Usage: Lucene.Net.search.RemoteSearchable <index>");
162 return ;
165 // create and install a security manager
166 if (true) // if (System_Renamed.getSecurityManager() == null) // {{Aroush-1.4.3}} Do we need this line?!
168 // System_Renamed.setSecurityManager(new RMISecurityManager()); // {{Aroush-1.4.3}} Do we need this line?!
171 Lucene.Net.Search.Searchable local = new IndexSearcher(indexName);
172 RemoteSearchable impl = new RemoteSearchable(local);
174 // bind the implementation to "Searchable"
175 System.Runtime.Remoting.RemotingServices.Marshal(impl, "tcp://localhost:1099/Searchable");
176 System.Console.ReadLine();