1 package com.dotmarketing.util; 2 3 import java.io.BufferedReader ; 4 import java.io.File ; 5 import java.io.FileReader ; 6 import java.io.FileWriter ; 7 import java.io.IOException ; 8 import java.text.SimpleDateFormat ; 9 import java.util.Date ; 10 import java.util.regex.Matcher ; 11 import java.util.regex.Pattern ; 12 13 import org.apache.commons.lang.StringUtils; 14 15 import com.dotmarketing.lucene.DotAnalyzer; 18 19 import org.apache.lucene.document.DateTools; 20 import org.apache.lucene.document.Document; 21 import org.apache.lucene.document.Field; 22 import org.apache.lucene.index.IndexModifier; 23 import org.apache.lucene.index.IndexReader; 24 import org.apache.lucene.index.Term; 25 import org.apache.lucene.queryParser.ParseException; 26 import org.apache.lucene.queryParser.QueryParser; 27 import org.apache.lucene.search.BooleanClause; 28 import org.apache.lucene.search.BooleanQuery; 29 import org.apache.lucene.search.Hits; 30 import org.apache.lucene.search.IndexSearcher; 31 import org.apache.lucene.search.Query; 32 import org.apache.lucene.search.Sort; 33 import org.apache.lucene.search.TermQuery; 34 import org.apache.lucene.store.FSDirectory; 35 36 import com.dotmarketing.viewtools.WebAPI; 37 38 public class LuceneUtils { 39 40 private static int currentIndexNumber = readIndexNumberFromFile(); 41 42 private static int nextIndexNumber = -1; 43 44 private static int readIndexNumberFromFile () { 45 int current = 0; 46 String baseDir = Config.getStringProperty("LUCENE_BASE_DIR"); 47 if (!baseDir.endsWith("/")) 48 baseDir = baseDir + "/"; 49 File indexNumberStoreFile = new File (baseDir + "currentindex.txt"); 50 if (indexNumberStoreFile.exists()) { 51 FileReader fReader = null; 52 try { 53 fReader = new FileReader (indexNumberStoreFile); 54 BufferedReader reader = new BufferedReader (fReader); 55 String numberSt = reader.readLine(); 56 current = Integer.parseInt(numberSt); 57 } catch (Exception e) { 58 Logger.error(LuceneUtils.class, "Error trying to obtain the current index number from " + 59 indexNumberStoreFile.getAbsolutePath(), e); 60 } finally { 61 if (fReader != null) 62 try { fReader.close(); } catch (Exception e) { 63 Logger.error(LuceneUtils.class, "Error trying to close the opened file reader for " + 64 indexNumberStoreFile.getAbsolutePath(), e); 65 } 66 } 67 } else { 68 saveIndexNumberToFile (0); 69 } 70 return current; 71 } 72 73 private static void saveIndexNumberToFile (int newNumber) { 74 String baseDir = Config.getStringProperty("LUCENE_BASE_DIR"); 75 if (!baseDir.endsWith("/")) 76 baseDir = baseDir + "/"; 77 File directory = new File (baseDir); 78 if (!directory.exists()) 79 directory.mkdirs(); 80 File indexNumberStoreFile = new File (baseDir + "currentindex.txt"); 81 if (!indexNumberStoreFile.exists()) { 82 try { 83 indexNumberStoreFile.createNewFile(); 84 } catch (IOException e) { 85 Logger.error(LuceneUtils.class, "Error trying to close the opened file writer for " + 86 indexNumberStoreFile.getAbsolutePath(), e); 87 return; 88 } 89 } 90 FileWriter fWriter = null; 91 try { 92 if (!indexNumberStoreFile.exists()) { 93 indexNumberStoreFile.createNewFile(); 94 } 95 fWriter = new FileWriter (indexNumberStoreFile, false); 96 fWriter.write(String.valueOf(newNumber)); 97 } catch (IOException e) { 98 Logger.error(LuceneUtils.class, "Error trying to save the index number: " + newNumber + " to " + 99 indexNumberStoreFile.getAbsolutePath()); 100 } finally { 101 if (fWriter != null) 102 try { 103 fWriter.close(); 104 } catch (IOException e) { 105 Logger.error(LuceneUtils.class, "Error trying to close the opened file writer for " + 106 indexNumberStoreFile.getAbsolutePath(), e); 107 } 108 } 109 } 110 111 public static String getCurrentLuceneDirPath() { 112 String baseDir = Config.getStringProperty("LUCENE_BASE_DIR"); 113 if (!UtilMethods.isSet(baseDir)) { 114 Logger.warn(LuceneUtils.class, "No LUCENE_DIR base dir found on dotmarketing.config.properties, using the default: lucenedotcms"); 115 baseDir = "lucenedotcms"; 116 } 117 118 String dir = ""; 119 if (!baseDir.endsWith("/")) 120 dir = baseDir + "/" + currentIndexNumber + "/"; 121 else 122 dir = baseDir + currentIndexNumber + "/"; 123 124 File dirFile = new File (dir); 125 if (!dirFile.exists()) 126 dirFile.mkdirs(); 127 if (dirFile.exists() && !dirFile.isDirectory()) { 128 Logger.fatal(LuceneUtils.class, "Trying to use " + dir + " as the current but it's not a directory"); 129 return dir; 130 } 131 return dir; 132 } 133 134 public static String getNewLuceneDirPath() { 135 String baseDir = Config.getStringProperty("LUCENE_BASE_DIR"); 136 if (!UtilMethods.isSet(baseDir)) { 137 Logger.warn(LuceneUtils.class, "No LUCENE_DIR base dir found on dotmarketing.config.properties, using the default: lucenedotcms"); 138 baseDir = "lucenedotcms"; 139 } 140 141 142 String dir = ""; 143 if (nextIndexNumber == -1) { 144 if (!baseDir.endsWith("/")) 145 dir = baseDir + "/" + ((currentIndexNumber + 1) % 10) + "/"; 146 else 147 dir = baseDir + ((currentIndexNumber + 1) % 10) + "/"; 148 nextIndexNumber = ((currentIndexNumber + 1) % 10); 149 } else { 150 if (!baseDir.endsWith("/")) 151 dir = baseDir + "/" + nextIndexNumber + "/"; 152 else 153 dir = baseDir + nextIndexNumber + "/"; 154 } 155 156 File dirFile = new File (dir); 157 if (!dirFile.exists()) 158 dirFile.mkdirs(); 159 if (dirFile.exists() && !dirFile.isDirectory()) { 160 Logger.fatal(LuceneUtils.class, "Trying to use " + dir + " as the current but it's not a directory"); 161 return dir; 162 } 163 return dir; 164 } 165 166 public synchronized static void changeToTheNewLuceneDir () { 168 if (nextIndexNumber != -1) 169 saveIndexNumberToFile(nextIndexNumber); 170 currentIndexNumber = nextIndexNumber; 171 } 172 173 public synchronized static boolean recreateNewIndexFolder () { 175 if (nextIndexNumber == -1) 176 nextIndexNumber = (currentIndexNumber + 1) % 10; 177 else 178 nextIndexNumber = (nextIndexNumber + 1) % 10; 179 String newIndexationDir = LuceneUtils.getNewLuceneDirPath(); 180 boolean result = true; 181 IndexModifier newIndexModifier = null; 182 try { 183 Logger.info(LuceneUtils.class, "Creting new index at: " + getNewLuceneDirPath()); 184 if (IndexReader.isLocked(getNewLuceneDirPath())) { 185 FSDirectory dirFS = FSDirectory.getDirectory(getNewLuceneDirPath(), false); 186 IndexReader.unlock(dirFS); 187 } 188 UtilMethods.revomeDir(newIndexationDir); 189 new File (newIndexationDir).mkdirs(); 190 191 newIndexModifier = new IndexModifier(newIndexationDir, new DotAnalyzer(), true); 193 194 newIndexModifier.setUseCompoundFile(true); 195 } catch (IOException e) { 196 if (nextIndexNumber != currentIndexNumber) { 197 Logger.error(LuceneUtils.class, "Error encountered trying to create the new index dir: " + newIndexationDir + 198 ", trying with the next available directory.", e); 199 result = recreateNewIndexFolder(); 200 } else { 201 Logger.fatal(LuceneUtils.class, "Error encountered trying to create the new index dir: " + newIndexationDir + 202 ", but no more usable directories has been found!!. Check the directories permissions.", e); 203 result = false; 204 } 205 } finally { 206 if (newIndexModifier != null) { 207 try { 208 newIndexModifier.close(); 209 } catch (IOException e) { 210 Logger.error(LuceneUtils.class, "Error encountered trying to create the new index dir: " + newIndexationDir, e); 211 } 212 } 213 } 214 return result; 215 } 216 217 public synchronized static void removeDocByIdenToReindexationIndex(String identifier) { 219 String newIndexDir = getNewLuceneDirPath(); 220 IndexModifier newIndexModifier = null; 221 try { 222 if (!IndexReader.indexExists(newIndexDir)) { 223 File newIndexDirFile = new File (newIndexDir); 224 newIndexDirFile.delete(); 225 newIndexDirFile.mkdirs(); 226 IndexReader.unlock(FSDirectory.getDirectory(newIndexDir, false)); 227 228 newIndexModifier = new IndexModifier(newIndexDir, new DotAnalyzer(), true); 230 } else { 231 newIndexModifier = new IndexModifier(newIndexDir, new DotAnalyzer(), false); 233 } 234 newIndexModifier.deleteDocuments(new Term("identifier", identifier)); 235 } catch (Exception e) { 236 Logger.error(LuceneUtils.class, "Error ocurred trying to write a document to the reindexation index.", e); 237 } finally { 238 try { 239 if (newIndexModifier != null) newIndexModifier.close (); 240 } catch (Exception e) { 241 Logger.error(LuceneUtils.class, "Error ocurred trying to close the modifier for the reindexation index.", e); 242 } 243 } 244 } 245 246 public synchronized static void writeInodeToReindexationIndex(Document inodeDoc) { 247 248 String newIndexDir = getNewLuceneDirPath(); 249 IndexModifier newIndexModifier = null; 250 try { 251 if (!IndexReader.indexExists(newIndexDir)) { 252 File newIndexDirFile = new File (newIndexDir); 253 newIndexDirFile.delete(); 254 newIndexDirFile.mkdirs(); 255 IndexReader.unlock(FSDirectory.getDirectory(newIndexDir, false)); 256 257 newIndexModifier = new IndexModifier(newIndexDir, new DotAnalyzer(), true); 259 } else { 260 newIndexModifier = new IndexModifier(newIndexDir, new DotAnalyzer(), false); 262 } 263 String inode = inodeDoc.get("inode"); 264 if (inode == null || inode.equals("0")) { 265 Logger.warn("An invalid document was given to be reindexed: " + inodeDoc.toString()); 266 return; 267 } 268 newIndexModifier.deleteDocuments(new Term("inode", inode)); 269 newIndexModifier.addDocument(inodeDoc); 270 } catch (Exception e) { 271 Logger.error(LuceneUtils.class, "Error ocurred trying to write a document to the reindexation index.", e); 272 } finally { 273 try { 274 if (newIndexModifier != null) newIndexModifier.close (); 275 } catch (Exception e) { 276 Logger.error(LuceneUtils.class, "Error ocurred trying to close the modifier for the reindexation index.", e); 277 } 278 } 279 } 280 281 public synchronized static void removeDocByIdenToCurrentIndex(String identifier) { 282 String currentIndexDir = getCurrentLuceneDirPath(); 283 IndexModifier currentIndexModifier = null; 284 try { 285 if (!IndexReader.indexExists(currentIndexDir)) { 286 File newIndexDirFile = new File (currentIndexDir); 287 newIndexDirFile.delete(); 288 newIndexDirFile.mkdirs(); 289 IndexReader.unlock(FSDirectory.getDirectory(currentIndexDir, false)); 290 291 currentIndexModifier = new IndexModifier(currentIndexDir, new DotAnalyzer(), true); 293 } else { 294 currentIndexModifier = new IndexModifier(currentIndexDir, new DotAnalyzer(), false); 296 } 297 currentIndexModifier.deleteDocuments(new Term("identifier", identifier)); 298 } catch (Exception e) { 299 Logger.error(LuceneUtils.class, "Error ocurred trying to write a document to the reindexation index.", e); 300 } finally { 301 try { 302 if (currentIndexModifier != null) currentIndexModifier.close (); 303 } catch (Exception e) { 304 Logger.error(LuceneUtils.class, "Error ocurred trying to close the modifier for the reindexation index.", e); 305 } 306 } 307 } 308 309 public synchronized static void writeInodeToCurrentIndex(Document inodeDoc) { 310 311 String currentIndexDir = getCurrentLuceneDirPath(); 312 IndexModifier currentIndexModifier = null; 313 try { 314 if (!IndexReader.indexExists(currentIndexDir)) { 315 File newIndexDirFile = new File (currentIndexDir); 316 newIndexDirFile.delete(); 317 newIndexDirFile.mkdirs(); 318 IndexReader.unlock(FSDirectory.getDirectory(currentIndexDir, false)); 319 320 currentIndexModifier = new IndexModifier(currentIndexDir, new DotAnalyzer(), true); 322 } else { 323 currentIndexModifier = new IndexModifier(currentIndexDir, new DotAnalyzer(), false); 325 } 326 String inode = inodeDoc.get("inode"); 327 if (inode == null || inode.equals("0")) { 328 Logger.warn("An invalid document was given to be reindexed: " + inodeDoc.toString()); 329 return; 330 } 331 currentIndexModifier.deleteDocuments(new Term("inode", inode)); 332 currentIndexModifier.addDocument(inodeDoc); 333 } catch (Exception e) { 334 Logger.error(LuceneUtils.class, "Error ocurred trying to write a document to the reindexation index.", e); 335 } finally { 336 try { 337 if (currentIndexModifier != null) currentIndexModifier.close (); 338 } catch (Exception e) { 339 Logger.error(LuceneUtils.class, "Error ocurred trying to close the modifier for the reindexation index.", e); 340 } 341 } 342 343 } 344 345 349 public synchronized static void checkAndInitialiazeCurrentIndex () { 350 IndexModifier modifier = null; 351 String currentIndexDir = getNewLuceneDirPath(); 352 try { 353 if (currentIndexDir == null) { 354 File currentIndexDirFile = new File (currentIndexDir); 355 if (!IndexReader.indexExists(currentIndexDir)) { 356 currentIndexDirFile.delete(); 357 currentIndexDirFile.mkdirs(); 358 IndexReader.unlock(FSDirectory.getDirectory(currentIndexDir, false)); 359 360 modifier = new IndexModifier(currentIndexDir, new DotAnalyzer(), true); 362 } else { 363 modifier = new IndexModifier(currentIndexDir, new DotAnalyzer(), false); 365 } 366 } else { 367 if (IndexReader.isLocked(currentIndexDir)) 368 IndexReader.unlock(FSDirectory.getDirectory(currentIndexDir, false)); 369 370 modifier = new IndexModifier(currentIndexDir, new DotAnalyzer(), false); 372 } 373 } catch (IOException e) { 374 if (modifier != null) 375 try { 376 modifier.close(); 377 } catch (IOException e1) { 378 Logger.error(LuceneUtils.class, "Error encountered trying to close the index modifier: " + currentIndexDir, e); 379 } 380 } 381 382 } 383 384 private static Sort getIndexSorter (String sortBy) 385 { 386 if (!UtilMethods.isSet(sortBy)) return null; 387 boolean desc = false; 388 String sortField = ""; 389 if (sortBy.endsWith("desc")) { 390 desc = true; 391 sortField = sortBy.substring(0, sortBy.indexOf("desc")).trim(); 392 } else if (sortBy.endsWith("asc")) { 393 sortField = sortBy.substring(0, sortBy.indexOf("asc")).trim(); 394 } else 395 sortField = sortBy.trim(); 396 return new Sort (sortField, desc); 397 } 398 399 public static LuceneHits searchInCurrentIndex(Query query, int offset, int limit, String sortBy) { 400 IndexSearcher searcher = null; 401 LuceneHits lhits = new LuceneHits (); 402 try { 403 searcher = new IndexSearcher(getCurrentLuceneDirPath()); 404 405 Hits hits = null; 406 407 hits = searcher.search(query); 415 lhits.recordHits(hits, offset, limit, sortBy); 416 418 } catch (Exception e) { 419 Logger.error(LuceneUtils.class, "Error ocurred trying to search results in the current index.", e); 420 } finally { 421 if (searcher != null) 422 try { 423 searcher.close(); 424 } catch (IOException e) { 425 Logger.error(LuceneUtils.class, "Error ocurred trying to close the searcher over the results in the current index.", e); 426 } 427 } 428 return lhits; 429 } 430 431 public static LuceneHits searchInReindexationIndex(Query query, int offset, int limit, String sortBy) { 432 IndexSearcher searcher = null; 433 LuceneHits lhits = new LuceneHits (); 434 try { 435 searcher = new IndexSearcher(getNewLuceneDirPath()); 436 Hits hits = null; 437 if (UtilMethods.isSet(sortBy)) 438 hits = searcher.search(query, getIndexSorter (sortBy)); 439 else 440 hits = searcher.search(query); 441 lhits.recordHits(hits, offset, limit, null); 442 } catch (Exception e) { 443 Logger.error(LuceneUtils.class, "Error ocurred trying to search results in the current index.", e); 444 } finally { 445 if (searcher != null) 446 try { 447 searcher.close(); 448 } catch (IOException e) { 449 Logger.error(LuceneUtils.class, "Error ocurred trying to close the searcher over the results in the current index.", e); 450 } 451 } 452 return lhits; 453 } 454 455 public static synchronized void optimizeCurrentIndex () { 459 IndexModifier currentIndexModifier = null; 460 try { 461 String currentIndexDir = getNewLuceneDirPath(); 462 463 currentIndexModifier = new IndexModifier(currentIndexDir, new DotAnalyzer(), false); 465 466 currentIndexModifier.optimize(); 467 } catch (Exception e) { 468 Logger.error(LuceneUtils.class, "A error ocurred trying to optimize the lucene index", e); 469 } finally { 470 try { 471 if (currentIndexModifier != null) currentIndexModifier.close (); 472 } catch (Exception e) { 473 Logger.error(LuceneUtils.class, "Error ocurred trying to close the modifier for the current index.", e); 474 } 475 } 476 } 477 478 public static Field getDateField(String field) { 480 return getDateField(field, new Date ()); 481 } 482 483 public static Field getDateField(String field, Date date) { 484 if (date == null) { 485 return getDateField(field); 486 } 487 else { 488 return new Field (field, LuceneUtils.toLuceneDate(date), Field.Store.YES, Field.Index.UN_TOKENIZED); 489 } 490 } 491 492 public static Field getKeywordField(String field, String keyword) { 493 Field fieldObj = new Field (field, keyword, Field.Store.YES, Field.Index.UN_TOKENIZED); 494 return fieldObj; 495 } 496 497 public static Field getIndexedField(String field, String keyword) { 498 Field fieldObj = new Field (field, keyword, Field.Store.YES, Field.Index.TOKENIZED); 499 return fieldObj; 500 } 501 502 public static Field getUnIndexedField(String field, String keyword) { 503 Field fieldObj = new Field(field, keyword, Field.Store.YES, Field.Index.NO); 504 return fieldObj; 505 } 506 507 509 public static void addQueryTerm( 510 BooleanQuery booleanQuery, String field, String text) throws ParseException 511 { 512 513 if (!UtilMethods.isSet(field) || !UtilMethods.isSet(text)) 514 return; 515 516 if (UtilMethods.isSet(text)) { 517 518 text = escape(text); 519 520 QueryParser parser = new QueryParser ("", new DotAnalyzer()); 521 text = parser.parse(text).toString(); 522 523 if (text.indexOf(" ") == -1) { 524 text = toWildcard(text); 525 } 526 527 Query query; 528 if(text.indexOf("'") != -1 || text.indexOf("\"") != -1){ 529 530 533 query = parser.parse(field+":"+text.toLowerCase()); 534 535 }else { 536 539 query = parser.parse(field + ":" + text); 540 } 541 542 booleanQuery.add(query, BooleanClause.Occur.SHOULD); 543 } 544 } 545 546 public static void addRequiredQueryTerm( 547 BooleanQuery booleanQuery, String field, String text, boolean wildcard) throws ParseException { 548 549 if (wildcard) { 550 if (!UtilMethods.isSet(field) || !UtilMethods.isSet(text)) 551 return; 552 553 if (UtilMethods.isSet(text)) { 554 555 text = escape(text); 556 557 QueryParser parser = new QueryParser ("", new DotAnalyzer()); 558 text = parser.parse(text).toString(); 559 560 if (text.indexOf(" ") == -1) { 561 text = toWildcard(text); 562 } 563 564 Query query; 565 566 if(text.indexOf("'") != -1 || text.indexOf("\"") != -1){ 567 568 571 query = parser.parse(field+":"+text.toLowerCase()); 572 573 }else { 574 575 578 query = parser.parse(field+":"+text.toLowerCase()); 579 } 580 581 booleanQuery.add(query, BooleanClause.Occur.MUST); 582 } 583 } else { 584 585 if (!UtilMethods.isSet(field) || !UtilMethods.isSet(text)) 586 return; 587 588 text = escape(text); 589 590 if (wildcard) { 591 text = toWildcard(text); 592 } 593 594 Term term = new Term(field, text.toLowerCase()); 595 TermQuery termQuery = new TermQuery(term); 596 597 booleanQuery.add(termQuery, BooleanClause.Occur.MUST); 598 } 599 } 600 601 public static void addRequiredDateTerm(BooleanQuery booleanQuery, String field, String text) throws ParseException { 602 if (!UtilMethods.isSet(field) || !UtilMethods.isSet(text)) 603 return; 604 Query query; 605 text = LuceneUtils.findAndReplaceQueryDates(text); 606 607 QueryParser parser = new QueryParser ("", new DotAnalyzer()); 609 610 query = parser.parse(field + ":" + text); 611 booleanQuery.add(query, BooleanClause.Occur.MUST); 612 } 613 614 public static void addDateTerm(BooleanQuery booleanQuery, String field, String text) throws ParseException { 615 if (!UtilMethods.isSet(field) || !UtilMethods.isSet(text)) 616 return; 617 Query query; 618 text = LuceneUtils.findAndReplaceQueryDates(text); 619 620 QueryParser parser = new QueryParser ("", new DotAnalyzer()); 622 623 query = parser.parse(field + ":" + text); 624 booleanQuery.add(query, BooleanClause.Occur.MUST); 625 } 626 627 public static final String [] SPECIAL = new String [] { 629 "+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^", "\"", "~", 630 "*", "?", ":", "\\" 631 }; 632 633 public static String escape(String text) { 634 for (int i = SPECIAL.length - 1; i >= 0; i--) { 635 text = StringUtils.replace( 636 text, SPECIAL[i], "\\" + SPECIAL[i]); 637 } 638 639 return text; 640 } 641 642 public static String toWildcard(String keywords) { 643 if (!UtilMethods.isSet(keywords)) { 644 return ""; 645 } 646 647 if (!keywords.endsWith("*")) { 648 keywords = keywords + "*"; 649 } 650 651 return keywords; 652 } 653 654 659 public static void printIndex () throws IOException { 660 672 } 673 674 public static String toLuceneDateTime(String dateString) 675 { 676 String format = "MM/dd/yyyy HH:mm:ss"; 677 return toLuceneDateWithFormat(dateString,format); 678 } 679 680 public static String toLuceneDate(String dateString) 681 { 682 String format = "MM/dd/yyyy"; 683 return toLuceneDateWithFormat(dateString,format); 684 } 685 686 public static String toLuceneDateWithFormat(String dateString,String format) 687 { 688 try 689 { 690 SimpleDateFormat sdf = new SimpleDateFormat (format); 691 Date date = sdf.parse(dateString); 692 String returnValue = LuceneUtils.toLuceneDate(date); 693 694 return returnValue; 695 } 696 catch(Exception ex) 697 { 698 Logger.error(WebAPI.class,ex.toString()); 699 return "error date"; 700 } 701 } 702 703 public static String toLuceneDate (Date date) 704 { 705 try 706 { 707 String returnValue = DateTools.dateToString(date, DateTools.Resolution.SECOND); 708 return returnValue; 709 } 710 catch(Exception ex) 711 { 712 Logger.error(WebAPI.class,ex.toString()); 713 return "error date"; 714 } 715 } 716 717 public static Date fromLuceneDate(String luceneDate) 718 { 719 try { 720 return DateTools.stringToDate(luceneDate); 721 } catch (java.text.ParseException e) { 722 Logger.error(LuceneUtils.class, "Unable to convert luceneDate: " + luceneDate + " to a regular date.", e); 723 return new Date (); 724 } 725 } 726 727 public static String findAndReplaceQueryDates (String query) { 728 Pattern p = Pattern.compile("\\\"?(\\d{1,2}/\\d{1,2}/\\d{4} \\d{1,2}:\\d{1,2}:\\d{1,2})\\\"?"); 729 Matcher m = p.matcher(query); 730 StringBuffer newQuery = new StringBuffer (); 731 while (m.find()) { 732 String originalDate = m.group(1); 733 String luceneDate = LuceneUtils.toLuceneDateTime(originalDate); 734 m.appendReplacement(newQuery, luceneDate); 735 } 736 m.appendTail(newQuery); 737 query = newQuery.toString(); 738 739 p = Pattern.compile("\\\"?(\\d{1,2}/\\d{1,2}/\\d{4})\\\"?"); 741 m = p.matcher(query); 742 newQuery = new StringBuffer (); 743 while (m.find()) { 744 String originalDate = m.group(1); 745 String luceneDate = LuceneUtils.toLuceneDate(originalDate); 746 m.appendReplacement(newQuery, luceneDate); 747 } 748 m.appendTail(newQuery); 749 query = newQuery.toString(); 750 751 return query; 752 } 753 } 754 | Popular Tags |