lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 童小军 <tongxiao...@yikey.com>
Subject (this mail have My code!)Why use RMI search very slow! when have 13 TermQuery! Return cost 7500 ms .
Date Tue, 12 Jun 2007 02:19:43 GMT
I am use RMI search two server date! When I use one TermQuery return 30ms (very good)! But
when I use booleanQuery add tow termQuery return must 150 ms :(

And three is 250 ms? My query have 13 TermQuery! Return cost 7500 ms . 

How can I do it quick! Use ICE(Internet Communications Engine) ZeroC ?

 

/*

 * Created on Sep 8, 2005

 */

package com.feedsky.search.client;

 

import java.io.IOException;

import java.rmi.Naming;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.Vector;

 

import org.apache.lucene.analysis.SimpleAnalyzer;

import org.apache.lucene.index.Term;

import org.apache.lucene.queryParser.ParseException;

import org.apache.lucene.queryParser.QueryParser;

import org.apache.lucene.search.BooleanQuery;

import org.apache.lucene.search.Hits;

import org.apache.lucene.search.MultiSearcher;

import org.apache.lucene.search.Query;

import org.apache.lucene.search.RemoteSearchable;

import org.apache.lucene.search.Searchable;

import org.apache.lucene.search.TermQuery;

import org.apache.lucene.search.BooleanClause.Occur;

 

import com.feedsky.search.conf.ServerInfo;

import com.feedsky.search.conf.ServerInfoReader;

 

public class RemoteLuceneConnector {

         

     private RemoteSearchable[] remoteSearchers;

    

     public RemoteLuceneConnector(){

          makeRemoteSearchables();   

     } 

     

     public static void main(String[] args) {

          RemoteLuceneConnector rlc= new RemoteLuceneConnector();

          RemoteSearchable[] rs= rlc.getRemoteSearchers();

          

          try {

                            MultiSearcher multi = new MultiSearcher(rs);

                            long startTime =System.currentTimeMillis();

                            long runtime =0;

                            for (int i = 0; i < 10000; i++) {

                                     BooleanQuery query=new BooleanQuery();

                                     TermQuery termQuery=new TermQuery(new Term("itemContent","中国"));

                                     query.add(termQuery,Occur.MUST);

                                     TermQuery termQuery1=new TermQuery(new Term("itemContent","美国"));

                                     query.add(termQuery1,Occur.MUST);

                                     

                   TermQuery termQuery2=new TermQuery(new Term("itemContent","你好"));

                                     query.add(termQuery2,Occur.MUST);

                                     

                                     TermQuery termQuery3=new TermQuery(new Term("itemContent","日本"));

                                     query.add(termQuery3,Occur.MUST);

                                     

                                     TermQuery termQuery4=new TermQuery(new Term("itemContent","中国"));

                                     query.add(termQuery4,Occur.MUST);

                                     TermQuery termQuery5=new TermQuery(new Term("itemContent","天下"));

                                     query.add(termQuery5,Occur.MUST);

                                     TermQuery termQuery6=new TermQuery(new Term("itemContent","系列"));

                                     query.add(termQuery6,Occur.MUST);

                                     TermQuery termQuery7=new TermQuery(new Term("itemContent","你好"));

                                     query.add(termQuery7,Occur.MUST);

                                     TermQuery termQuery8=new TermQuery(new Term("itemContent","中国"));

                                     query.add(termQuery8,Occur.MUST);

                                     

                                     

                                     TermQuery termQuery9=new TermQuery(new Term("itemContent","中国"));

                                     query.add(termQuery9,Occur.MUST);

                                     TermQuery termQuery10=new TermQuery(new Term("itemContent","韩国"));

                                     query.add(termQuery10,Occur.MUST);

                                     TermQuery termQuery11=new TermQuery(new Term("itemContent","新加坡"));

                                     query.add(termQuery11,Occur.MUST);

                                     TermQuery termQuery12=new TermQuery(new Term("itemContent","台湾"));

                                     query.add(termQuery12,Occur.MUST);

                                     TermQuery termQuery13=new TermQuery(new Term("itemContent","中国"));

                                     query.add(termQuery13,Occur.MUST);

                                     //System.out.println(query.toString());

                                     QueryParser qp = new QueryParser("itemContent", new SimpleAnalyzer());

                                     try {

                                               Query query2 = qp.parse(query.toString());

                                     } catch (ParseException e) {

                                               // TODO Auto-generated catch block

                                               e.printStackTrace();

                                     }

                                     

                                     runtime=System.currentTimeMillis();

                                     Hits hits = multi.search(query);

                                     System.out.println("hits length = "+hits.length());

                                     System.out.println("runtime ="+(System.currentTimeMillis()-runtime));

                                     

                                     

                            }

                            long endTime =System.currentTimeMillis();

                            System.out.println("endTime = "+(endTime - startTime));

                            

                            

                   } catch (IOException e) {

                            // TODO Auto-generated catch block

                            e.printStackTrace();

                   }

 

          System.out.println(rs);

         }

         

 

     /**

     * <p>create remoteSearchables  

     */

     private synchronized void makeRemoteSearchables(){       

             ServerInfoReader serverInfoReader = new ServerInfoReader();

 

             ArrayList searcherList = serverInfoReader.getNameList();       

             

             if (searcherList!=null) System.out.println("Number of Machines=" + searcherList.size());

             

             Vector v = new Vector(); 

             //int index=0;

                   for ( Iterator i=searcherList.iterator(); i.hasNext(); )

                   {   

                 ServerInfo serverInfo = (ServerInfo)i.next();

                 

                 String machinename= "//" + serverInfo.getIpAddr() + ":" + serverInfo.getPortNum()
+ "/searchable";

                 //String machinename= "//" + serverInfo.getIpAddr() + ":" + serverInfo.getPortNum()
+ "/luceneindex";

                 System.out.println("Machine: " + machinename);

                 

                 try{

                 Searchable s = (Searchable)Naming.lookup(machinename);           

                           RemoteSearchable searcher = new RemoteSearchable(s);

                           v.add(searcher);

                           

                 }catch(Exception ee){ 

                 ee.printStackTrace();

                 System.out.println("Exception in getting Remote Object: " + ee.getMessage());

                 }

                   }        

                   remoteSearchers = new RemoteSearchable[v.size()];

                   for(int i = 0; i < remoteSearchers.length; i++)

                            remoteSearchers[i] = (RemoteSearchable)v.get(i);

 

     }

 

    public RemoteSearchable[] getRemoteSearchers(){

            makeRemoteSearchables();

           return remoteSearchers;

    }

   

}

 

Thank you very much !

 

xiaojun tong

 

010-64489518-613

tongxiaojun@msn.com

www.feedsky.com

 

 

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message