FAQ
Hi,
I studied "5.6 Searching across multiple Lucene indexes 178" in <<Lucene
in action>>.

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 <IP>");
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 <query> <IP1> <IP2>
<...>");
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<serverSum; suc++) remoteSearch[suc]=lookupRemote
("//192.168.10."+m_args[suc+1]+"/",name);

//searcher = new MultiSearcher(remoteSearch);
searcher = new ParallelMultiSearcher(remoteSearch);
searcherCache.put(name, searcher);
}

long begin = new Date().getTime();
Hits hits = searcher.search(query);
long end = new Date().getTime();

System.out.println("Searched " + name +
" for '" + word + "' (" + (end - begin) + " ms): ");

if (hits.length() == 0) {
System.out.print("<NONE FOUND>");
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 <su.cheng@playstarmusic.com>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org

Search Discussions

  • Su.Cheng at May 24, 2007 at 5:05 pm
    Hi,

    I found the problem. The version of Lucene on server is 2.1 while on
    client is 1.9.

    Thanks

    On Wed, 2007-05-23 at 13:52 -0600, Su.Cheng wrote:
    Hi,
    I studied "5.6 Searching across multiple Lucene indexes 178" in <<Lucene
    in action>>.

    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 <IP>");
    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 <query> <IP1> <IP2>
    <...>");
    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<serverSum; suc++) remoteSearch[suc]=lookupRemote
    ("//192.168.10."+m_args[suc+1]+"/",name);

    //searcher = new MultiSearcher(remoteSearch);
    searcher = new ParallelMultiSearcher(remoteSearch);
    searcherCache.put(name, searcher);
    }

    long begin = new Date().getTime();
    Hits hits = searcher.search(query);
    long end = new Date().getTime();

    System.out.println("Searched " + name +
    " for '" + word + "' (" + (end - begin) + " ms): ");

    if (hits.length() == 0) {
    System.out.print("<NONE FOUND>");
    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 <su.cheng@playstarmusic.com>


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedMay 23, '07 at 7:53p
activeMay 24, '07 at 5:05p
posts2
users1
websitelucene.apache.org

1 user in discussion

Su.Cheng: 2 posts

People

Translate

site design / logo © 2022 Grokbase