/* * $Id$ */ package org.sphx.api; import java.util.*; /** * Test class for sphinx API */ public class test { private static final int RESULT_LIMIT = 20; private static final int MAX_RESULTS = 1000; public static void main ( String[] argv ) throws SphinxException { if ( argv==null || argv.length<2 ) { System.out.println ( "usage: test [-a] [-g ] [-p ] [-h ] [-i ] [-e] [-b]" ); System.out.println ( "or: test [-any] [--group ] [--port ] [--host ] [--index ] [--extended] [--boolean]\n" ); } StringBuffer q = new StringBuffer(); String host = "localhost"; int port = 3312; int mode = SphinxClient.SPH_MATCH_ALL; Set groups = new LinkedHashSet(); String index = "*"; int offset = 0; /* parse arguments */ if ( argv!=null) for ( int i=0; i0 ) { int[] groupList = new int[groups.size()]; String group = null; int i = 0; try { for (Iterator e = groups.iterator(); e.hasNext(); i++) { group = (String) e.next(); groupList[i] = Integer.parseInt(group); } } catch (Exception ex) { System.out.println("Groups must be integer. Failed to convert group " + group); return; } cl.SetFilter("group_id", groupList, false); } SphinxResult res = cl.Query(q.toString(), index); if (res == null || (cl.GetLastError() != null && cl.GetLastError().length() > 0)) { System.err.println("Error: " + cl.GetLastError()); System.exit(1); } /* print me out */ System.out.println ( "Query '" + q + "' retrieved " + res.total + " of " + res.totalFound + " matches in " + res.time + " sec." ); System.out.println ( "Query stats:" ); for ( int i=0; i