/* * $Id: test.java 2876 2011-07-08 15:23:04Z tomat $ */ package org.sphx.api; import java.util.*; /** * Test class for sphinx API */ public class test { public static void main ( String[] argv ) throws SphinxException { if ( argv==null || argv.length<1 ) { System.out.print ( "Usage: java -jar sphinxapi.jar [OPTIONS] query words\n\n" ); System.out.print ( "Options are:\n" ); System.out.print ( "-h, --host \tconnect to searchd at host HOST\n" ); System.out.print ( "-p, --port\t\tconnect to searchd at port PORT\n" ); System.out.print ( "-i, --index \tsearch through index(es) specified by IDX\n" ); System.out.print ( "-s, --sortby \tsort matches by 'CLAUSE' in sort_extended mode\n" ); System.out.print ( "-S, --sortexpr \tsort matches by 'EXPR' DESC in sort_expr mode\n" ); System.out.print ( "-a, --any\t\tuse 'match any word' matching mode\n" ); System.out.print ( "-b, --boolean\t\tuse 'boolean query' matching mode\n" ); System.out.print ( "-e, --extended\t\tuse 'extended query' matching mode\n" ); System.out.print ( "-ph,--phrase\t\tuse 'exact phrase' matching mode\n" ); // System.out.print ( "-f, --filter \tfilter by attribute 'ATTR' (default is 'group_id')\n" ); // System.out.print ( "-v, --value \tadd VAL to allowed 'group_id' values list\n" ); System.out.print ( "-g, --groupby \tgroup matches by 'EXPR'\n" ); System.out.print ( "-gs,--groupsort \tsort groups by 'EXPR'\n" ); // System.out.print ( "-d, --distinct \tcount distinct values of 'ATTR''\n" ); System.out.print ( "-l, --limit \tretrieve COUNT matches (default: 20)\n" ); System.out.print ( "-ga, --geoanchor \n" ); System.out.print ( "\t\t\tset anchor for geodistance\n" ); System.out.print ( "--select \tselect the listed expressions only\n" ); System.exit ( 0 ); } StringBuffer q = new StringBuffer(); String host = "localhost"; int port = 9312; int mode = SphinxClient.SPH_MATCH_ALL; String index = "*"; int offset = 0; int limit = 20; int sortMode = SphinxClient.SPH_SORT_RELEVANCE; String sortClause = ""; String groupBy = ""; String groupSort = ""; SphinxClient cl = new SphinxClient(); /* parse arguments */ if ( argv!=null) for ( int i=0; i0 ) cl.SetGroupBy ( groupBy, SphinxClient.SPH_GROUPBY_ATTR, groupSort ); SphinxResult res = cl.Query(q.toString(), index); if ( res==null ) { System.err.println ( "Error: " + cl.GetLastError() ); System.exit ( 1 ); } if ( cl.GetLastWarning()!=null && cl.GetLastWarning().length()>0 ) System.out.println ( "WARNING: " + cl.GetLastWarning() + "\n" ); /* 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