Changeset 12987


Ignore:
Timestamp:
2006-10-03T17:00:22+13:00 (16 years ago)
Author:
mdewsnip
Message:

You can now specify the query string as a command-line argument to GS2LuceneQuery.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java

    r12983 r12987  
    5555    {
    5656    if (args.length == 0) {
    57         System.out.println("Usage: GS2LuceneQuery <index directory> [-fuzziness value] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-startresults number -endresults number]");
     57        System.out.println("Usage: GS2LuceneQuery <index directory> [-fuzziness value] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-startresults number -endresults number] [query]");
    5858        return;
    5959    }
     
    6767        QueryParser query_parser_no_stop_words = new QueryParser(TEXTFIELD, new StandardAnalyzer(new String[] { }));
    6868
     69        String query_string = null;
     70
     71        // Parse the command-line arguments
    6972            for (int i = 1; i < args.length; i++) {
    7073        if (args[i].equals("-sort")) {
     
    9598            end_results = Integer.parseInt(args[i]);
    9699            }
     100        }
     101        else {
     102            query_string = args[i];
    97103        }
    98104        }
     
    104110        }
    105111
    106         BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
    107         while (true) {
    108         // Read the query from STDIN
    109         String query_string = in.readLine();
    110         if (query_string == null || query_string.length() == -1) {
    111             break;
    112         }
    113 
     112        // The query string has been specified as a command-line argument
     113        if (query_string != null) {
    114114        runQuery(searcher, reader, query_parser, query_parser_no_stop_words, query_string);
     115        }
     116
     117        // Read queries from STDIN
     118        else {
     119        BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
     120        while (true) {
     121            // Read the query from STDIN
     122            query_string = in.readLine();
     123            if (query_string == null || query_string.length() == -1) {
     124            break;
     125            }
     126
     127            runQuery(searcher, reader, query_parser, query_parser_no_stop_words, query_string);
     128        }
    115129        }
    116130    }
  • trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java

    r12983 r12987  
    5555    {
    5656    if (args.length == 0) {
    57         System.out.println("Usage: GS2LuceneQuery <index directory> [-fuzziness value] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-startresults number -endresults number]");
     57        System.out.println("Usage: GS2LuceneQuery <index directory> [-fuzziness value] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-startresults number -endresults number] [query]");
    5858        return;
    5959    }
     
    6767        QueryParser query_parser_no_stop_words = new QueryParser(TEXTFIELD, new StandardAnalyzer(new String[] { }));
    6868
     69        String query_string = null;
     70
     71        // Parse the command-line arguments
    6972            for (int i = 1; i < args.length; i++) {
    7073        if (args[i].equals("-sort")) {
     
    9598            end_results = Integer.parseInt(args[i]);
    9699            }
     100        }
     101        else {
     102            query_string = args[i];
    97103        }
    98104        }
     
    104110        }
    105111
    106         BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
    107         while (true) {
    108         // Read the query from STDIN
    109         String query_string = in.readLine();
    110         if (query_string == null || query_string.length() == -1) {
    111             break;
    112         }
    113 
     112        // The query string has been specified as a command-line argument
     113        if (query_string != null) {
    114114        runQuery(searcher, reader, query_parser, query_parser_no_stop_words, query_string);
     115        }
     116
     117        // Read queries from STDIN
     118        else {
     119        BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
     120        while (true) {
     121            // Read the query from STDIN
     122            query_string = in.readLine();
     123            if (query_string == null || query_string.length() == -1) {
     124            break;
     125            }
     126
     127            runQuery(searcher, reader, query_parser, query_parser_no_stop_words, query_string);
     128        }
    115129        }
    116130    }
Note: See TracChangeset for help on using the changeset viewer.