Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 51800 invoked from network); 23 May 2007 19:53:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 May 2007 19:53:20 -0000 Received: (qmail 83361 invoked by uid 500); 23 May 2007 19:53:19 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 82999 invoked by uid 500); 23 May 2007 19:53:17 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 82987 invoked by uid 99); 23 May 2007 19:53:17 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 May 2007 12:53:17 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [64.56.150.16] (HELO mail.globaldesigns.ca) (64.56.150.16) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 May 2007 12:53:08 -0700 Received: from 192.168.0.100 [72.29.233.189] by mail.globaldesigns.ca with ESMTP (SMTPD-8.22) id AB8F0298; Wed, 23 May 2007 13:52:47 -0600 Subject: Who has sample code of remote multiple servers multiple indexes searching? From: "Su.Cheng" To: java-user@lucene.apache.org Content-Type: text/plain Date: Wed, 23 May 2007 13:52:47 -0600 Message-Id: <1179949967.26630.6.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-8) Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hi, I studied "5.6 Searching across multiple Lucene indexes 178" in <>. I have 2 remote serarch computers(SearchServer) work as index servers and search requests from a search client(SearchClient,the 3rd computer). An error message, "Exception in thread "main" java.rmi.UnmarshalException", was thrown out. Does someone can explain with sample code about multiple-index servers and multiple indexes in single server? Thanks. Below are the source code: ////////////////SearchServer.java///////////////////// import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.ParallelMultiSearcher; import org.apache.lucene.search.RemoteSearchable; import org.apache.lucene.search.Searchable; import org.apache.lucene.search.Searcher; import org.apache.lucene.search.MultiSearcher; import java.io.File; import java.io.IOException; import java.rmi.Naming; import java.rmi.registry.LocateRegistry; public class SearchServer { private static final String m_disk1="/usr/local/eBingBong/"; //English private static final String m_disk2="/backup/eBingBong/"; //other languages private static Searchable []m_searchables; public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: SearchServer "); System.err.println("java -Xms1000m -Xmx2000m SearchServer 161"); System.exit(-1); } FindIndex(); LocateRegistry.createRegistry(1099); Searcher multiSearcher = new MultiSearcher(m_searchables); RemoteSearchable multiImpl = new RemoteSearchable(multiSearcher); //Naming.rebind("//192.168.10.175/LIA_Multi", multiImpl); Naming.rebind("//192.168.10." +args[0] + "/LIA_Multi", multiImpl); Searcher parallelSearcher = new ParallelMultiSearcher (m_searchables); RemoteSearchable parallelImpl = new RemoteSearchable (parallelSearcher); //Naming.rebind("//192.168.10.175/LIA_Parallel", parallelImpl); Naming.rebind("//192.168.10." + args[0] + "/LIA_Parallel", parallelImpl); System.out.println("Server started"); } private static void FindIndex() { File []file=new File[10]; File tmpFile; int i=0; tmpFile=new File(m_disk1,"english"); if(tmpFile.exists()) file[i+ +]=tmpFile; tmpFile=new File(m_disk2,"chinese"); if(tmpFile.exists()) file[i+ +]=tmpFile; tmpFile=new File(m_disk2,"japanese"); if(tmpFile.exists()) file[i+ +]=tmpFile; tmpFile=new File(m_disk2,"korean"); if(tmpFile.exists()) file[i+ +]=tmpFile; tmpFile=new File(m_disk2,"czech"); if(tmpFile.exists()) file[i+ +]=tmpFile; tmpFile=new File(m_disk2,"german"); if(tmpFile.exists()) file[i+ +]=tmpFile; tmpFile=new File(m_disk2,"greek"); if(tmpFile.exists()) file[i+ +]=tmpFile; tmpFile=new File(m_disk2,"french"); if(tmpFile.exists()) file[i+ +]=tmpFile; tmpFile=new File(m_disk2,"dutch"); if(tmpFile.exists()) file[i+ +]=tmpFile; tmpFile=new File(m_disk2,"russian"); if(tmpFile.exists()) file[i+ +]=tmpFile; m_searchables = new Searchable[i]; for (int j = 0; j < i; j++) { try { m_searchables[j] = new IndexSearcher(file[j].getAbsolutePath()); } catch(IOException e) {} System.out.println(file[j].getAbsolutePath()); } } } /////////////////////////SearchClient.java/////////////////////// import org.apache.lucene.document.Document; import org.apache.lucene.index.Term; import org.apache.lucene.search.Hits; import org.apache.lucene.search.MultiSearcher; import org.apache.lucene.search.ParallelMultiSearcher; import org.apache.lucene.search.Searchable; import org.apache.lucene.search.TermQuery; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.search.Query; import org.apache.lucene.queryParser.QueryParser; import java.rmi.Naming; import java.util.Date; import java.util.HashMap; public class SearchClient { private static HashMap searcherCache = new HashMap(); private static String[] m_args; public static void main(String[] args) throws Exception { m_args=args; if (args.length < 2) { System.err.println("Usage: SearchClient <...>"); System.err.println("java -Xms1000m -Xmx2000m SearchClient oil 161 163"); System.exit(-1); } String word = args[0]; // warm up the VM with several of each search for (int i=0; i < 5; i++) { search("LIA_Multi", word); search("LIA_Parallel", word); } } private static void search(String name, String word) throws Exception { //TermQuery query = new TermQuery(new Term("contents", word));//content //contents QueryParser parser=new QueryParser("content",new StandardAnalyzer ()); //parser.setOperator(QueryParser.DEFAULT_OPERATOR_AND); parser.setDefaultOperator(QueryParser.AND_OPERATOR); Query query = parser.parse(word); System.out.println(query.toString()); //MultiSearcher searcher = (MultiSearcher) searcherCache.get (name); ParallelMultiSearcher searcher = (ParallelMultiSearcher) searcherCache.get(name); if (searcher == null) { int serverSum=m_args.length-1; Searchable []remoteSearch=new Searchable[serverSum]; //remoteSearch[0]=lookupRemote("//192.168.10.156/",name); //remoteSearch[1]=lookupRemote("//192.168.10.175/",name); for(int suc=0; suc"); return; } else System.out.println("hit="+hits.length()); //for (int i = 0; i < hits.length(); i++) { for (int i = 0; i < 3; i++) { Document doc = hits.doc(i); //java.io.InvalidClassException: org.apache.lucene.document.Document; //String[] values = doc.getValues("syn"); //for (int j = 0; j < values.length; j++) { //System.out.print(values[j] + " "); System.out.println(doc.get("url")+"\n"); } System.out.println(hits.length()); //System.out.println(); // DO NOT CLOSE searcher! } private static Searchable lookupRemote(String IP, String name) throws Exception { return (Searchable) Naming.lookup(IP + name); } } -- Su.Cheng --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org