Changeset 12275


Ignore:
Timestamp:
2006-07-21T17:23:04+12:00 (18 years ago)
Author:
mdewsnip
Message:

Added a command-line option for sorting the search results.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/lucene_query.pl

    r12258 r12275  
    5252sub open_java_lucene
    5353{
    54     my ($full_indexdir, $out_file) = @_;
     54    my $full_indexdir = shift(@_);
     55    my $sort_field = shift(@_) || "";
     56    my $out_file = shift(@_);
    5557    my $bin_java = &util::filename_cat($ENV{'GSDLHOME'},"bin","java");
    5658    my $classpath = &util::filename_cat($bin_java,"LuceneWrap.jar");
     
    6466    $out_file = "";
    6567    }
    66     if (!open (PIPEOUT, "| $java_cmd \"$full_indexdir\" $out_file")) {
     68    if (!open (PIPEOUT, "| $java_cmd \"$full_indexdir\" $sort_field")) {
    6769    die "$PROGNAME - couldn't run $java_cmd\n";
    6870    }
    69 
    7071}
    7172
     
    8283    my $full_indexdir;
    8384    my $query = undef;
     85    my $sort_field = undef;
    8486    my $out_file = undef;
    85     if ($argc==1) {
     87    if ($argc == 0) {
     88    print STDERR "Usage: $PROGNAME full-index-dir [query] [sort_field] [outfile]\n";
     89    exit 1;
     90    }
     91    if ($argc >= 1) {
    8692    $full_indexdir = $argv[0];
    8793    }
    88     elsif ($argc==2) {
    89     $full_indexdir = $argv[0];
     94    if ($argc >= 2) {
    9095    $query = $argv[1];
    9196    }
    92     elsif  ($argc==3) {
    93     $full_indexdir = $argv[0];
    94     $query = $argv[1];
    95     $out_file = $argv[2];
     97    if ($argc >= 3) {
     98    $sort_field = $argv[2];
    9699    }
    97     else {
    98     print STDERR "Usage: $PROGNAME full-index-dir [query] [outfile]\n";
    99     exit 1;
     100    if ($argc >= 4) {
     101    $out_file = $argv[3];
    100102    }
    101     open_java_lucene($full_indexdir, $out_file);
     103    open_java_lucene($full_indexdir, $sort_field, $out_file);
    102104
    103105    if (defined $query) {
  • trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java

    r12261 r12275  
    2424import org.apache.lucene.search.Query;
    2525import org.apache.lucene.search.Searcher;
     26import org.apache.lucene.search.Sort;
    2627
    2728
     
    3132    {
    3233    if (args.length == 0) {
    33         System.out.println("Usage: GS2LuceneQuery <index directory>");
     34        System.out.println("Usage: GS2LuceneQuery <index directory> (<sort field>)");
    3435        return;
    3536    }
     
    3738        try {
    3839        Searcher searcher = new IndexSearcher(args[0]);
     40        Sort sorter = new Sort();
     41        if (args.length > 1) {
     42        sorter = new Sort(args[1]);
     43        }
    3944        Analyzer analyzer = new StandardAnalyzer();
    4045        IndexReader reader = ((IndexSearcher) searcher).getIndexReader();
     
    5560
    5661        // Perform the query
    57         Hits hits = searcher.search(query);
     62        Hits hits = searcher.search(query, sorter);
    5863        System.out.println("<ResultSet>");
    5964        System.out.println("  <QueryString>" + query_string + "</QueryString>");
  • trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java

    r12261 r12275  
    2424import org.apache.lucene.search.Query;
    2525import org.apache.lucene.search.Searcher;
     26import org.apache.lucene.search.Sort;
    2627
    2728
     
    3132    {
    3233    if (args.length == 0) {
    33         System.out.println("Usage: GS2LuceneQuery <index directory>");
     34        System.out.println("Usage: GS2LuceneQuery <index directory> (<sort field>)");
    3435        return;
    3536    }
     
    3738        try {
    3839        Searcher searcher = new IndexSearcher(args[0]);
     40        Sort sorter = new Sort();
     41        if (args.length > 1) {
     42        sorter = new Sort(args[1]);
     43        }
    3944        Analyzer analyzer = new StandardAnalyzer();
    4045        IndexReader reader = ((IndexSearcher) searcher).getIndexReader();
     
    5560
    5661        // Perform the query
    57         Hits hits = searcher.search(query);
     62        Hits hits = searcher.search(query, sorter);
    5863        System.out.println("<ResultSet>");
    5964        System.out.println("  <QueryString>" + query_string + "</QueryString>");
Note: See TracChangeset for help on using the changeset viewer.