Changeset 12364


Ignore:
Timestamp:
2006-08-01T11:33:37+12:00 (18 years ago)
Author:
mdewsnip
Message:

Now uses the t variable to control whether a "some" or "all" search is done with Lucene. Many thanks to John Thompson and DL Consulting Ltd.

Location:
trunk
Files:
5 edited

Legend:

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

    r12275 r12364  
    5353{
    5454    my $full_indexdir = shift(@_);
    55     my $sort_field = shift(@_) || "";
    56     my $out_file = shift(@_);
     55    my $sort_field = 0;
     56    my $dco = 0;
     57    my $out_file = 0;
     58    for ($i = 0; $i < scalar(@_); $i++)
     59      {
     60        if ($_[$i] eq "-sort")
     61          {
     62            $i++;
     63            $sort_field = $_[$i];
     64          }
     65        elsif ($_[$i] eq "-dco")
     66          {
     67            $i++;
     68            $dco = $_[$i];
     69          }
     70        else
     71          {
     72            $out_file = $_[$i];
     73          }
     74      }
     75
     76
    5777    my $bin_java = &util::filename_cat($ENV{'GSDLHOME'},"bin","java");
    5878    my $classpath = &util::filename_cat($bin_java,"LuceneWrap.jar");
     
    6686    $out_file = "";
    6787    }
    68     if (!open (PIPEOUT, "| $java_cmd \"$full_indexdir\" $sort_field")) {
     88
     89    my $cmd = "| " . $java_cmd . " \"" . $full_indexdir . "\"";
     90    if ($sort_field)
     91      {
     92        $cmd .= " -sort " . $sort_field;
     93      }
     94    if ($dco)
     95      {
     96        $cmd .= " -dco " . $dco;
     97      }
     98
     99    print STDERR $cmd . "\n";
     100
     101    if (!open (PIPEOUT, $cmd)) {
    69102    die "$PROGNAME - couldn't run $java_cmd\n";
    70103    }
  • trunk/gsdl/src/colservr/lucenesearch.cpp

    r12276 r12364  
    8484}
    8585
    86 
    8786bool lucenesearchclass::search(const queryparamclass &queryparams,
    8887                   queryresultsclass &queryresult) {
     
    107106  }
    108107 
    109   // set default Boolean combiner from all/some setting
    110   // if match_mode == 1, ie all, default=1 ie AND
    111   // if match_mode == 0, ie some, default=0, ie OR
    112   int defaultBoolCombine = 0;
    113   if (queryparams.match_mode){
    114     defaultBoolCombine = 1;
    115   }
    116 
    117108  text_t utf8querystring = to_utf8(queryparams.querystring);
    118109  cerr << "**** query string = " << utf8querystring << endl;
     
    131122  cmd += (text_t)" \""+indexname + (text_t)"\" \"" + escaped_utf8querystring + (text_t)"\"";
    132123  if (!queryparams.sortfield.empty()) {
    133     cmd += " \"" + queryparams.sortfield + "\"";
    134   }
     124    cmd += " -sort \"" + queryparams.sortfield + "\"";
     125  }
     126
     127  // New code to support configuration of the default conjuction operator
     128  // set default Boolean combiner from all/some setting
     129  // if match_mode == 1, ie all, default=1 ie AND
     130  // if match_mode == 0, ie some, default=0, ie OR
     131  if (queryparams.match_mode)
     132    {
     133      cmd += " -dco AND";
     134    }
     135
    135136  cerr << "Lucene command: " << cmd << endl;
    136137 
  • trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java

    r12275 r12364  
    3939        Searcher searcher = new IndexSearcher(args[0]);
    4040        Sort sorter = new Sort();
    41         if (args.length > 1) {
    42         sorter = new Sort(args[1]);
    43         }
     41            // New code to allow the default conjunction operator to be
     42            // definable
     43            String default_conjuction_operator = "OR";
     44            for (int i = 1; i < args.length; i++)
     45                {
     46                    if (args[i].equals("-sort"))
     47                        {
     48                            i++;
     49                            sorter = new Sort(args[i]);
     50                        }
     51                    if (args[i].equals("-dco"))
     52                        {
     53                            i++;
     54                            default_conjuction_operator = args[i];
     55                        }
     56                }
     57
    4458        Analyzer analyzer = new StandardAnalyzer();
    4559        IndexReader reader = ((IndexSearcher) searcher).getIndexReader();
     
    5670        // Parse the query and rewrite it into individual terms (eg. for wildcard searches)
    5771        QueryParser query_parser = new QueryParser("TX", analyzer);
     72                // Set the default conjuction operator
     73                System.err.println("**** DCO = " + default_conjuction_operator);
     74                if (default_conjuction_operator.equals("AND"))
     75                    {
     76                        query_parser.setDefaultOperator(query_parser.AND_OPERATOR);
     77                    }
     78                // Otherwise its OR
     79
    5880        Query query = query_parser.parse(query_string);
    5981        query = query.rewrite(reader);
     
    7193        while (iter.hasNext()) {
    7294            Term term = (Term) iter.next();
    73             System.out.println("  <Term value=\"" + term.text() + "\" freq=\"" + reader.docFreq(term) + "\"/>");
     95                    //System.out.println("  <Term value=\"" + term.text() + "\" freq=\"" + reader.docFreq(term) + "\"/>");
     96            System.out.println("  <Term value=\"" + term.text() + "\" freq=\"" + reader.docFreq(term) + "\" field=\"" + term.field() + "\"/>");
    7497        }
    7598
  • trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java

    r12275 r12364  
    3939        Searcher searcher = new IndexSearcher(args[0]);
    4040        Sort sorter = new Sort();
    41         if (args.length > 1) {
    42         sorter = new Sort(args[1]);
    43         }
     41            // New code to allow the default conjunction operator to be
     42            // definable
     43            String default_conjuction_operator = "OR";
     44            for (int i = 1; i < args.length; i++)
     45                {
     46                    if (args[i].equals("-sort"))
     47                        {
     48                            i++;
     49                            sorter = new Sort(args[i]);
     50                        }
     51                    if (args[i].equals("-dco"))
     52                        {
     53                            i++;
     54                            default_conjuction_operator = args[i];
     55                        }
     56                }
     57
    4458        Analyzer analyzer = new StandardAnalyzer();
    4559        IndexReader reader = ((IndexSearcher) searcher).getIndexReader();
     
    5670        // Parse the query and rewrite it into individual terms (eg. for wildcard searches)
    5771        QueryParser query_parser = new QueryParser("TX", analyzer);
     72                // Set the default conjuction operator
     73                System.err.println("**** DCO = " + default_conjuction_operator);
     74                if (default_conjuction_operator.equals("AND"))
     75                    {
     76                        query_parser.setDefaultOperator(query_parser.AND_OPERATOR);
     77                    }
     78                // Otherwise its OR
     79
    5880        Query query = query_parser.parse(query_string);
    5981        query = query.rewrite(reader);
     
    7193        while (iter.hasNext()) {
    7294            Term term = (Term) iter.next();
    73             System.out.println("  <Term value=\"" + term.text() + "\" freq=\"" + reader.docFreq(term) + "\"/>");
     95                    //System.out.println("  <Term value=\"" + term.text() + "\" freq=\"" + reader.docFreq(term) + "\"/>");
     96            System.out.println("  <Term value=\"" + term.text() + "\" freq=\"" + reader.docFreq(term) + "\" field=\"" + term.field() + "\"/>");
    7497        }
    7598
Note: See TracChangeset for help on using the changeset viewer.