Methods Summary |
---|
private static org.apache.lucene.search.Searchable | getRemote()
try {
return lookupRemote();
} catch (Throwable e) {
startServer();
return lookupRemote();
}
|
private static org.apache.lucene.search.Searchable | lookupRemote()
return (Searchable)Naming.lookup("//localhost/Searchable");
|
private static void | search(org.apache.lucene.search.Query query)
// try to search the published index
Searchable[] searchables = { getRemote() };
Searcher searcher = new MultiSearcher(searchables);
Hits result = searcher.search(query);
assertEquals(1, result.length());
assertEquals("test text", result.doc(0).get("test"));
|
private static void | startServer()
// 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 text"));
writer.addDocument(doc);
writer.optimize();
writer.close();
// publish it
LocateRegistry.createRegistry(1099);
Searchable local = new IndexSearcher(indexStore);
RemoteSearchable impl = new RemoteSearchable(local);
Naming.rebind("//localhost/Searchable", impl);
|
public void | testBooleanQuery()
BooleanQuery query = new BooleanQuery();
query.add(new TermQuery(new Term("test", "test")), true, false);
search(query);
|
public void | testPhraseQuery()
PhraseQuery query = new PhraseQuery();
query.add(new Term("test", "test"));
query.add(new Term("test", "text"));
search(query);
|
public void | testQueryFilter()
// try to search the published index
Searchable[] searchables = { getRemote() };
Searcher searcher = new MultiSearcher(searchables);
Hits hits = searcher.search(
new TermQuery(new Term("test", "text")),
new QueryFilter(new TermQuery(new Term("test", "test"))));
Hits nohits = searcher.search(
new TermQuery(new Term("test", "text")),
new QueryFilter(new TermQuery(new Term("test", "non-existent-term"))));
assertEquals(0, nohits.length());
|
public void | testTermQuery()
search(new TermQuery(new Term("test", "test")));
|