cutting 2002/08/15 16:44:00 Modified: src/java/org/apache/lucene/search BooleanClause.java src/test/org/apache/lucene/search TestRemoteSearchable.java Log: Fixed a bug serializing BooleanQuery and added test code. Revision Changes Path 1.4 +1 -1 jakarta-lucene/src/java/org/apache/lucene/search/BooleanClause.java Index: BooleanClause.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/BooleanClause.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- BooleanClause.java 17 Jul 2002 17:38:04 -0000 1.3 +++ BooleanClause.java 15 Aug 2002 23:44:00 -0000 1.4 @@ -55,7 +55,7 @@ */ /** A clause in a BooleanQuery. */ -public class BooleanClause { +public class BooleanClause implements java.io.Serializable { /** The query whose matching documents are combined by the boolean query. */ public Query query; /** If true, documents documents which <i>do not</i> 1.3 +33 -14 jakarta-lucene/src/test/org/apache/lucene/search/TestRemoteSearchable.java Index: TestRemoteSearchable.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/search/TestRemoteSearchable.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TestRemoteSearchable.java 17 Jul 2002 22:11:34 -0000 1.2 +++ TestRemoteSearchable.java 15 Aug 2002 23:44:00 -0000 1.3 @@ -56,6 +56,7 @@ import java.rmi.Naming; import java.rmi.RemoteException; +import java.rmi.NotBoundException; import java.rmi.registry.LocateRegistry; import junit.framework.TestCase; @@ -72,12 +73,25 @@ super(name); } - public static void startServer() throws Exception { + private static Searchable getRemote() throws Exception { + try { + return lookupRemote(); + } catch (Throwable e) { + startServer(); + return lookupRemote(); + } + } + + private static Searchable lookupRemote() throws Exception { + return (Searchable)Naming.lookup("//localhost/Searchable"); + } + + private static void startServer() throws Exception { // construct an index RAMDirectory indexStore = new RAMDirectory(); IndexWriter writer = new IndexWriter(indexStore,new SimpleAnalyzer(),true); Document doc = new Document(); - doc.add(Field.Text("test", "test")); + doc.add(Field.Text("test", "test text")); writer.addDocument(doc); writer.optimize(); writer.close(); @@ -89,26 +103,31 @@ Naming.rebind("//localhost/Searchable", impl); } - public static void search() throws Exception { + public static void search(Query query) throws Exception { // try to search the published index - Searchable remote = (Searchable)Naming.lookup("//localhost/Searchable"); - Searchable[] searchables = {remote}; + Searchable[] searchables = { getRemote() }; Searcher searcher = new MultiSearcher(searchables); - Query query = new TermQuery(new Term("test", "test")); Hits result = searcher.search(query); assertEquals(1, result.length()); - assertEquals("test", result.doc(0).get("test")); + assertEquals("test text", result.doc(0).get("test")); } - public void testRemoteSearch() throws Exception { - startServer(); - search(); + public void testTermQuery() throws Exception { + search(new TermQuery(new Term("test", "test"))); } - public static void main(String[] args) throws Exception { - startServer(); - search(); - System.exit(0); + public void testBooleanQuery() throws Exception { + BooleanQuery query = new BooleanQuery(); + query.add(new TermQuery(new Term("test", "test")), true, false); + search(query); } + + public void testPhraseQuery() throws Exception { + PhraseQuery query = new PhraseQuery(); + query.add(new Term("test", "test")); + query.add(new Term("test", "text")); + search(query); + } + }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>