Locator: NIE Home / Publications / Enterprise Search Newsletter / Volume 2 Number 4 / Article 2:
Searching with the Ultraseek XPA Java API
By Miles Kehoe. - Volume 2 Number 4 - January 2005
In our first newsletter back in 2003, we provided a sample Windows Shell Script program to allow command line searching of Verity K2 collections.
Ultraseek, Verity's other search product line, is thought to be more of a web-based tool with a powerful and friendly browser-based console and search; but using the XPA Java library, you can access Ultraseek collections from within command line programs. This month we will show you how.
Now you're ready to get going. Copy the sample program listed in Figure 1 and save it as Search1.java. Note that Java is case sensitive, so be sure to save the file using the exact name specified in the "public class" statement just after the imports.
You'll also need to know the Ultraseek server name and port. You can discover these by firing up the Ultraseek Administrative Console shortcut in your browser and observing the system name and port you use to access the console. In Figure 1, the host name is titan and the port is the standard Ultraseek port 8765. Your host may be a fully qualified name, something like max.ideaeng.com.
/* A very simple Ultraseek XPA example, based loosely on Verity's SearchOneCollection example */ import java.io.*; import java.util.*; import com.ultraseek.xpa.search.*; import com.ultraseek.xpa.server.*; public class Search1 { // Null constructor Search1() { } // The entire demo runs in main() public static void main(String[] args) throws Exception { // We will be asking the user to type in queries InputStreamReader inputStreamReader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); // Change this to the name of your Ultraseek server String host = "titan"; // The default port for Ultraseek is 8765, so you can usually // leave this as is int port = 8765; System.out.println( "Using " + host + ':' + port ); UltraseekServer searchServer = new UltraseekServer(host,port); System.out.println("Remote Version: " + searchServer.getVersionString() ); System.out.println(); System.out.println("Enter searches; enter empty search to exit"); // Loop until done for (;;) { System.out.println(); System.out.print("search: "); String line = bufferedReader.readLine(); // Exit if we got a null or blank line if (line==null) break; if( line.trim().length() == 0 ) break; // Parse and Compile the query Query query = Query.parse(line); // Run the search SearchResultList searchResultList = searchServer.search(query); System.out.println(); // If we have some results if( !searchResultList.isEmpty() ) { Iterator iterator = searchResultList.iterator(); // Need try/catch to detect end of results list try { // For each matching document while (iterator.hasNext()) { SearchResult searchResult = (SearchResult)iterator.next(); // Print the score System.out.print( "" + searchResult.getScore() + " " ); // Print the title System.out.println( searchResult.getTitle() ); // - OR - // Print the URL // System.out.println( searchResult.getURL() ); } } catch (NoSuchElementException e) { // No more results from server, this is not an error } } else { // Else No results System.out.println( "No matches found" ); } } } }
Figure 1
@echo off set TARGET=Search1.java set MYCP=C:\Apps\Ultraseek53\lib\xpasearch.jar set JAVAC=javac "%JAVAC%" -classpath .;"%MYCP%" %TARGET%
Figure 2: COMPILE_SEARCH1.BAT
@echo off set TARGET=Search1 set MYCP=C:\Apps\Ultraseek53\lib\xpasearch.jar set JAVA=java "%JAVA%" -cp .;"%MYCP%" %TARGET%
Figure 3: RUN_SEARCH1.BAT
COMPILE_SEARCH1You should see no messages if the program compiles correctly. If you get any errors or messages, re-check your steps; check with someone in your organization who knows Java; or contact us at New Idea Engineering for help.
Once your code does compile, you're ready to run Figure 4 shows a session in our development labs:
RUN_SEARCH1 Using titan:8765 Remote Version: 5.3.1 Enter searches; enter empty search to exit search: xpa 0.42 Verity Ultraseek XPA ProgrammerĘs Guide 2.1 0.35999998 Verity Ultraseek Customization Guide 0.35999998 Verity Ultraseek Administrator Guide 0.29 Verity Ultraseek Installation Guide 0.29 Verity Ultraseek Implementation Guide search:null D:\Dev\ultra>The program prompts you for a query, here shown in bold. Ultraseek searches all active Ultraseek collections for the term. The results display on your screen. Enter a null search term to exit the program.Figire 4: Sample Session
That's it!
Reviewing The Steps
In preparing to use the sample program here, be sure to: