Changeset 16015
- Timestamp:
- 2008-06-16T11:58:51+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
indexers/trunk/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java
r14559 r16015 75 75 private Searcher searcher = null; 76 76 private IndexReader reader = null; 77 78 static private PrintWriter utf8out = null; 79 80 static 81 { 82 try { 83 OutputStreamWriter osw = new OutputStreamWriter(System.out, "UTF-8"); 84 utf8out = new PrintWriter(osw, true); 85 } 86 catch (UnsupportedEncodingException e) { 87 System.out.println(e); 88 } 89 } 90 77 91 78 92 public GS2LuceneQuery() { … … 88 102 89 103 if (full_indexdir==null || full_indexdir.length()==-1){ 90 System.out.println("Index directory is not indicated "); 104 utf8out.println("Index directory is not indicated "); 105 utf8out.flush(); 91 106 return false; 92 107 } … … 107 122 108 123 if (query_string == null || query_string.equals("")) { 109 System.out.println("The query word is not indicated "); 124 utf8out.println("The query word is not indicated "); 125 utf8out.flush(); 110 126 return null; 111 127 } … … 407 423 } 408 424 425 426 protected void finalize() throws Throwable 427 { 428 try { 429 utf8out.flush(); 430 } finally { 431 super.finalize(); 432 } 433 } 434 409 435 410 436 /** command line program and auxiliary methods */ … … 413 439 static private boolean query_result_caching_enabled = false; 414 440 441 415 442 static public void main (String args[]) 416 443 { 444 445 417 446 if (args.length == 0) { 418 447 System.out.println("Usage: GS2LuceneQuery <index directory> [-fuzziness value] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-startresults number -endresults number] [query]"); … … 495 524 break; 496 525 } 526 497 527 runQueryCaching(index_directory, queryer, query_string); 498 528 … … 542 572 String query_results_xml_string = query_results_xml.toString(); 543 573 query_results_xml_string = query_results_xml_string.replaceFirst("cached=\"false\"", "cached=\"true\""); 544 System.out.print(query_results_xml_string); 574 575 utf8out.print(query_results_xml_string); 576 utf8out.flush(); 577 545 578 return; 546 579 } … … 568 601 query_results_xml.append("</ResultSet>\n"); 569 602 570 System.out.print(query_results_xml); 603 utf8out.print(query_results_xml); 604 utf8out.flush(); 605 606 try { 607 /* 608 Writer output = null; 609 File file = new File("/tmp/lucenequery.txt"); 610 output = new BufferedWriter(new FileWriter(file,"UTF-8")); 611 output.write(query_results_xml.toString()); 612 output.close(); 613 */ 614 615 FileOutputStream fos = new FileOutputStream("/tmp/lucenequery.txt"); 616 617 OutputStreamWriter osw2 = new OutputStreamWriter(fos, "UTF-8"); 618 619 osw2.write("Query string = " + query_string + "\n"); 620 osw2.write(query_results_xml.toString()); 621 osw2.close(); 622 } 623 catch (Exception e) { 624 e.printStackTrace(); 625 } 626 627 571 628 572 629 // Cache this query result, if desired
Note:
See TracChangeset
for help on using the changeset viewer.