Science With the Virtual Observatory |
Our stub function looks like this:
public static SimpleResource[] keywordSearch(String keywords)
throws ServiceException, RemoteException
{
String query = ""; //
String keyword;
StringTokenizer st = new StringTokenizer(keywords);
while (st.hasMoreTokens()) {
keyword = st.nextToken();
// add in our constraints to the query
}
System.err.println("Registry query: " + query); //
// submit our query
return null;
}
We can start by setting our base query. Change:
String query = "";
to:
String query = "ServiceType like '%CONE%'";
The while loop that is already in the stub parses out each word
and sets it to keyword. For each keyword, we want it to
match any of a selected set of text metadata. The constraint for each
word then might look something like this, place just after keyword is
set:
String constraint = "Title like '%" + keyword + "%' or " +
"ShortName like '%" + keyword + "' or "
You could add any other attributes (e.g. Description, Subject, etc.).
In this implementation, we will require that all given keywords be matched somewhere. So we add each keyword constraint to the query with the following:
query += " and (" + constraint + ")";
Now we're ready to submit the query. This is done in exactly the
same way we did it in the search() method, so we can just
cut and paste the remaining code in (replacing the return
null):
// get a registry service object Registry regService = new RegistryLocator(); // get an interface object that can accept our query. RegistrySoap regInterface = regService.getRegistrySoap(); // Now submit the query ArrayOfSimpleResource results = regInterface.queryRegistry(query); // return all of the results return results.getSimpleResource();
You are done.
The NVO Summer School is made possible through the support of the National Science Foundation and the National Aeronautics and Space Administration.
![]() |