FileDocCategorySizeDatePackage
ConsoleSearch.javaAPI DocExample3763Mon Mar 01 16:32:06 GMT 2004com.develop.ss

ConsoleSearch

public class ConsoleSearch extends Object

Fields Summary
Constructors Summary
Methods Summary
private static booleancheckArgs(java.lang.String[] args)

        if(args.length < 2)
        {
            if(args.length > 0)
            {
                if(args[0].startsWith("/i") || args[0].startsWith("/?"))
                {
                    return true;
                }
            }
            else
            {
                return true;
            }
        }
        return false;
    
private static voiddoIndex(java.lang.String indexflag)

        try
            {

            ConfigBean config = new ConfigBean();
            String nextIndex;
            try
            {
               nextIndex = config.getNextIndexPath();
            }
            catch(Exception ex)
            {
                return;
            }

            IndexLinks lts = new IndexLinks(nextIndex, config.getMaxLinks(), config.getSkippedLinksFile());
            lts.initFollowPrefixesFromSystemProperties();
            lts.initAvoidPrefixesFromSystemProperties();
            lts.setAvoidPrefixes(config.getAvoidLinks().split(" "));
            lts.setInitialLink(indexflag);

            config.flipIndexPath();

            }
            catch(Exception e)
            {
                //System.out.print(e.getStackTrace());
            }
    
private static java.lang.StringgetIndexFlag(java.lang.String[] args)

      for(int i=0;i<args.length;i++)
      {
          if(args[i].startsWith("/i:"))
          {
              return args[i].substring(3, args[i].length());
          }
      }
      return "";
    
public static voidmain(java.lang.String[] args)

        // get configured index path from IndexPathBean
        ConfigBean config = new ConfigBean();
        String indexPath = config.getCurIndexPath();
        if(indexPath == "") return;

        // check args for index flag, retrieve initial page, execute index
        if(!checkArgs(args)) {
            writeUsage();
            return;
        }

        String indexInitialPage = getIndexFlag(args);
        if(indexInitialPage != "")
        {
            doIndex(indexInitialPage);
            return;
        }

        // Allow multiple queries from command line
        BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
        try {
             while (true) {
              System.out.print("Query: ");
              String line = rdr.readLine();
                if (line.length() == 0) {
                  break;
                }
             QueryBean query = new QueryBean(indexPath, line, "contents");
             query.execute();
             HitBean[] hits = query.getResults();
             for(int i = 0;i<hits.length;i++)
             {
                 System.out.println(hits[i].getScoreAsString() + " " + hits[i].getUrl());
             }
             }
        }
        catch(Exception e)
        {
             e.printStackTrace();
        }
    
private static voidwriteUsage()

        System.out.println("Usage: java ConsoleSearch");
        System.out.println(" -- /i:http://YOUR_INITIAL_INDEX_PATH");
        System.out.println(" -- /?:show this message");