1 17 package org.alfresco.repo.search.impl.lucene; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.ByteArrayOutputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.ObjectInputStream ; 24 import java.io.ObjectOutputStream ; 25 import java.io.Serializable ; 26 import java.util.ArrayList ; 27 import java.util.Date ; 28 import java.util.HashMap ; 29 import java.util.HashSet ; 30 import java.util.Map ; 31 import java.util.Random ; 32 33 import javax.transaction.Status ; 34 import javax.transaction.UserTransaction ; 35 36 import junit.framework.TestCase; 37 38 import org.alfresco.model.ContentModel; 39 import org.alfresco.repo.dictionary.DictionaryDAO; 40 import org.alfresco.repo.dictionary.M2Model; 41 import org.alfresco.repo.node.BaseNodeServiceTest; 42 import org.alfresco.repo.search.QueryParameterDefImpl; 43 import org.alfresco.repo.search.QueryRegisterComponent; 44 import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; 45 import org.alfresco.repo.search.results.ChildAssocRefResultSet; 46 import org.alfresco.repo.search.results.DetachedResultSet; 47 import org.alfresco.repo.search.transaction.LuceneIndexLock; 48 import org.alfresco.repo.security.authentication.AuthenticationComponent; 49 import org.alfresco.service.ServiceRegistry; 50 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 51 import org.alfresco.service.cmr.dictionary.DictionaryService; 52 import org.alfresco.service.cmr.repository.ChildAssociationRef; 53 import org.alfresco.service.cmr.repository.ContentData; 54 import org.alfresco.service.cmr.repository.ContentService; 55 import org.alfresco.service.cmr.repository.ContentWriter; 56 import org.alfresco.service.cmr.repository.NodeRef; 57 import org.alfresco.service.cmr.repository.NodeService; 58 import org.alfresco.service.cmr.repository.Path; 59 import org.alfresco.service.cmr.repository.StoreRef; 60 import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; 61 import org.alfresco.service.cmr.search.QueryParameter; 62 import org.alfresco.service.cmr.search.QueryParameterDefinition; 63 import org.alfresco.service.cmr.search.ResultSet; 64 import org.alfresco.service.cmr.search.ResultSetRow; 65 import org.alfresco.service.cmr.search.SearchParameters; 66 import org.alfresco.service.cmr.search.SearchService; 67 import org.alfresco.service.namespace.DynamicNamespacePrefixResolver; 68 import org.alfresco.service.namespace.NamespacePrefixResolver; 69 import org.alfresco.service.namespace.NamespaceService; 70 import org.alfresco.service.namespace.QName; 71 import org.alfresco.service.transaction.TransactionService; 72 import org.alfresco.util.ApplicationContextHelper; 73 import org.alfresco.util.CachingDateFormat; 74 import org.alfresco.util.ISO9075; 75 import org.apache.commons.logging.Log; 76 import org.apache.commons.logging.LogFactory; 77 import org.springframework.context.ApplicationContext; 78 79 83 public class LuceneTest extends TestCase 84 { 85 private static final String TEST_NAMESPACE = "http://www.alfresco.org/test/lucenetest"; 86 87 private static final QName ASSOC_TYPE_QNAME = QName.createQName(TEST_NAMESPACE, "assoc"); 88 89 private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); 90 91 private static Log logger = LogFactory.getLog(LuceneTest.class); 92 93 TransactionService transactionService; 94 95 NodeService nodeService; 96 97 DictionaryService dictionaryService; 98 99 LuceneIndexLock luceneIndexLock; 100 101 private NodeRef rootNodeRef; 102 103 private NodeRef n1; 104 105 private NodeRef n2; 106 107 private NodeRef n3; 108 109 private NodeRef n4; 110 111 private NodeRef n5; 112 113 private NodeRef n6; 114 115 private NodeRef n7; 116 117 private NodeRef n8; 118 119 private NodeRef n9; 120 121 private NodeRef n10; 122 123 private NodeRef n11; 124 125 private NodeRef n12; 126 127 private NodeRef n13; 128 129 private NodeRef n14; 130 131 private DictionaryDAO dictionaryDAO; 132 133 private FullTextSearchIndexer luceneFTS; 134 135 private QName testType = QName.createQName(TEST_NAMESPACE, "testType"); 136 137 private QName testSuperType = QName.createQName(TEST_NAMESPACE, "testSuperType"); 138 139 private QName testAspect = QName.createQName(TEST_NAMESPACE, "testAspect"); 140 141 private QName testSuperAspect = QName.createQName(TEST_NAMESPACE, "testSuperAspect"); 142 143 private ContentService contentService; 144 145 private QueryRegisterComponent queryRegisterComponent; 146 147 private NamespacePrefixResolver namespacePrefixResolver; 148 149 private LuceneIndexerAndSearcher indexerAndSearcher; 150 151 private ServiceRegistry serviceRegistry; 152 153 private UserTransaction testTX; 154 155 private AuthenticationComponent authenticationComponent; 156 157 private NodeRef[] documentOrder; 158 159 public LuceneTest() 160 { 161 super(); 162 } 163 164 public void setUp() throws Exception 165 { 166 nodeService = (NodeService) ctx.getBean("dbNodeService"); 167 luceneIndexLock = (LuceneIndexLock) ctx.getBean("luceneIndexLock"); 168 dictionaryService = (DictionaryService) ctx.getBean("dictionaryService"); 169 dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO"); 170 luceneFTS = (FullTextSearchIndexer) ctx.getBean("LuceneFullTextSearchIndexer"); 171 contentService = (ContentService) ctx.getBean("contentService"); 172 queryRegisterComponent = (QueryRegisterComponent) ctx.getBean("queryRegisterComponent"); 173 namespacePrefixResolver = (NamespacePrefixResolver) ctx.getBean("namespaceService"); 174 indexerAndSearcher = (LuceneIndexerAndSearcher) ctx.getBean("luceneIndexerAndSearcherFactory"); 175 transactionService = (TransactionService) ctx.getBean("transactionComponent"); 176 serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); 177 178 this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent"); 179 this.authenticationComponent.setSystemUserAsCurrentUser(); 180 181 queryRegisterComponent.loadQueryCollection("testQueryRegister.xml"); 182 183 assertEquals(true, ctx.isSingleton("luceneIndexLock")); 184 assertEquals(true, ctx.isSingleton("LuceneFullTextSearchIndexer")); 185 186 testTX = transactionService.getUserTransaction(); 187 testTX.begin(); 188 189 ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); 191 InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/search/impl/lucene/LuceneTest_model.xml"); 192 assertNotNull(modelStream); 193 M2Model model = M2Model.createModel(modelStream); 194 dictionaryDAO.putModel(model); 195 196 StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); 197 rootNodeRef = nodeService.getRootNode(storeRef); 198 199 200 n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), 201 testSuperType).getChildRef(); 202 nodeService.setProperty(n1, QName.createQName("{namespace}property-1"), "ValueOne"); 203 204 n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}two"), 205 testSuperType).getChildRef(); 206 nodeService.setProperty(n2, QName.createQName("{namespace}property-1"), "valueone"); 207 nodeService.setProperty(n2, QName.createQName("{namespace}property-2"), "valuetwo"); 208 209 210 n3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}three"), 211 testSuperType).getChildRef(); 212 213 ObjectOutputStream oos; 214 try 215 { 216 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 217 oos = new ObjectOutputStream (baos); 218 oos.writeObject(n3); 219 oos.close(); 220 221 ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream (baos.toByteArray())); 222 Object o = ois.readObject(); 223 ois.close(); 224 } 225 catch (IOException e) 226 { 227 e.printStackTrace(); 229 } 230 catch (ClassNotFoundException e) 231 { 232 e.printStackTrace(); 234 } 235 236 Map <QName, Serializable > testProperties = new HashMap <QName, Serializable >(); 237 testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"), 238 "TEXT THAT IS INDEXED STORED AND TOKENISED ATOMICALLY KEYONE"); 239 testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic"), 240 "TEXT THAT IS INDEXED STORED AND TOKENISED ATOMICALLY KEYUNSTORED"); 241 testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic"), 242 "TEXT THAT IS INDEXED STORED AND TOKENISED BUT NOT ATOMICALLY KEYTWO"); 243 testProperties.put(QName.createQName(TEST_NAMESPACE, "int-ista"), Integer.valueOf(1)); 244 testProperties.put(QName.createQName(TEST_NAMESPACE, "long-ista"), Long.valueOf(2)); 245 testProperties.put(QName.createQName(TEST_NAMESPACE, "float-ista"), Float.valueOf(3.4f)); 246 testProperties.put(QName.createQName(TEST_NAMESPACE, "double-ista"), Double.valueOf(5.6)); 247 testProperties.put(QName.createQName(TEST_NAMESPACE, "date-ista"), new Date ()); 248 testProperties.put(QName.createQName(TEST_NAMESPACE, "datetime-ista"), new Date ()); 249 testProperties.put(QName.createQName(TEST_NAMESPACE, "boolean-ista"), Boolean.valueOf(true)); 250 testProperties.put(QName.createQName(TEST_NAMESPACE, "qname-ista"), QName.createQName("{wibble}wobble")); 251 testProperties.put(QName.createQName(TEST_NAMESPACE, "category-ista"), new NodeRef(storeRef, "CategoryId")); 252 testProperties.put(QName.createQName(TEST_NAMESPACE, "noderef-ista"), n1); 253 testProperties.put(QName.createQName(TEST_NAMESPACE, "path-ista"), nodeService.getPath(n3)); 254 testProperties.put(QName.createQName(TEST_NAMESPACE, "null"), null); 255 testProperties.put(QName.createQName(TEST_NAMESPACE, "list"), new ArrayList ()); 256 ArrayList <Object > testList = new ArrayList <Object >(); 257 testList.add(null); 258 testProperties.put(QName.createQName(TEST_NAMESPACE, "nullList"), testList); 259 ArrayList <Object > testList2 = new ArrayList <Object >(); 260 testList2.add("woof"); 261 testList2.add(null); 262 263 n4 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}four"), 264 testType, testProperties).getChildRef(); 265 266 nodeService.getProperties(n1); 267 nodeService.getProperties(n2); 268 nodeService.getProperties(n3); 269 nodeService.getProperties(n4); 270 271 n5 = nodeService.createNode(n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}five"), testSuperType) 272 .getChildRef(); 273 n6 = nodeService.createNode(n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}six"), testSuperType) 274 .getChildRef(); 275 n7 = nodeService.createNode(n2, ASSOC_TYPE_QNAME, QName.createQName("{namespace}seven"), testSuperType) 276 .getChildRef(); 277 n8 = nodeService.createNode(n2, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-2"), testSuperType) 278 .getChildRef(); 279 n9 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}nine"), testSuperType) 280 .getChildRef(); 281 n10 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ten"), testSuperType) 282 .getChildRef(); 283 n11 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eleven"), testSuperType) 284 .getChildRef(); 285 n12 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}twelve"), testSuperType) 286 .getChildRef(); 287 n13 = nodeService.createNode(n12, ASSOC_TYPE_QNAME, QName.createQName("{namespace}thirteen"), testSuperType) 288 .getChildRef(); 289 290 Map <QName, Serializable > properties = new HashMap <QName, Serializable >(); 291 properties.put(ContentModel.PROP_CONTENT, new ContentData(null, "text/plain", 0L, "UTF-16")); 292 n14 = nodeService.createNode(n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}fourteen"), 293 ContentModel.TYPE_CONTENT, properties).getChildRef(); 294 297 ContentWriter writer = contentService.getWriter(n14, ContentModel.PROP_CONTENT, true); 298 writer.putContent("The quick brown fox jumped over the lazy dog"); 302 303 nodeService.addChild(rootNodeRef, n8, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eight-0")); 304 nodeService.addChild(n1, n8, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-1")); 305 nodeService.addChild(n2, n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}link")); 306 307 nodeService.addChild(n1, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); 308 nodeService.addChild(n2, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); 309 nodeService.addChild(n5, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); 310 nodeService.addChild(n6, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); 311 nodeService.addChild(n12, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); 312 nodeService.addChild(n13, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); 313 314 documentOrder= new NodeRef[]{rootNodeRef, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14}; 315 316 } 317 318 @Override 319 protected void tearDown() throws Exception 320 { 321 322 if (testTX.getStatus() == Status.STATUS_ACTIVE) 323 { 324 testTX.rollback(); 325 } 326 authenticationComponent.clearCurrentSecurityContext(); 327 super.tearDown(); 328 } 329 330 public LuceneTest(String arg0) 331 { 332 super(arg0); 333 } 334 335 336 public void test0() throws Exception 337 { 338 luceneFTS.pause(); 339 buildBaseIndex(); 340 runBaseTests(); 341 luceneFTS.resume(); 342 } 343 344 345 346 public void testDeleteIssue() throws Exception 347 { 348 349 testTX.commit(); 350 351 352 UserTransaction tx = transactionService.getUserTransaction(); 353 tx.begin(); 354 ChildAssociationRef testFind = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName 355 .createQName("{namespace}testFind"), testSuperType); 356 tx.commit(); 357 358 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 359 searcher.setNodeService(nodeService); 360 searcher.setDictionaryService(dictionaryService); 361 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 362 searcher.setQueryRegister(queryRegisterComponent); 363 364 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); 365 assertEquals(1, results.length()); 366 results.close(); 367 368 UserTransaction tx1 = transactionService.getUserTransaction(); 369 tx1.begin(); 370 for (int i = 0; i < 100; i++) 371 { 372 HashSet <ChildAssociationRef> refs = new HashSet <ChildAssociationRef>(); 373 for (int j =0 ; j < i; j++) 374 { 375 ChildAssociationRef test = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName 376 .createQName("{namespace}test"), testSuperType); 377 refs.add(test); 378 } 379 380 for(ChildAssociationRef car : refs) 381 { 382 nodeService.deleteNode(car.getChildRef()); 383 } 384 385 } 386 tx1.commit(); 387 388 UserTransaction tx3 = transactionService.getUserTransaction(); 389 tx3.begin(); 390 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); 391 assertEquals(1, results.length()); 392 results.close(); 393 tx3.commit(); 394 } 395 396 397 public void testMTDeleteIssue() throws Exception 398 { 399 400 testTX.commit(); 401 402 403 UserTransaction tx = transactionService.getUserTransaction(); 404 tx.begin(); 405 ChildAssociationRef testFind = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName 406 .createQName("{namespace}testFind"), testSuperType); 407 tx.commit(); 408 409 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 410 searcher.setNodeService(nodeService); 411 searcher.setDictionaryService(dictionaryService); 412 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 413 searcher.setQueryRegister(queryRegisterComponent); 414 415 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); 416 assertEquals(1, results.length()); 417 results.close(); 418 419 420 Thread runner = null; 421 422 for (int i = 0; i < 20; i++) 423 { 424 runner = new Nester("Concurrent-" + i, runner); 425 } 426 if (runner != null) 427 { 428 runner.start(); 429 430 try 431 { 432 runner.join(); 433 } 434 catch (InterruptedException e) 435 { 436 e.printStackTrace(); 437 } 438 } 439 440 441 442 UserTransaction tx3 = transactionService.getUserTransaction(); 443 tx3.begin(); 444 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); 445 assertEquals(1, results.length()); 446 results.close(); 447 tx3.commit(); 448 } 449 450 class Nester extends Thread 451 { 452 Thread waiter; 453 454 Nester(String name, Thread waiter) 455 { 456 super(name); 457 this.setDaemon(true); 458 this.waiter = waiter; 459 } 460 461 public void run() 462 { 463 authenticationComponent.setSystemUserAsCurrentUser(); 464 if (waiter != null) 465 { 466 waiter.start(); 467 } 468 try 469 { 470 System.out.println("Start " + this.getName()); 471 UserTransaction tx1 = transactionService.getUserTransaction(); 472 tx1.begin(); 473 for (int i = 0; i < 20; i++) 474 { 475 HashSet <ChildAssociationRef> refs = new HashSet <ChildAssociationRef>(); 476 for (int j =0 ; j < i; j++) 477 { 478 ChildAssociationRef test = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName 479 .createQName("{namespace}test"), testSuperType); 480 refs.add(test); 481 } 482 483 for(ChildAssociationRef car : refs) 484 { 485 nodeService.deleteNode(car.getChildRef()); 486 } 487 488 } 489 tx1.commit(); 490 System.out.println("End " + this.getName()); 491 } 492 catch (Exception e) 493 { 494 e.printStackTrace(); 495 System.exit(12); 496 } 497 finally 498 { 499 authenticationComponent.clearCurrentSecurityContext(); 500 } 501 if (waiter != null) 502 { 503 try 504 { 505 waiter.join(); 506 } 507 catch (InterruptedException e) 508 { 509 } 510 } 511 } 512 513 } 514 515 516 517 public void testDeltaIssue() throws Exception 518 { 519 final NodeService pns = (NodeService) ctx.getBean("NodeService"); 520 521 testTX.commit(); 522 UserTransaction tx = transactionService.getUserTransaction(); 523 tx.begin(); 524 luceneFTS.pause(); 525 buildBaseIndex(); 526 runBaseTests(); 527 tx.commit(); 528 529 Thread thread = new Thread (new Runnable () 530 { 531 532 public void run() 533 { 534 try 535 { 536 UserTransaction tx = transactionService.getUserTransaction(); 537 tx = transactionService.getUserTransaction(); 538 tx.begin(); 539 540 SearchParameters sp = new SearchParameters(); 541 sp.addStore(rootNodeRef.getStoreRef()); 542 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 543 sp.setQuery("PATH:\"//.\""); 544 sp.excludeDataInTheCurrentTransaction(false); 545 ResultSet results = serviceRegistry.getSearchService().query(sp); 546 assertEquals(15, results.length()); 547 results.close(); 548 549 sp = new SearchParameters(); 550 sp.addStore(rootNodeRef.getStoreRef()); 551 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 552 sp.setQuery("PATH:\"//.\""); 553 sp.excludeDataInTheCurrentTransaction(false); 554 results = serviceRegistry.getSearchService().query(sp); 555 assertEquals(15, results.length()); 556 results.close(); 557 558 Map <QName, Serializable > props = new HashMap <QName, Serializable >(); 559 props.put(ContentModel.PROP_TITLE, "woof"); 560 pns.addAspect(n1, ContentModel.ASPECT_TITLED, props); 561 562 sp = new SearchParameters(); 563 sp.addStore(rootNodeRef.getStoreRef()); 564 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 565 sp.setQuery("PATH:\"//.\""); 566 sp.excludeDataInTheCurrentTransaction(false); 567 results = serviceRegistry.getSearchService().query(sp); 568 assertEquals(15, results.length()); 569 results.close(); 570 571 tx.rollback(); 572 } 573 catch (Exception e) 574 { 575 throw new RuntimeException (e); 576 } 577 578 } 579 580 }); 581 582 thread.start(); 583 thread.join(); 584 585 tx = transactionService.getUserTransaction(); 586 tx.begin(); 587 588 SearchParameters sp = new SearchParameters(); 589 sp.addStore(rootNodeRef.getStoreRef()); 590 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 591 sp.setQuery("PATH:\"//.\""); 592 sp.excludeDataInTheCurrentTransaction(false); 593 ResultSet results = serviceRegistry.getSearchService().query(sp); 594 assertEquals(15, results.length()); 595 results.close(); 596 597 sp = new SearchParameters(); 598 sp.addStore(rootNodeRef.getStoreRef()); 599 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 600 sp.setQuery("PATH:\"//.\""); 601 sp.excludeDataInTheCurrentTransaction(false); 602 results = serviceRegistry.getSearchService().query(sp); 603 assertEquals(15, results.length()); 604 results.close(); 605 606 runBaseTests(); 607 608 sp = new SearchParameters(); 609 sp.addStore(rootNodeRef.getStoreRef()); 610 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 611 sp.setQuery("PATH:\"//.\""); 612 sp.excludeDataInTheCurrentTransaction(false); 613 results = serviceRegistry.getSearchService().query(sp); 614 assertEquals(15, results.length()); 615 results.close(); 616 617 Map <QName, Serializable > props = new HashMap <QName, Serializable >(); 618 props.put(ContentModel.PROP_TITLE, "woof"); 619 pns.addAspect(n1, ContentModel.ASPECT_TITLED, props); 620 621 sp = new SearchParameters(); 622 sp.addStore(rootNodeRef.getStoreRef()); 623 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 624 sp.setQuery("PATH:\"//.\""); 625 sp.excludeDataInTheCurrentTransaction(false); 626 results = serviceRegistry.getSearchService().query(sp); 627 assertEquals(15, results.length()); 628 results.close(); 629 630 pns.setProperty(n1, ContentModel.PROP_TITLE, "cube"); 631 632 sp = new SearchParameters(); 633 sp.addStore(rootNodeRef.getStoreRef()); 634 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 635 sp.setQuery("PATH:\"//.\""); 636 sp.excludeDataInTheCurrentTransaction(false); 637 results = serviceRegistry.getSearchService().query(sp); 638 assertEquals(15, results.length()); 639 results.close(); 640 641 tx.rollback(); 642 643 } 644 645 public void testRepeatPerformance() throws Exception 646 { 647 luceneFTS.pause(); 648 buildBaseIndex(); 649 runBaseTests(); 650 651 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 652 searcher.setNodeService(nodeService); 653 searcher.setDictionaryService(dictionaryService); 654 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 655 656 String query = "ID:\"" + rootNodeRef + "\""; 657 SearchParameters sp = new SearchParameters(); 659 sp.addStore(rootNodeRef.getStoreRef()); 660 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 661 sp.setQuery(query); 662 ResultSet results = searcher.query(sp); 663 assertEquals("No results found from query", 1, results.length()); 664 665 long start = System.nanoTime(); 666 int count = 1000; 667 for (int i = 0; i < count; i++) 669 { 670 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 671 sp.setQuery(query); 672 results = searcher.query(sp); 673 } 674 long end = System.nanoTime(); 675 double duration = ((double) (end - start)) / 1E6; double average = duration / (double) count; 678 System.out.println("Searched for identifier: \n" 679 + " count: " + count + "\n" + " average: " + average + " ms/search \n" 680 + " a million searches could take: " + (1E6 * average) / 1E3 / 60D + " minutes"); 681 if (average > 10.0) 683 { 684 logger.error("Search taking longer than 10ms: " + query); 685 } 686 } 687 688 public void testSort() throws Exception 689 { 690 luceneFTS.pause(); 691 buildBaseIndex(); 692 runBaseTests(); 693 694 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 695 searcher.setNodeService(nodeService); 696 searcher.setDictionaryService(dictionaryService); 697 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 698 699 SearchParameters sp = new SearchParameters(); 700 sp.addStore(rootNodeRef.getStoreRef()); 701 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 702 sp.setQuery("PATH:\"//.\""); 703 sp.addSort("ID", true); 704 ResultSet results = searcher.query(sp); 705 706 String current = null; 707 for (ResultSetRow row : results) 708 { 709 String id = row.getNodeRef().getId(); 710 711 if (current != null) 712 { 713 if (current.compareTo(id) > 0) 714 { 715 fail(); 716 } 717 } 718 current = id; 719 } 720 results.close(); 721 722 SearchParameters sp2 = new SearchParameters(); 723 sp2.addStore(rootNodeRef.getStoreRef()); 724 sp2.setLanguage(SearchService.LANGUAGE_LUCENE); 725 sp2.setQuery("PATH:\"//.\""); 726 sp2.addSort("ID", false); 727 results = searcher.query(sp2); 728 729 current = null; 730 for (ResultSetRow row : results) 731 { 732 String id = row.getNodeRef().getId(); 733 if (current != null) 734 { 735 if (current.compareTo(id) < 0) 736 { 737 fail(); 738 } 739 } 740 current = id; 741 } 742 results.close(); 743 744 luceneFTS.resume(); 745 746 747 748 SearchParameters sp3 = new SearchParameters(); 749 sp3.addStore(rootNodeRef.getStoreRef()); 750 sp3.setLanguage(SearchService.LANGUAGE_LUCENE); 751 sp3.setQuery("PATH:\"//.\""); 752 sp3.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_ASCENDING); 753 results = searcher.query(sp3); 754 755 int count = 0; 756 for (ResultSetRow row : results) 757 { 758 assertEquals(documentOrder[count++], row.getNodeRef()); 759 } 760 results.close(); 761 762 SearchParameters sp4 = new SearchParameters(); 763 sp4.addStore(rootNodeRef.getStoreRef()); 764 sp4.setLanguage(SearchService.LANGUAGE_LUCENE); 765 sp4.setQuery("PATH:\"//.\""); 766 sp4.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_DESCENDING); 767 results = searcher.query(sp4); 768 769 count = 1; 770 for (ResultSetRow row : results) 771 { 772 assertEquals(documentOrder[documentOrder.length - (count++)], row.getNodeRef()); 773 } 774 results.close(); 775 776 SearchParameters sp5 = new SearchParameters(); 777 sp5.addStore(rootNodeRef.getStoreRef()); 778 sp5.setLanguage(SearchService.LANGUAGE_LUCENE); 779 sp5.setQuery("PATH:\"//.\""); 780 sp5.addSort(SearchParameters.SORT_IN_SCORE_ORDER_ASCENDING); 781 results = searcher.query(sp5); 782 783 float score = 0; 784 for (ResultSetRow row : results) 785 { 786 assertTrue(score <= row.getScore()); 787 score = row.getScore(); 788 } 789 results.close(); 790 791 SearchParameters sp6 = new SearchParameters(); 792 sp6.addStore(rootNodeRef.getStoreRef()); 793 sp6.setLanguage(SearchService.LANGUAGE_LUCENE); 794 sp6.setQuery("PATH:\"//.\""); 795 sp6.addSort(SearchParameters.SORT_IN_SCORE_ORDER_DESCENDING); 796 results = searcher.query(sp6); 797 798 score = 1.0f; 799 for (ResultSetRow row : results) 800 { 801 assertTrue(score >= row.getScore()); 802 score = row.getScore(); 803 } 804 results.close(); 805 806 luceneFTS.resume(); 807 } 808 809 public void test1() throws Exception 810 { 811 luceneFTS.pause(); 812 buildBaseIndex(); 813 runBaseTests(); 814 luceneFTS.resume(); 815 } 816 817 public void test2() throws Exception 818 { 819 luceneFTS.pause(); 820 buildBaseIndex(); 821 runBaseTests(); 822 luceneFTS.resume(); 823 } 824 825 public void test3() throws Exception 826 { 827 luceneFTS.pause(); 828 buildBaseIndex(); 829 runBaseTests(); 830 luceneFTS.resume(); 831 } 832 833 public void test4() throws Exception 834 { 835 luceneFTS.pause(); 836 buildBaseIndex(); 837 838 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 839 searcher.setDictionaryService(dictionaryService); 840 841 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 842 "\\@\\{namespace\\}property\\-2:\"valuetwo\"", null, null); 843 results.close(); 844 luceneFTS.resume(); 845 } 846 847 public void test5() throws Exception 848 { 849 luceneFTS.pause(); 850 buildBaseIndex(); 851 runBaseTests(); 852 luceneFTS.resume(); 853 } 854 855 public void test6() throws Exception 856 { 857 luceneFTS.pause(); 858 buildBaseIndex(); 859 runBaseTests(); 860 luceneFTS.resume(); 861 } 862 863 public void testNoOp() throws Exception 864 { 865 luceneFTS.pause(); 866 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 867 + System.currentTimeMillis() + "_1", indexerAndSearcher); 868 869 indexer.setNodeService(nodeService); 870 indexer.setLuceneIndexLock(luceneIndexLock); 871 indexer.setDictionaryService(dictionaryService); 872 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 873 indexer.setContentService(contentService); 874 875 indexer.prepare(); 876 indexer.commit(); 877 luceneFTS.resume(); 878 } 879 880 886 887 public void testStandAloneIndexerCommit() throws Exception 888 { 889 luceneFTS.pause(); 890 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 891 + System.currentTimeMillis() + "_1", indexerAndSearcher); 892 893 indexer.setNodeService(nodeService); 894 indexer.setLuceneIndexLock(luceneIndexLock); 895 indexer.setDictionaryService(dictionaryService); 896 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 897 indexer.setContentService(contentService); 898 899 901 indexer.createNode(new ChildAssociationRef(null, null, null, rootNodeRef)); 902 indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName 903 .createQName("{namespace}one"), n1)); 904 indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName 905 .createQName("{namespace}two"), n2)); 906 indexer.updateNode(n1); 907 910 indexer.prepare(); 911 indexer.commit(); 912 913 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 914 searcher.setNodeService(nodeService); 915 searcher.setDictionaryService(dictionaryService); 916 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 917 918 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 919 "\\@\\{namespace\\}property\\-2:\"valuetwo\"", null, null); 920 simpleResultSetTest(results); 921 922 ChildAssocRefResultSet r2 = new ChildAssocRefResultSet(nodeService, results.getNodeRefs(), null, false); 923 simpleResultSetTest(r2); 924 925 ChildAssocRefResultSet r3 = new ChildAssocRefResultSet(nodeService, results.getNodeRefs(), null, true); 926 simpleResultSetTest(r3); 927 928 ChildAssocRefResultSet r4 = new ChildAssocRefResultSet(nodeService, results.getChildAssocRefs(), null); 929 simpleResultSetTest(r4); 930 931 DetachedResultSet r5 = new DetachedResultSet(results, null); 932 simpleResultSetTest(r5); 933 934 DetachedResultSet r6 = new DetachedResultSet(r2, null); 935 simpleResultSetTest(r6); 936 937 DetachedResultSet r7 = new DetachedResultSet(r3, null); 938 simpleResultSetTest(r7); 939 940 DetachedResultSet r8 = new DetachedResultSet(r4, null); 941 simpleResultSetTest(r8); 942 943 DetachedResultSet r9 = new DetachedResultSet(r5, null); 944 simpleResultSetTest(r9); 945 946 results.close(); 947 948 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@\\{namespace\\}property\\-1:\"valueone\"", 949 null, null); 950 assertEquals(2, results.length()); 951 assertEquals(n2.getId(), results.getNodeRef(0).getId()); 952 assertEquals(n1.getId(), results.getNodeRef(1).getId()); 953 assertEquals(1.0f, results.getScore(0)); 954 assertEquals(1.0f, results.getScore(1)); 955 results.close(); 956 957 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@namespace\\:property\\-1:\"valueone\"", null, 958 null); 959 assertEquals(2, results.length()); 960 assertEquals(n2.getId(), results.getNodeRef(0).getId()); 961 assertEquals(n1.getId(), results.getNodeRef(1).getId()); 962 assertEquals(1.0f, results.getScore(0)); 963 assertEquals(1.0f, results.getScore(1)); 964 results.close(); 965 966 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@property\\-1:\"valueone\"", null, null); 967 assertEquals(2, results.length()); 968 assertEquals(n2.getId(), results.getNodeRef(0).getId()); 969 assertEquals(n1.getId(), results.getNodeRef(1).getId()); 970 assertEquals(1.0f, results.getScore(0)); 971 assertEquals(1.0f, results.getScore(1)); 972 results.close(); 973 974 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@property\\-1:\"Valueone\"", null, null); 975 assertEquals(2, results.length()); 976 assertEquals(n2.getId(), results.getNodeRef(0).getId()); 977 assertEquals(n1.getId(), results.getNodeRef(1).getId()); 978 assertEquals(1.0f, results.getScore(0)); 979 assertEquals(1.0f, results.getScore(1)); 980 results.close(); 981 982 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@property\\-1:ValueOne", null, null); 983 assertEquals(2, results.length()); 984 assertEquals(n2.getId(), results.getNodeRef(0).getId()); 985 assertEquals(n1.getId(), results.getNodeRef(1).getId()); 986 assertEquals(1.0f, results.getScore(0)); 987 assertEquals(1.0f, results.getScore(1)); 988 results.close(); 989 990 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@property\\-1:valueone", null, null); 991 assertEquals(2, results.length()); 992 assertEquals(n2.getId(), results.getNodeRef(0).getId()); 993 assertEquals(n1.getId(), results.getNodeRef(1).getId()); 994 assertEquals(1.0f, results.getScore(0)); 995 assertEquals(1.0f, results.getScore(1)); 996 results.close(); 997 998 QName qname = QName.createQName("", "property-1"); 999 1000 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ID:\"" + n1.toString() + "\"", null, null); 1001 1002 assertEquals(2, results.length()); 1003 1004 results.close(); 1005 luceneFTS.resume(); 1006 } 1007 1008 private void simpleResultSetTest(ResultSet results) 1009 { 1010 assertEquals(1, results.length()); 1011 assertEquals(n2.getId(), results.getNodeRef(0).getId()); 1012 assertEquals(n2, results.getNodeRef(0)); 1013 assertEquals(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName 1014 .createQName("{namespace}two"), n2), results.getChildAssocRef(0)); 1015 assertEquals(1, results.getChildAssocRefs().size()); 1016 assertNotNull(results.getChildAssocRefs()); 1017 assertEquals(0, results.getRow(0).getIndex()); 1018 assertEquals(1.0f, results.getRow(0).getScore()); 1019 assertEquals(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName 1020 .createQName("{namespace}two"), n2), results.getRow(0).getChildAssocRef()); 1021 assertEquals(n2, results.getRow(0).getNodeRef()); 1022 assertEquals(QName.createQName("{namespace}two"), results.getRow(0).getQName()); 1023 assertEquals("valuetwo", results.getRow(0).getValue(QName.createQName("{namespace}property-2"))); 1024 for (ResultSetRow row : results) 1025 { 1026 assertNotNull(row); 1027 } 1028 } 1029 1030 public void testStandAlonePathIndexer() throws Exception 1031 { 1032 luceneFTS.pause(); 1033 buildBaseIndex(); 1034 1035 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 1036 searcher.setNodeService(nodeService); 1037 searcher.setDictionaryService(dictionaryService); 1038 1039 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@\\{namespace\\}property-1:valueone", 1040 null, null); 1041 try 1042 { 1043 assertEquals(2, results.length()); 1044 assertEquals(n1.getId(), results.getNodeRef(0).getId()); 1045 assertEquals(n2.getId(), results.getNodeRef(1).getId()); 1046 1049 QName qname = QName.createQName("", "property-1"); 1050 1051 } finally 1052 { 1053 results.close(); 1054 } 1055 1056 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "+ID:\"" + n1.toString() + "\"", null, null); 1057 try 1058 { 1059 assertEquals(2, results.length()); 1060 } finally 1061 { 1062 results.close(); 1063 } 1064 1065 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ID:\"" + rootNodeRef.toString() + "\"", null, 1066 null); 1067 try 1068 { 1069 assertEquals(1, results.length()); 1070 } finally 1071 { 1072 results.close(); 1073 } 1074 luceneFTS.resume(); 1075 } 1076 1077 private void buildBaseIndex() 1078 { 1079 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 1080 + System.currentTimeMillis() + "_" + (new Random ().nextInt()), indexerAndSearcher); 1081 indexer.setNodeService(nodeService); 1082 indexer.setLuceneIndexLock(luceneIndexLock); 1083 indexer.setDictionaryService(dictionaryService); 1084 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 1085 indexer.setContentService(contentService); 1086 indexer.createNode(new ChildAssociationRef(null, null, null, rootNodeRef)); 1088 indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName 1089 .createQName("{namespace}one"), n1)); 1090 indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName 1091 .createQName("{namespace}two"), n2)); 1092 indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName 1093 .createQName("{namespace}three"), n3)); 1094 indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName 1095 .createQName("{namespace}four"), n4)); 1096 indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n1, QName.createQName("{namespace}five"), n5)); 1097 indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n1, QName.createQName("{namespace}six"), n6)); 1098 indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName.createQName("{namespace}seven"), n7)); 1099 indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName.createQName("{namespace}eight"), n8)); 1100 indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n5, QName.createQName("{namespace}nine"), n9)); 1101 indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n5, QName.createQName("{namespace}ten"), n10)); 1102 indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n5, QName.createQName("{namespace}eleven"), n11)); 1103 indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n5, QName.createQName("{namespace}twelve"), n12)); 1104 indexer 1105 .createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n12, QName.createQName("{namespace}thirteen"), 1106 n13)); 1107 indexer 1108 .createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n13, QName.createQName("{namespace}fourteen"), 1109 n14)); 1110 indexer.prepare(); 1111 indexer.commit(); 1112 } 1113 1114 public void testAllPathSearch() throws Exception 1115 { 1116 luceneFTS.pause(); 1117 buildBaseIndex(); 1118 1119 runBaseTests(); 1120 luceneFTS.resume(); 1121 } 1122 1123 private void runBaseTests() 1124 { 1125 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 1126 searcher.setNodeService(nodeService); 1127 searcher.setDictionaryService(dictionaryService); 1128 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 1129 searcher.setQueryRegister(queryRegisterComponent); 1130 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null, null); 1131 assertEquals(1, results.length()); 1132 results.close(); 1133 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null, null); 1142 assertEquals(1, results.length()); 1143 results.close(); 1144 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null, null); 1145 assertEquals(1, results.length()); 1146 results.close(); 1147 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null, null); 1148 assertEquals(1, results.length()); 1149 results.close(); 1150 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null, null); 1151 assertEquals(1, results.length()); 1152 results.close(); 1153 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null, null); 1154 assertEquals(0, results.length()); 1155 results.close(); 1156 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null, 1157 null); 1158 assertEquals(0, results.length()); 1159 results.close(); 1160 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null, 1161 null); 1162 assertEquals(0, results.length()); 1163 results.close(); 1164 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null, 1165 null); 1166 assertEquals(0, results.length()); 1167 results.close(); 1168 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null, 1169 null); 1170 assertEquals(0, results.length()); 1171 results.close(); 1172 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null, 1173 null); 1174 assertEquals(1, results.length()); 1175 results.close(); 1176 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null, 1177 null); 1178 assertEquals(1, results.length()); 1179 results.close(); 1180 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null, 1181 null); 1182 assertEquals(1, results.length()); 1183 results.close(); 1184 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", 1185 null, null); 1186 assertEquals(1, results.length()); 1187 results.close(); 1188 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", 1189 null, null); 1190 assertEquals(1, results.length()); 1191 results.close(); 1192 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", 1193 null, null); 1194 assertEquals(0, results.length()); 1195 results.close(); 1196 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", 1197 null, null); 1198 assertEquals(0, results.length()); 1199 results.close(); 1200 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", 1201 null, null); 1202 assertEquals(0, results.length()); 1203 results.close(); 1204 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", 1205 null, null); 1206 assertEquals(0, results.length()); 1207 results.close(); 1208 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1209 "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null, null); 1210 assertEquals(1, results.length()); 1211 results.close(); 1212 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1213 "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null, null); 1214 assertEquals(1, results.length()); 1215 results.close(); 1216 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1217 "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null, null); 1218 assertEquals(1, results.length()); 1219 results.close(); 1220 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1221 "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null, null); 1222 assertEquals(1, results.length()); 1223 results.close(); 1224 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1225 "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null, null); 1226 assertEquals(1, results.length()); 1227 results.close(); 1228 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1229 "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null, 1230 null); 1231 assertEquals(1, results.length()); 1232 results.close(); 1233 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null, null); 1234 assertEquals(5, results.length()); 1235 results.close(); 1236 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/namespace:*/namespace:*\"", 1237 null, null); 1238 assertEquals(8, results.length()); 1239 results.close(); 1240 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null, null); 1241 assertEquals(6, results.length()); 1242 results.close(); 1243 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null, 1244 null); 1245 assertEquals(1, results.length()); 1246 results.close(); 1247 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1248 "PATH_WITH_REPEATS:\"/namespace:*/namespace:*/namespace:*\"", null, null); 1249 assertEquals(8, results.length()); 1250 results.close(); 1251 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", 1252 null, null); 1253 assertEquals(5, results.length()); 1254 results.close(); 1255 results = searcher 1256 .query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null, null); 1257 assertEquals(4, results.length()); 1258 results.close(); 1259 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1260 "PATH:\"/namespace:*/namespace:five/namespace:*\"", null, null); 1261 assertEquals(5, results.length()); 1262 results.close(); 1263 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1264 "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null, null); 1265 assertEquals(1, results.length()); 1266 results.close(); 1267 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null, null); 1268 assertEquals(5, results.length()); 1269 results.close(); 1270 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/*/*\"", null, null); 1271 assertEquals(8, results.length()); 1272 results.close(); 1273 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null, null); 1274 assertEquals(6, results.length()); 1275 results.close(); 1276 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null, null); 1277 assertEquals(1, results.length()); 1278 results.close(); 1279 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/*/*/*\"", null, null); 1280 assertEquals(8, results.length()); 1281 results.close(); 1282 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null, null); 1283 assertEquals(5, results.length()); 1284 results.close(); 1285 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null, null); 1286 assertEquals(4, results.length()); 1287 results.close(); 1288 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null, null); 1289 assertEquals(5, results.length()); 1290 results.close(); 1291 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null, 1292 null); 1293 assertEquals(1, results.length()); 1294 results.close(); 1295 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//.\"", null, null); 1296 assertEquals(26, results.length()); 1297 results.close(); 1298 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null, null); 1299 assertEquals(15, results.length()); 1300 results.close(); 1301 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null, null); 1302 assertEquals(14, results.length()); 1303 results.close(); 1304 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*\"", null, null); 1305 assertEquals(25, results.length()); 1306 results.close(); 1307 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null, null); 1308 assertEquals(14, results.length()); 1309 results.close(); 1310 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*/.\"", null, null); 1311 assertEquals(25, results.length()); 1312 results.close(); 1313 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null, null); 1314 assertEquals(14, results.length()); 1315 results.close(); 1316 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*/./.\"", null, null); 1317 assertEquals(25, results.length()); 1318 results.close(); 1319 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//./*\"", null, null); 1320 assertEquals(25, results.length()); 1321 results.close(); 1322 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null, null); 1323 assertEquals(14, results.length()); 1324 results.close(); 1325 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null, null); 1326 assertEquals(14, results.length()); 1327 results.close(); 1328 results = searcher 1329 .query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//././*/././.\"", null, null); 1330 assertEquals(25, results.length()); 1331 results.close(); 1332 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null, null); 1333 assertEquals(1, results.length()); 1334 results.close(); 1335 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//common\"", null, null); 1336 assertEquals(7, results.length()); 1337 results.close(); 1338 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null, null); 1339 assertEquals(1, results.length()); 1340 results.close(); 1341 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one//common\"", null, null); 1342 assertEquals(5, results.length()); 1343 results.close(); 1344 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null, null); 1345 assertEquals(6, results.length()); 1346 results.close(); 1347 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one/five//*\"", null, null); 1348 assertEquals(9, results.length()); 1349 results.close(); 1350 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null, null); 1351 assertEquals(7, results.length()); 1352 results.close(); 1353 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one/five//.\"", null, null); 1354 assertEquals(10, results.length()); 1355 results.close(); 1356 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null, null); 1357 assertEquals(1, results.length()); 1358 results.close(); 1359 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null, null); 1360 assertEquals(1, results.length()); 1361 results.close(); 1362 results = searcher 1363 .query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen//.\"", null, null); 1364 assertEquals(1, results.length()); 1365 results.close(); 1366 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen//.//.\"", null, 1367 null); 1368 assertEquals(1, results.length()); 1369 results.close(); 1370 1371 1373 QName qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1374 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"1\"", null, 1375 null); 1376 assertEquals(1, results.length()); 1377 assertNotNull(results.getRow(0).getValue(qname)); 1378 results.close(); 1379 1380 qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1381 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":1", null, 1382 null); 1383 assertEquals(1, results.length()); 1384 assertNotNull(results.getRow(0).getValue(qname)); 1385 results.close(); 1386 1387 qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1388 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"01\"", null, 1389 null); 1390 assertEquals(1, results.length()); 1391 assertNotNull(results.getRow(0).getValue(qname)); 1392 results.close(); 1393 1394 qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1395 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":01", null, 1396 null); 1397 assertEquals(1, results.length()); 1398 assertNotNull(results.getRow(0).getValue(qname)); 1399 results.close(); 1400 1401 qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1402 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + escapeQName(qname) + ":\"001\"", null, 1403 null); 1404 assertEquals(1, results.length()); 1405 assertNotNull(results.getRow(0).getValue(qname)); 1406 results.close(); 1407 1408 qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1409 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@test\\:int\\-ista:\"0001\"", null, 1410 null); 1411 assertEquals(1, results.length()); 1412 assertNotNull(results.getRow(0).getValue(qname)); 1413 results.close(); 1414 1415 qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1416 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO 2]", null, 1417 null); 1418 assertEquals(1, results.length()); 1419 assertNotNull(results.getRow(0).getValue(qname)); 1420 results.close(); 1421 1422 qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1423 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO 1}", null, 1424 null); 1425 assertEquals(0, results.length()); 1426 results.close(); 1427 1428 qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1429 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{1 TO 2}", null, 1430 null); 1431 assertEquals(0, results.length()); 1432 results.close(); 1433 1434 qname = QName.createQName(TEST_NAMESPACE, "long-ista"); 1435 results = searcher 1436 .query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"2\"", null, null); 1437 assertEquals(1, results.length()); 1438 assertNotNull(results.getRow(0).getValue(qname)); 1439 results.close(); 1440 1441 qname = QName.createQName(TEST_NAMESPACE, "long-ista"); 1442 results = searcher 1443 .query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"02\"", null, null); 1444 assertEquals(1, results.length()); 1445 assertNotNull(results.getRow(0).getValue(qname)); 1446 results.close(); 1447 1448 qname = QName.createQName(TEST_NAMESPACE, "long-ista"); 1449 results = searcher 1450 .query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"002\"", null, null); 1451 assertEquals(1, results.length()); 1452 assertNotNull(results.getRow(0).getValue(qname)); 1453 results.close(); 1454 1455 qname = QName.createQName(TEST_NAMESPACE, "long-ista"); 1456 results = searcher 1457 .query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"0002\"", null, null); 1458 assertEquals(1, results.length()); 1459 assertNotNull(results.getRow(0).getValue(qname)); 1460 results.close(); 1461 1462 qname = QName.createQName(TEST_NAMESPACE, "long-ista"); 1463 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO 2]", null, 1464 null); 1465 assertEquals(1, results.length()); 1466 assertNotNull(results.getRow(0).getValue(qname)); 1467 results.close(); 1468 1469 qname = QName.createQName(TEST_NAMESPACE, "long-ista"); 1470 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO 2}", null, 1471 null); 1472 assertEquals(0, results.length()); 1473 results.close(); 1474 1475 qname = QName.createQName(TEST_NAMESPACE, "long-ista"); 1476 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{2 TO 3}", null, 1477 null); 1478 assertEquals(0, results.length()); 1479 results.close(); 1480 1481 qname = QName.createQName(TEST_NAMESPACE, "float-ista"); 1482 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"3.4\"", null, 1483 null); 1484 assertEquals(1, results.length()); 1485 assertNotNull(results.getRow(0).getValue(qname)); 1486 results.close(); 1487 1488 qname = QName.createQName(TEST_NAMESPACE, "float-ista"); 1489 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3 TO 4]", null, 1490 null); 1491 assertEquals(1, results.length()); 1492 assertNotNull(results.getRow(0).getValue(qname)); 1493 results.close(); 1494 1495 qname = QName.createQName(TEST_NAMESPACE, "float-ista"); 1496 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3.3 TO 3.4]", null, 1497 null); 1498 assertEquals(1, results.length()); 1499 assertNotNull(results.getRow(0).getValue(qname)); 1500 results.close(); 1501 1502 qname = QName.createQName(TEST_NAMESPACE, "float-ista"); 1503 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{3.3 TO 3.4}", null, 1504 null); 1505 assertEquals(0, results.length()); 1506 results.close(); 1507 1508 1509 qname = QName.createQName(TEST_NAMESPACE, "float-ista"); 1510 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"3.40\"", null, 1511 null); 1512 assertEquals(1, results.length()); 1513 assertNotNull(results.getRow(0).getValue(qname)); 1514 results.close(); 1515 1516 qname = QName.createQName(TEST_NAMESPACE, "float-ista"); 1517 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"03.4\"", null, 1518 null); 1519 assertEquals(1, results.length()); 1520 assertNotNull(results.getRow(0).getValue(qname)); 1521 results.close(); 1522 1523 qname = QName.createQName(TEST_NAMESPACE, "float-ista"); 1524 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"03.40\"", null, 1525 null); 1526 assertEquals(1, results.length()); 1527 assertNotNull(results.getRow(0).getValue(qname)); 1528 results.close(); 1529 1530 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1531 + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"5.6\"", null, null); 1532 assertEquals(1, results.length()); 1533 results.close(); 1534 1535 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1536 + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"05.6\"", null, null); 1537 assertEquals(1, results.length()); 1538 results.close(); 1539 1540 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1541 + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"5.60\"", null, null); 1542 assertEquals(1, results.length()); 1543 results.close(); 1544 1545 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1546 + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"05.60\"", null, null); 1547 assertEquals(1, results.length()); 1548 results.close(); 1549 1550 qname = QName.createQName(TEST_NAMESPACE, "double-ista"); 1551 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[5.5 TO 5.7]", null, 1552 null); 1553 assertEquals(1, results.length()); 1554 assertNotNull(results.getRow(0).getValue(qname)); 1555 results.close(); 1556 1557 qname = QName.createQName(TEST_NAMESPACE, "double-ista"); 1558 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.5 TO 5.6}", null, 1559 null); 1560 assertEquals(0, results.length()); 1561 results.close(); 1562 1563 qname = QName.createQName(TEST_NAMESPACE, "double-ista"); 1564 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.6 TO 5.7}", null, 1565 null); 1566 assertEquals(0, results.length()); 1567 results.close(); 1568 1569 1570 Date date = new Date (); 1571 String sDate = CachingDateFormat.getDateFormat().format(date); 1572 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1573 + escapeQName(QName.createQName(TEST_NAMESPACE, "date-ista")) + ":\"" + sDate + "\"", null, null); 1574 assertEquals(1, results.length()); 1575 results.close(); 1576 1577 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1578 + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":\"" + sDate + "\"", null, null); 1579 assertEquals(1, results.length()); 1580 results.close(); 1581 1582 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1583 + escapeQName(QName.createQName(TEST_NAMESPACE, "boolean-ista")) + ":\"true\"", null, null); 1584 assertEquals(1, results.length()); 1585 results.close(); 1586 1587 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1588 + escapeQName(QName.createQName(TEST_NAMESPACE, "qname-ista")) + ":\"{wibble}wobble\"", null, null); 1589 assertEquals(1, results.length()); 1590 results.close(); 1591 1592 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1593 + escapeQName(QName.createQName(TEST_NAMESPACE, "category-ista")) 1594 + ":\"" 1595 + DefaultTypeConverter.INSTANCE.convert(String .class, new NodeRef(rootNodeRef.getStoreRef(), 1596 "CategoryId")) + "\"", null, null); 1597 assertEquals(1, results.length()); 1598 results.close(); 1599 1600 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1601 + escapeQName(QName.createQName(TEST_NAMESPACE, "noderef-ista")) + ":\"" + n1 + "\"", null, null); 1602 assertEquals(1, results.length()); 1603 results.close(); 1604 1605 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1606 + escapeQName(QName.createQName(TEST_NAMESPACE, "path-ista")) + ":\"" + nodeService.getPath(n3) + "\"", 1607 null, null); 1608 assertEquals(1, results.length()); 1609 assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); 1610 results.close(); 1611 1612 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testType.toString() + "\"", null, 1613 null); 1614 assertEquals(1, results.length()); 1615 results.close(); 1616 1617 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testSuperType.toString() + "\"", 1618 null, null); 1619 assertEquals(13, results.length()); 1620 results.close(); 1621 1622 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASPECT:\"" + ISO9075.getXPathName(testAspect) + "\"", null, 1623 null); 1624 assertEquals(1, results.length()); 1625 results.close(); 1626 1627 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASPECT:\"" + ISO9075.getXPathName(testSuperAspect) + "\"", 1628 null, null); 1629 assertEquals(1, results.length()); 1630 results.close(); 1631 1632 1634 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"fox\"", null, null); 1635 assertEquals(1, results.length()); 1636 results.close(); 1637 1638 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@"+LuceneQueryParser.escape(ContentModel.PROP_CONTENT.toString())+":\"fox\"", null, null); 1639 assertEquals(1, results.length()); 1640 results.close(); 1641 1642 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@"+LuceneQueryParser.escape(ContentModel.PROP_CONTENT.toString())+".mimetype:\"text/plain\"", null, null); 1643 assertEquals(1, results.length()); 1644 results.close(); 1645 1646 QName queryQName = QName.createQName("alf:test1", namespacePrefixResolver); 1647 results = searcher.query(rootNodeRef.getStoreRef(), queryQName, null); 1648 assertEquals(1, results.length()); 1649 results.close(); 1650 1651 1653 queryQName = QName.createQName("alf:test2", namespacePrefixResolver); 1654 results = searcher.query(rootNodeRef.getStoreRef(), queryQName, null); 1655 assertEquals(1, results.length()); 1656 results.close(); 1657 1658 queryQName = QName.createQName("alf:test2", namespacePrefixResolver); 1659 QueryParameter qp = new QueryParameter(QName.createQName("alf:banana", namespacePrefixResolver), "woof"); 1660 results = searcher.query(rootNodeRef.getStoreRef(), queryQName, new QueryParameter[] { qp }); 1661 assertEquals(0, results.length()); 1662 results.close(); 1663 1664 queryQName = QName.createQName("alf:test3", namespacePrefixResolver); 1665 qp = new QueryParameter(QName.createQName("alf:banana", namespacePrefixResolver), "/one/five//*"); 1666 results = searcher.query(rootNodeRef.getStoreRef(), queryQName, new QueryParameter[] { qp }); 1667 assertEquals(6, results.length()); 1668 results.close(); 1669 1670 QueryParameterDefImpl paramDef = new QueryParameterDefImpl(QName.createQName("alf:lemur", 1672 namespacePrefixResolver), (DataTypeDefinition) null, true, "fox"); 1673 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"${alf:lemur}\"", null, 1674 new QueryParameterDefinition[] { paramDef }); 1675 assertEquals(1, results.length()); 1676 results.close(); 1677 1678 paramDef = new QueryParameterDefImpl(QName.createQName("alf:intvalue", namespacePrefixResolver), 1679 (DataTypeDefinition) null, true, "1"); 1680 qname = QName.createQName(TEST_NAMESPACE, "int-ista"); 1681 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 1682 + escapeQName(qname) + ":\"${alf:intvalue}\"", null, new QueryParameterDefinition[] { paramDef }); 1683 assertEquals(1, results.length()); 1684 assertNotNull(results.getRow(0).getValue(qname)); 1685 results.close(); 1686 1687 } 1688 1689 public void testPathSearch() throws Exception 1690 { 1691 luceneFTS.pause(); 1692 buildBaseIndex(); 1693 1694 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 1695 searcher.setNodeService(nodeService); 1696 searcher.setDictionaryService(dictionaryService); 1697 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 1698 1699 1701 ResultSet 1702 1703 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null, null); 1704 assertEquals(1, results.length()); 1705 results.close(); 1706 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//common\"", null, null); 1707 assertEquals(7, results.length()); 1708 results.close(); 1709 1710 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null, null); 1711 assertEquals(1, results.length()); 1712 results.close(); 1713 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one//common\"", null, null); 1714 assertEquals(5, results.length()); 1715 results.close(); 1716 1717 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null, null); 1718 assertEquals(6, results.length()); 1719 results.close(); 1720 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one/five//*\"", null, null); 1721 assertEquals(9, results.length()); 1722 results.close(); 1723 1724 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null, null); 1725 assertEquals(7, results.length()); 1726 results.close(); 1727 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one/five//.\"", null, null); 1728 assertEquals(10, results.length()); 1729 results.close(); 1730 1731 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null, null); 1732 assertEquals(1, results.length()); 1733 results.close(); 1734 1735 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null, null); 1736 assertEquals(1, results.length()); 1737 results.close(); 1738 luceneFTS.resume(); 1739 } 1740 1741 public void testXPathSearch() throws Exception 1742 { 1743 luceneFTS.pause(); 1744 buildBaseIndex(); 1745 1746 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 1747 searcher.setNodeService(nodeService); 1748 searcher.setDictionaryService(dictionaryService); 1749 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 1750 1751 1753 ResultSet 1754 1755 results = searcher.query(rootNodeRef.getStoreRef(), "xpath", "//./*", null, null); 1756 assertEquals(14, results.length()); 1757 results.close(); 1758 luceneFTS.resume(); 1759 1760 QueryParameterDefinition paramDef = new QueryParameterDefImpl(QName.createQName("alf:query", 1761 namespacePrefixResolver), (DataTypeDefinition) null, true, "//./*"); 1762 results = searcher.query(rootNodeRef.getStoreRef(), "xpath", "${alf:query}", null, 1763 new QueryParameterDefinition[] { paramDef }); 1764 assertEquals(14, results.length()); 1765 results.close(); 1766 } 1767 1768 public void testMissingIndex() throws Exception 1769 { 1770 luceneFTS.pause(); 1771 StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "_missing_"); 1772 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(storeRef, indexerAndSearcher); 1773 searcher.setNodeService(nodeService); 1774 searcher.setDictionaryService(dictionaryService); 1775 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 1776 1777 1779 ResultSet 1780 1781 results = searcher.query(storeRef, "xpath", "//./*", null, null); 1782 assertEquals(0, results.length()); 1783 luceneFTS.resume(); 1784 } 1785 1786 public void testUpdateIndex() throws Exception 1787 { 1788 luceneFTS.pause(); 1789 buildBaseIndex(); 1790 1791 runBaseTests(); 1792 1793 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 1794 + System.currentTimeMillis(), indexerAndSearcher); 1795 indexer.setNodeService(nodeService); 1796 indexer.setLuceneIndexLock(luceneIndexLock); 1797 indexer.setDictionaryService(dictionaryService); 1798 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 1799 indexer.setContentService(contentService); 1800 1801 indexer.updateNode(rootNodeRef); 1802 indexer.updateNode(n1); 1803 indexer.updateNode(n2); 1804 indexer.updateNode(n3); 1805 indexer.updateNode(n4); 1806 indexer.updateNode(n5); 1807 indexer.updateNode(n6); 1808 indexer.updateNode(n7); 1809 indexer.updateNode(n8); 1810 indexer.updateNode(n9); 1811 indexer.updateNode(n10); 1812 indexer.updateNode(n11); 1813 indexer.updateNode(n12); 1814 indexer.updateNode(n13); 1815 indexer.updateNode(n14); 1816 1817 indexer.commit(); 1818 1819 runBaseTests(); 1820 luceneFTS.resume(); 1821 } 1822 1823 public void testDeleteLeaf() throws Exception 1824 { 1825 luceneFTS.pause(); 1826 buildBaseIndex(); 1827 runBaseTests(); 1828 1829 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 1830 + System.currentTimeMillis(), indexerAndSearcher); 1831 indexer.setNodeService(nodeService); 1832 indexer.setLuceneIndexLock(luceneIndexLock); 1833 indexer.setDictionaryService(dictionaryService); 1834 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 1835 indexer.setContentService(contentService); 1836 1837 indexer 1838 .deleteNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n13, QName.createQName("{namespace}fourteen"), 1839 n14)); 1840 1841 indexer.commit(); 1842 1843 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 1844 searcher.setNodeService(nodeService); 1845 searcher.setDictionaryService(dictionaryService); 1846 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 1847 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null, null); 1848 assertEquals(1, results.length()); 1849 results.close(); 1850 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null, null); 1851 assertEquals(1, results.length()); 1852 results.close(); 1853 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null, null); 1854 assertEquals(1, results.length()); 1855 results.close(); 1856 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null, null); 1857 assertEquals(1, results.length()); 1858 results.close(); 1859 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null, null); 1860 assertEquals(1, results.length()); 1861 results.close(); 1862 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null, null); 1863 assertEquals(0, results.length()); 1864 results.close(); 1865 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null, 1866 null); 1867 assertEquals(0, results.length()); 1868 results.close(); 1869 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null, 1870 null); 1871 assertEquals(0, results.length()); 1872 results.close(); 1873 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null, 1874 null); 1875 assertEquals(0, results.length()); 1876 results.close(); 1877 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null, 1878 null); 1879 assertEquals(0, results.length()); 1880 results.close(); 1881 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null, 1882 null); 1883 assertEquals(1, results.length()); 1884 results.close(); 1885 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null, 1886 null); 1887 assertEquals(1, results.length()); 1888 results.close(); 1889 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null, 1890 null); 1891 assertEquals(1, results.length()); 1892 results.close(); 1893 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", 1894 null, null); 1895 assertEquals(1, results.length()); 1896 results.close(); 1897 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", 1898 null, null); 1899 assertEquals(1, results.length()); 1900 results.close(); 1901 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", 1902 null, null); 1903 assertEquals(0, results.length()); 1904 results.close(); 1905 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", 1906 null, null); 1907 assertEquals(0, results.length()); 1908 results.close(); 1909 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", 1910 null, null); 1911 assertEquals(0, results.length()); 1912 results.close(); 1913 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", 1914 null, null); 1915 assertEquals(0, results.length()); 1916 results.close(); 1917 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1918 "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null, null); 1919 assertEquals(1, results.length()); 1920 results.close(); 1921 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1922 "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null, null); 1923 assertEquals(1, results.length()); 1924 results.close(); 1925 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1926 "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null, null); 1927 assertEquals(1, results.length()); 1928 results.close(); 1929 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1930 "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null, null); 1931 assertEquals(1, results.length()); 1932 results.close(); 1933 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1934 "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null, null); 1935 assertEquals(1, results.length()); 1936 results.close(); 1937 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1938 "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null, 1939 null); 1940 assertEquals(0, results.length()); 1941 results.close(); 1942 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null, null); 1943 assertEquals(5, results.length()); 1944 results.close(); 1945 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null, null); 1946 assertEquals(5, results.length()); 1947 results.close(); 1948 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/namespace:*/namespace:*\"", 1949 null, null); 1950 assertEquals(6, results.length()); 1951 results.close(); 1952 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null, 1953 null); 1954 assertEquals(1, results.length()); 1955 results.close(); 1956 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", 1957 null, null); 1958 assertEquals(4, results.length()); 1959 results.close(); 1960 results = searcher 1961 .query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null, null); 1962 assertEquals(3, results.length()); 1963 results.close(); 1964 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1965 "PATH:\"/namespace:*/namespace:five/namespace:*\"", null, null); 1966 assertEquals(4, results.length()); 1967 results.close(); 1968 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 1969 "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null, null); 1970 assertEquals(1, results.length()); 1971 results.close(); 1972 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null, null); 1973 assertEquals(5, results.length()); 1974 results.close(); 1975 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null, null); 1976 assertEquals(5, results.length()); 1977 results.close(); 1978 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/*/*\"", null, null); 1979 assertEquals(6, results.length()); 1980 results.close(); 1981 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null, null); 1982 assertEquals(1, results.length()); 1983 results.close(); 1984 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null, null); 1985 assertEquals(4, results.length()); 1986 results.close(); 1987 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null, null); 1988 assertEquals(3, results.length()); 1989 results.close(); 1990 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null, null); 1991 assertEquals(4, results.length()); 1992 results.close(); 1993 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null, 1994 null); 1995 assertEquals(1, results.length()); 1996 results.close(); 1997 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null, null); 1998 assertEquals(14, results.length()); 1999 results.close(); 2000 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//.\"", null, null); 2001 assertEquals(17, results.length()); 2002 results.close(); 2003 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null, null); 2004 assertEquals(13, results.length()); 2005 results.close(); 2006 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*\"", null, null); 2007 assertEquals(16, results.length()); 2008 results.close(); 2009 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null, null); 2010 assertEquals(13, results.length()); 2011 results.close(); 2012 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*/.\"", null, null); 2013 assertEquals(16, results.length()); 2014 results.close(); 2015 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null, null); 2016 assertEquals(13, results.length()); 2017 results.close(); 2018 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*/./.\"", null, null); 2019 assertEquals(16, results.length()); 2020 results.close(); 2021 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null, null); 2022 assertEquals(13, results.length()); 2023 results.close(); 2024 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//./*\"", null, null); 2025 assertEquals(16, results.length()); 2026 results.close(); 2027 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null, null); 2028 assertEquals(13, results.length()); 2029 results.close(); 2030 results = searcher 2031 .query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//././*/././.\"", null, null); 2032 assertEquals(16, results.length()); 2033 results.close(); 2034 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null, null); 2035 assertEquals(0, results.length()); 2036 results.close(); 2037 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null, null); 2038 assertEquals(0, results.length()); 2039 results.close(); 2040 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null, null); 2041 assertEquals(5, results.length()); 2042 results.close(); 2043 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one/five//*\"", null, null); 2044 assertEquals(5, results.length()); 2045 results.close(); 2046 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null, null); 2047 assertEquals(6, results.length()); 2048 results.close(); 2049 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null, null); 2050 assertEquals(1, results.length()); 2051 results.close(); 2052 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null, null); 2053 assertEquals(0, results.length()); 2054 results.close(); 2055 luceneFTS.resume(); 2056 } 2057 2058 public void testAddEscapedChild() throws Exception 2059 { 2060 String COMPLEX_LOCAL_NAME = " `¬¦!\"£$%^&*()-_=+\t\n\\\u0000[]{};'#:@~,./<>?\\|\u0123\u4567\u8900\uabcd\uefff_xT65A_"; 2061 2062 luceneFTS.pause(); 2063 buildBaseIndex(); 2064 runBaseTests(); 2065 2066 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 2067 + System.currentTimeMillis(), indexerAndSearcher); 2068 indexer.setNodeService(nodeService); 2069 indexer.setLuceneIndexLock(luceneIndexLock); 2070 indexer.setDictionaryService(dictionaryService); 2071 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 2072 indexer.setContentService(contentService); 2073 2074 ChildAssociationRef car = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName 2075 .createQName("{namespace}" + COMPLEX_LOCAL_NAME), testSuperType); 2076 indexer.createNode(car); 2077 2078 indexer.commit(); 2079 2080 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2081 searcher.setNodeService(nodeService); 2082 searcher.setDictionaryService(dictionaryService); 2083 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2084 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:" 2085 + ISO9075.encode(COMPLEX_LOCAL_NAME) + "\"", null, null); 2086 assertEquals(1, results.length()); 2087 results.close(); 2088 } 2089 2090 public void testDeleteContainer() throws Exception 2091 { 2092 luceneFTS.pause(); 2093 buildBaseIndex(); 2094 runBaseTests(); 2095 2096 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 2097 + System.currentTimeMillis(), indexerAndSearcher); 2098 indexer.setNodeService(nodeService); 2099 indexer.setLuceneIndexLock(luceneIndexLock); 2100 indexer.setDictionaryService(dictionaryService); 2101 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 2102 indexer.setContentService(contentService); 2103 2104 indexer 2105 .deleteNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n12, QName.createQName("{namespace}thirteen"), 2106 n13)); 2107 2108 indexer.commit(); 2109 2110 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2111 searcher.setNodeService(nodeService); 2112 searcher.setDictionaryService(dictionaryService); 2113 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2114 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null, null); 2115 assertEquals(1, results.length()); 2116 results.close(); 2117 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null, null); 2118 assertEquals(1, results.length()); 2119 results.close(); 2120 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null, null); 2121 assertEquals(1, results.length()); 2122 results.close(); 2123 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null, null); 2124 assertEquals(1, results.length()); 2125 results.close(); 2126 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null, null); 2127 assertEquals(1, results.length()); 2128 results.close(); 2129 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null, null); 2130 assertEquals(0, results.length()); 2131 results.close(); 2132 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null, 2133 null); 2134 assertEquals(0, results.length()); 2135 results.close(); 2136 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null, 2137 null); 2138 assertEquals(0, results.length()); 2139 results.close(); 2140 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null, 2141 null); 2142 assertEquals(0, results.length()); 2143 results.close(); 2144 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null, 2145 null); 2146 assertEquals(0, results.length()); 2147 results.close(); 2148 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null, 2149 null); 2150 assertEquals(1, results.length()); 2151 results.close(); 2152 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null, 2153 null); 2154 assertEquals(1, results.length()); 2155 results.close(); 2156 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null, 2157 null); 2158 assertEquals(1, results.length()); 2159 results.close(); 2160 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", 2161 null, null); 2162 assertEquals(1, results.length()); 2163 results.close(); 2164 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", 2165 null, null); 2166 assertEquals(1, results.length()); 2167 results.close(); 2168 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", 2169 null, null); 2170 assertEquals(0, results.length()); 2171 results.close(); 2172 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", 2173 null, null); 2174 assertEquals(0, results.length()); 2175 results.close(); 2176 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", 2177 null, null); 2178 assertEquals(0, results.length()); 2179 results.close(); 2180 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", 2181 null, null); 2182 assertEquals(0, results.length()); 2183 results.close(); 2184 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2185 "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null, null); 2186 assertEquals(1, results.length()); 2187 results.close(); 2188 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2189 "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null, null); 2190 assertEquals(1, results.length()); 2191 results.close(); 2192 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2193 "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null, null); 2194 assertEquals(1, results.length()); 2195 results.close(); 2196 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2197 "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null, null); 2198 assertEquals(1, results.length()); 2199 results.close(); 2200 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2201 "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null, null); 2202 assertEquals(0, results.length()); 2203 results.close(); 2204 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2205 "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null, 2206 null); 2207 assertEquals(0, results.length()); 2208 results.close(); 2209 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null, null); 2210 assertEquals(5, results.length()); 2211 results.close(); 2212 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/namespace:*\"", null, null); 2213 assertEquals(5, results.length()); 2214 results.close(); 2215 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null, null); 2216 assertEquals(4, results.length()); 2217 results.close(); 2218 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/namespace:*/namespace:*\"", 2219 null, null); 2220 assertEquals(5, results.length()); 2221 results.close(); 2222 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null, 2223 null); 2224 assertEquals(1, results.length()); 2225 results.close(); 2226 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", 2227 null, null); 2228 assertEquals(4, results.length()); 2229 results.close(); 2230 results = searcher 2231 .query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null, null); 2232 assertEquals(3, results.length()); 2233 results.close(); 2234 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2235 "PATH:\"/namespace:*/namespace:five/namespace:*\"", null, null); 2236 assertEquals(4, results.length()); 2237 results.close(); 2238 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2239 "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null, null); 2240 assertEquals(1, results.length()); 2241 results.close(); 2242 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null, null); 2243 assertEquals(5, results.length()); 2244 results.close(); 2245 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null, null); 2246 assertEquals(4, results.length()); 2247 results.close(); 2248 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/*/*\"", null, null); 2249 assertEquals(5, results.length()); 2250 results.close(); 2251 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null, null); 2252 assertEquals(1, results.length()); 2253 results.close(); 2254 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null, null); 2255 assertEquals(4, results.length()); 2256 results.close(); 2257 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/*/*/*\"", null, null); 2258 assertEquals(4, results.length()); 2259 results.close(); 2260 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null, null); 2261 assertEquals(3, results.length()); 2262 results.close(); 2263 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null, null); 2264 assertEquals(4, results.length()); 2265 results.close(); 2266 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null, 2267 null); 2268 assertEquals(1, results.length()); 2269 results.close(); 2270 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null, null); 2271 assertEquals(13, results.length()); 2272 results.close(); 2273 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//.\"", null, null); 2274 assertEquals(15, results.length()); 2275 results.close(); 2276 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null, null); 2277 assertEquals(12, results.length()); 2278 results.close(); 2279 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*\"", null, null); 2280 assertEquals(14, results.length()); 2281 results.close(); 2282 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null, null); 2283 assertEquals(12, results.length()); 2284 results.close(); 2285 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*/.\"", null, null); 2286 assertEquals(14, results.length()); 2287 results.close(); 2288 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null, null); 2289 assertEquals(12, results.length()); 2290 results.close(); 2291 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*/./.\"", null, null); 2292 assertEquals(14, results.length()); 2293 results.close(); 2294 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null, null); 2295 assertEquals(12, results.length()); 2296 results.close(); 2297 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//./*\"", null, null); 2298 assertEquals(14, results.length()); 2299 results.close(); 2300 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null, null); 2301 assertEquals(12, results.length()); 2302 results.close(); 2303 results = searcher 2304 .query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//././*/././.\"", null, null); 2305 assertEquals(14, results.length()); 2306 results.close(); 2307 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null, null); 2308 assertEquals(0, results.length()); 2309 results.close(); 2310 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null, null); 2311 assertEquals(0, results.length()); 2312 results.close(); 2313 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null, null); 2314 assertEquals(4, results.length()); 2315 results.close(); 2316 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null, null); 2317 assertEquals(5, results.length()); 2318 results.close(); 2319 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null, null); 2320 assertEquals(1, results.length()); 2321 results.close(); 2322 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null, null); 2323 assertEquals(0, results.length()); 2324 results.close(); 2325 luceneFTS.resume(); 2326 } 2327 2328 public void testDeleteAndAddReference() throws Exception 2329 { 2330 luceneFTS.pause(); 2331 buildBaseIndex(); 2332 runBaseTests(); 2333 2334 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 2335 + System.currentTimeMillis(), indexerAndSearcher); 2336 indexer.setNodeService(nodeService); 2337 indexer.setLuceneIndexLock(luceneIndexLock); 2338 indexer.setDictionaryService(dictionaryService); 2339 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 2340 indexer.setContentService(contentService); 2341 2342 nodeService.removeChild(n2, n13); 2343 indexer.deleteChildRelationship(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName 2344 .createQName("{namespace}link"), n13)); 2345 2346 indexer.commit(); 2347 2348 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2349 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2350 searcher.setNodeService(nodeService); 2351 searcher.setDictionaryService(dictionaryService); 2352 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null, null); 2353 assertEquals(1, results.length()); 2354 results.close(); 2355 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null, null); 2356 assertEquals(1, results.length()); 2357 results.close(); 2358 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null, null); 2359 assertEquals(1, results.length()); 2360 results.close(); 2361 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null, null); 2362 assertEquals(1, results.length()); 2363 results.close(); 2364 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null, null); 2365 assertEquals(1, results.length()); 2366 results.close(); 2367 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null, null); 2368 assertEquals(0, results.length()); 2369 results.close(); 2370 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null, 2371 null); 2372 assertEquals(0, results.length()); 2373 results.close(); 2374 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null, 2375 null); 2376 assertEquals(0, results.length()); 2377 results.close(); 2378 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null, 2379 null); 2380 assertEquals(0, results.length()); 2381 results.close(); 2382 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null, 2383 null); 2384 assertEquals(0, results.length()); 2385 results.close(); 2386 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null, 2387 null); 2388 assertEquals(1, results.length()); 2389 results.close(); 2390 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null, 2391 null); 2392 assertEquals(1, results.length()); 2393 results.close(); 2394 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null, 2395 null); 2396 assertEquals(1, results.length()); 2397 results.close(); 2398 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", 2399 null, null); 2400 assertEquals(1, results.length()); 2401 results.close(); 2402 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", 2403 null, null); 2404 assertEquals(1, results.length()); 2405 results.close(); 2406 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", 2407 null, null); 2408 assertEquals(0, results.length()); 2409 results.close(); 2410 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", 2411 null, null); 2412 assertEquals(0, results.length()); 2413 results.close(); 2414 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", 2415 null, null); 2416 assertEquals(0, results.length()); 2417 results.close(); 2418 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", 2419 null, null); 2420 assertEquals(0, results.length()); 2421 results.close(); 2422 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2423 "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null, null); 2424 assertEquals(1, results.length()); 2425 results.close(); 2426 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2427 "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null, null); 2428 assertEquals(1, results.length()); 2429 results.close(); 2430 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2431 "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null, null); 2432 assertEquals(1, results.length()); 2433 results.close(); 2434 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2435 "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null, null); 2436 assertEquals(1, results.length()); 2437 results.close(); 2438 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2439 "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null, null); 2440 assertEquals(1, results.length()); 2441 results.close(); 2442 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2443 "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null, 2444 null); 2445 assertEquals(1, results.length()); 2446 results.close(); 2447 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null, null); 2448 assertEquals(5, results.length()); 2449 results.close(); 2450 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null, null); 2451 assertEquals(5, results.length()); 2452 results.close(); 2453 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/namespace:*/namespace:*\"", 2454 null, null); 2455 assertEquals(7, results.length()); 2456 results.close(); 2457 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null, 2458 null); 2459 assertEquals(1, results.length()); 2460 results.close(); 2461 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", 2462 null, null); 2463 assertEquals(5, results.length()); 2464 results.close(); 2465 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2466 "PATH_WITH_REPEATS:\"/namespace:*/namespace:*/namespace:*\"", null, null); 2467 assertEquals(6, results.length()); 2468 results.close(); 2469 results = searcher 2470 .query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null, null); 2471 assertEquals(4, results.length()); 2472 results.close(); 2473 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2474 "PATH:\"/namespace:*/namespace:five/namespace:*\"", null, null); 2475 assertEquals(5, results.length()); 2476 results.close(); 2477 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2478 "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null, null); 2479 assertEquals(1, results.length()); 2480 results.close(); 2481 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null, null); 2482 assertEquals(5, results.length()); 2483 results.close(); 2484 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null, null); 2485 assertEquals(5, results.length()); 2486 results.close(); 2487 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/*/*\"", null, null); 2488 assertEquals(7, results.length()); 2489 results.close(); 2490 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null, null); 2491 assertEquals(1, results.length()); 2492 results.close(); 2493 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null, null); 2494 assertEquals(5, results.length()); 2495 results.close(); 2496 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/*/*/*\"", null, null); 2497 assertEquals(6, results.length()); 2498 results.close(); 2499 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null, null); 2500 assertEquals(4, results.length()); 2501 results.close(); 2502 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null, null); 2503 assertEquals(5, results.length()); 2504 results.close(); 2505 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null, 2506 null); 2507 assertEquals(1, results.length()); 2508 results.close(); 2509 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null, null); 2510 assertEquals(15, results.length()); 2511 results.close(); 2512 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//.\"", null, null); 2513 assertEquals(23, results.length()); 2514 results.close(); 2515 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null, null); 2516 assertEquals(14, results.length()); 2517 results.close(); 2518 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*\"", null, null); 2519 assertEquals(22, results.length()); 2520 results.close(); 2521 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null, null); 2522 assertEquals(14, results.length()); 2523 results.close(); 2524 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*/.\"", null, null); 2525 assertEquals(22, results.length()); 2526 results.close(); 2527 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null, null); 2528 assertEquals(14, results.length()); 2529 results.close(); 2530 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//*/./.\"", null, null); 2531 assertEquals(22, results.length()); 2532 results.close(); 2533 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null, null); 2534 assertEquals(14, results.length()); 2535 results.close(); 2536 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//./*\"", null, null); 2537 assertEquals(22, results.length()); 2538 results.close(); 2539 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null, null); 2540 assertEquals(14, results.length()); 2541 results.close(); 2542 results = searcher 2543 .query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//././*/././.\"", null, null); 2544 assertEquals(22, results.length()); 2545 results.close(); 2546 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null, null); 2547 assertEquals(1, results.length()); 2548 results.close(); 2549 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//common\"", null, null); 2550 assertEquals(6, results.length()); 2551 results.close(); 2552 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null, null); 2553 assertEquals(1, results.length()); 2554 results.close(); 2555 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one//common\"", null, null); 2556 assertEquals(5, results.length()); 2557 results.close(); 2558 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null, null); 2559 assertEquals(6, results.length()); 2560 results.close(); 2561 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one/five//*\"", null, null); 2562 assertEquals(9, results.length()); 2563 results.close(); 2564 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null, null); 2565 assertEquals(7, results.length()); 2566 results.close(); 2567 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"/one/five//.\"", null, null); 2568 assertEquals(10, results.length()); 2569 results.close(); 2570 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null, null); 2571 assertEquals(1, results.length()); 2572 results.close(); 2573 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null, null); 2574 assertEquals(1, results.length()); 2575 results.close(); 2576 2577 indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis(), 2578 indexerAndSearcher); 2579 indexer.setNodeService(nodeService); 2580 indexer.setLuceneIndexLock(luceneIndexLock); 2581 indexer.setDictionaryService(dictionaryService); 2582 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 2583 indexer.setContentService(contentService); 2584 2585 nodeService.addChild(n2, n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}link")); 2586 indexer.createChildRelationship(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName 2587 .createQName("{namespace}link"), n13)); 2588 2589 indexer.commit(); 2590 2591 runBaseTests(); 2592 luceneFTS.resume(); 2593 } 2594 2595 public void testRenameReference() throws Exception 2596 { 2597 luceneFTS.pause(); 2598 buildBaseIndex(); 2599 runBaseTests(); 2600 2601 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2602 searcher.setNodeService(nodeService); 2603 searcher.setDictionaryService(dictionaryService); 2604 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2605 2606 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//namespace:link//.\"", null, 2607 null); 2608 assertEquals(2, results.length()); 2609 results.close(); 2610 2611 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH_WITH_REPEATS:\"//namespace:link//.\"", 2612 null, null); 2613 assertEquals(3, results.length()); 2614 results.close(); 2615 2616 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//namespace:renamed_link//.\"", null, 2617 null); 2618 assertEquals(0, results.length()); 2619 results.close(); 2620 2621 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 2622 + System.currentTimeMillis(), indexerAndSearcher); 2623 indexer.setNodeService(nodeService); 2624 indexer.setLuceneIndexLock(luceneIndexLock); 2625 indexer.setDictionaryService(dictionaryService); 2626 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 2627 indexer.setContentService(contentService); 2628 2629 nodeService.removeChild(n2, n13); 2630 nodeService.addChild(n2, n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}renamed_link")); 2631 2632 indexer.updateChildRelationship(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName.createQName("namespace", 2633 "link"), n13), new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName.createQName("namespace", 2634 "renamed_link"), n13)); 2635 2636 indexer.commit(); 2637 2638 runBaseTests(); 2639 2640 searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2641 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2642 searcher.setDictionaryService(dictionaryService); 2643 2644 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//namespace:link//.\"", null, null); 2645 assertEquals(0, results.length()); 2646 results.close(); 2647 2648 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//namespace:renamed_link//.\"", null, 2649 null); 2650 assertEquals(2, results.length()); 2651 results.close(); 2652 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", 2653 "PATH_WITH_REPEATS:\"//namespace:renamed_link//.\"", null, null); 2654 assertEquals(3, results.length()); 2655 results.close(); 2656 luceneFTS.resume(); 2657 } 2658 2659 public void testDelayIndex() throws Exception 2660 { 2661 luceneFTS.pause(); 2662 buildBaseIndex(); 2663 runBaseTests(); 2664 2665 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2666 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2667 searcher.setNodeService(nodeService); 2668 searcher.setDictionaryService(dictionaryService); 2669 2670 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2671 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) 2672 + ":\"KEYONE\"", null, null); 2673 assertEquals(1, results.length()); 2674 results.close(); 2675 2676 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2677 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic")) 2678 + ":\"KEYUNSTORED\"", null, null); 2679 assertEquals(1, results.length()); 2680 results.close(); 2681 2682 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2683 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic")) 2684 + ":\"KEYTWO\"", null, null); 2685 assertEquals(0, results.length()); 2686 results.close(); 2687 2688 2690 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 2691 + System.currentTimeMillis() + "_" + (new Random ().nextInt()), indexerAndSearcher); 2692 indexer.setNodeService(nodeService); 2693 indexer.setLuceneIndexLock(luceneIndexLock); 2694 indexer.setDictionaryService(dictionaryService); 2695 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 2696 indexer.setContentService(contentService); 2697 indexer.updateFullTextSearch(1000); 2698 indexer.prepare(); 2699 indexer.commit(); 2700 2701 searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2702 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2703 searcher.setDictionaryService(dictionaryService); 2704 2705 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2706 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) 2707 + ":\"keyone\"", null, null); 2708 assertEquals(1, results.length()); 2709 results.close(); 2710 2711 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2712 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic")) 2713 + ":\"keytwo\"", null, null); 2714 assertEquals(1, results.length()); 2715 results.close(); 2716 2717 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2718 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic")) 2719 + ":\"keyunstored\"", null, null); 2720 assertEquals(1, results.length()); 2721 results.close(); 2722 2723 runBaseTests(); 2724 luceneFTS.resume(); 2725 } 2726 2727 public void testWaitForIndex() throws Exception 2728 { 2729 luceneFTS.pause(); 2730 buildBaseIndex(); 2731 runBaseTests(); 2732 2733 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2734 searcher.setNodeService(nodeService); 2735 searcher.setDictionaryService(dictionaryService); 2736 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2737 2738 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2739 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) 2740 + ":\"KEYONE\"", null, null); 2741 assertEquals(1, results.length()); 2742 results.close(); 2743 2744 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2745 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic")) 2746 + ":\"KEYUNSTORED\"", null, null); 2747 assertEquals(1, results.length()); 2748 results.close(); 2749 2750 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2751 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic")) 2752 + ":\"KEYTWO\"", null, null); 2753 assertEquals(0, results.length()); 2754 results.close(); 2755 2756 2758 searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2759 searcher.setNodeService(nodeService); 2760 searcher.setDictionaryService(dictionaryService); 2761 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2762 2763 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2764 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) 2765 + ":\"keyone\"", null, null); 2766 assertEquals(1, results.length()); 2767 results.close(); 2768 2769 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 2770 + System.currentTimeMillis() + "_" + (new Random ().nextInt()), indexerAndSearcher); 2771 indexer.setNodeService(nodeService); 2772 indexer.setLuceneIndexLock(luceneIndexLock); 2773 indexer.setDictionaryService(dictionaryService); 2774 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 2775 indexer.setContentService(contentService); 2776 indexer.updateFullTextSearch(1000); 2777 indexer.prepare(); 2778 indexer.commit(); 2779 2780 luceneFTS.resume(); 2781 2786 Thread.sleep(35000); 2787 2788 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2789 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic")) 2790 + ":\"keytwo\"", null, null); 2791 assertEquals(1, results.length()); 2792 results.close(); 2793 2794 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" 2795 + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic")) 2796 + ":\"KEYUNSTORED\"", null, null); 2797 assertEquals(1, results.length()); 2798 results.close(); 2799 2800 runBaseTests(); 2801 } 2802 2803 private String escapeQName(QName qname) 2804 { 2805 return LuceneQueryParser.escape(qname.toString()); 2806 } 2807 2808 public void testForKev() throws Exception 2809 { 2810 luceneFTS.pause(); 2811 buildBaseIndex(); 2812 runBaseTests(); 2813 2814 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2815 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2816 searcher.setNodeService(nodeService); 2817 searcher.setDictionaryService(dictionaryService); 2818 2819 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PARENT:\"" 2820 + rootNodeRef.toString() + "\"", null, null); 2821 assertEquals(5, results.length()); 2822 results.close(); 2823 2824 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "+PARENT:\"" 2825 + rootNodeRef.toString() + "\" +QNAME:\"one\"", null, null); 2826 assertEquals(1, results.length()); 2827 results.close(); 2828 2829 results = searcher 2830 .query( 2831 rootNodeRef.getStoreRef(), 2832 "lucene", 2833 "( +TYPE:\"{http://www.alfresco.org/model/content/1.0}linkfile\" +@\\{http\\://www.alfresco.org/model/content/1.0\\}name:\"content woof\") OR TEXT:\"content\"", 2834 null, null); 2835 2836 luceneFTS.resume(); 2837 } 2838 2839 public void testIssueAR47() throws Exception 2840 { 2841 2847 2850 testTX.commit(); 2852 UserTransaction tx = transactionService.getUserTransaction(); 2853 tx.begin(); 2854 ChildAssociationRef testFind = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName 2855 .createQName("{namespace}testFind"), testSuperType); 2856 tx.commit(); 2857 2858 LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), indexerAndSearcher); 2859 searcher.setNodeService(nodeService); 2860 searcher.setDictionaryService(dictionaryService); 2861 searcher.setNamespacePrefixResolver(getNamespacePrefixReolsver("namespace")); 2862 searcher.setQueryRegister(queryRegisterComponent); 2863 2864 ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); 2865 assertEquals(1, results.length()); 2866 results.close(); 2867 2868 for (int i = 0; i < 100; i++) 2869 { 2870 UserTransaction tx1 = transactionService.getUserTransaction(); 2871 tx1.begin(); 2872 ChildAssociationRef test = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName 2873 .createQName("{namespace}test"), testSuperType); 2874 tx1.commit(); 2875 2876 UserTransaction tx2 = transactionService.getUserTransaction(); 2877 tx2.begin(); 2878 nodeService.deleteNode(test.getChildRef()); 2879 tx2.commit(); 2880 } 2881 2882 UserTransaction tx3 = transactionService.getUserTransaction(); 2883 tx3.begin(); 2884 results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); 2885 assertEquals(1, results.length()); 2886 results.close(); 2887 tx3.commit(); 2888 } 2889 2890 2892 public void testReadAgainstDelta() throws Exception 2893 { 2894 testTX.commit(); 2895 UserTransaction tx = transactionService.getUserTransaction(); 2896 tx.begin(); 2897 luceneFTS.pause(); 2898 buildBaseIndex(); 2899 runBaseTests(); 2900 tx.commit(); 2901 2902 2904 tx = transactionService.getUserTransaction(); 2905 tx.begin(); 2906 2907 runBaseTests(); 2908 2909 serviceRegistry.getNodeService().deleteNode(n1); 2910 2911 SearchParameters sp = new SearchParameters(); 2912 sp.addStore(rootNodeRef.getStoreRef()); 2913 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 2914 sp.setQuery("PATH:\"//.\""); 2915 sp.excludeDataInTheCurrentTransaction(false); 2916 ResultSet results = serviceRegistry.getSearchService().query(sp); 2917 assertEquals(5, results.length()); 2918 results.close(); 2919 2920 sp = new SearchParameters(); 2921 sp.addStore(rootNodeRef.getStoreRef()); 2922 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 2923 sp.setQuery("PATH:\"//.\""); 2924 sp.excludeDataInTheCurrentTransaction(true); 2925 results = serviceRegistry.getSearchService().query(sp); 2926 assertEquals(15, results.length()); 2927 results.close(); 2928 2929 tx.rollback(); 2930 2931 sp = new SearchParameters(); 2932 sp.addStore(rootNodeRef.getStoreRef()); 2933 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 2934 sp.setQuery("PATH:\"//.\""); 2935 sp.addSort("ID", true); 2936 sp.excludeDataInTheCurrentTransaction(false); 2937 results = serviceRegistry.getSearchService().query(sp); 2938 assertEquals(15, results.length()); 2939 results.close(); 2940 2941 2943 tx = transactionService.getUserTransaction(); 2944 tx.begin(); 2945 2946 runBaseTests(); 2947 2948 assertEquals(5, serviceRegistry.getNodeService().getChildAssocs(rootNodeRef).size()); 2949 serviceRegistry.getNodeService().createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, 2950 QName.createQName("{namespace}texas"), testSuperType).getChildRef(); 2951 assertEquals(6, serviceRegistry.getNodeService().getChildAssocs(rootNodeRef).size()); 2952 2953 sp = new SearchParameters(); 2954 sp.addStore(rootNodeRef.getStoreRef()); 2955 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 2956 sp.setQuery("PATH:\"//.\""); 2957 sp.excludeDataInTheCurrentTransaction(false); 2958 results = serviceRegistry.getSearchService().query(sp); 2959 assertEquals(16, results.length()); 2960 results.close(); 2961 2962 tx.rollback(); 2963 2964 sp = new SearchParameters(); 2965 sp.addStore(rootNodeRef.getStoreRef()); 2966 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 2967 sp.setQuery("PATH:\"//.\""); 2968 sp.addSort("ID", true); 2969 sp.excludeDataInTheCurrentTransaction(false); 2970 results = serviceRegistry.getSearchService().query(sp); 2971 assertEquals(15, results.length()); 2972 results.close(); 2973 2974 2976 tx = transactionService.getUserTransaction(); 2977 tx.begin(); 2978 2979 runBaseTests(); 2980 2981 sp = new SearchParameters(); 2982 sp.addStore(rootNodeRef.getStoreRef()); 2983 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 2984 sp.setQuery("\\@\\{namespace\\}property\\-1:\"valueone\""); 2985 sp.addSort("ID", true); 2986 sp.excludeDataInTheCurrentTransaction(false); 2987 results = serviceRegistry.getSearchService().query(sp); 2988 2989 assertEquals(2, results.length()); 2990 results.close(); 2991 2992 nodeService.setProperty(n1, QName.createQName("{namespace}property-1"), "Different"); 2993 2994 sp = new SearchParameters(); 2995 sp.addStore(rootNodeRef.getStoreRef()); 2996 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 2997 sp.setQuery("\\@\\{namespace\\}property\\-1:\"valueone\""); 2998 sp.addSort("ID", true); 2999 sp.excludeDataInTheCurrentTransaction(false); 3000 results = serviceRegistry.getSearchService().query(sp); 3001 3002 assertEquals(1, results.length()); 3003 results.close(); 3004 3005 tx.rollback(); 3006 3007 sp = new SearchParameters(); 3008 sp.addStore(rootNodeRef.getStoreRef()); 3009 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 3010 sp.setQuery("\\@\\{namespace\\}property\\-1:\"valueone\""); 3011 sp.excludeDataInTheCurrentTransaction(false); 3012 sp.addSort("ID", true); 3013 results = serviceRegistry.getSearchService().query(sp); 3014 3015 assertEquals(2, results.length()); 3016 results.close(); 3017 3018 3020 tx = transactionService.getUserTransaction(); 3021 tx.begin(); 3022 3023 runBaseTests(); 3024 3025 serviceRegistry.getNodeService().deleteNode(n1); 3026 serviceRegistry.getNodeService().createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, 3027 QName.createQName("{namespace}texas"), testSuperType).getChildRef(); 3028 3029 sp = new SearchParameters(); 3030 sp.addStore(rootNodeRef.getStoreRef()); 3031 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 3032 sp.setQuery("PATH:\"//.\""); 3033 sp.excludeDataInTheCurrentTransaction(false); 3034 results = serviceRegistry.getSearchService().query(sp); 3035 assertEquals(6, results.length()); 3036 results.close(); 3037 3038 sp = new SearchParameters(); 3039 sp.addStore(rootNodeRef.getStoreRef()); 3040 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 3041 sp.setQuery("PATH:\"//.\""); 3042 sp.excludeDataInTheCurrentTransaction(true); 3043 results = serviceRegistry.getSearchService().query(sp); 3044 assertEquals(15, results.length()); 3045 results.close(); 3046 3047 tx.rollback(); 3048 3049 sp = new SearchParameters(); 3050 sp.addStore(rootNodeRef.getStoreRef()); 3051 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 3052 sp.setQuery("PATH:\"//.\""); 3053 sp.addSort("ID", true); 3054 sp.excludeDataInTheCurrentTransaction(false); 3055 results = serviceRegistry.getSearchService().query(sp); 3056 assertEquals(15, results.length()); 3057 results.close(); 3058 3059 } 3060 3061 private void runPerformanceTest(double time, boolean clear) 3062 { 3063 LuceneIndexerImpl indexer = LuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" 3064 + System.currentTimeMillis() + "_" + (new Random ().nextInt()), indexerAndSearcher); 3065 indexer.setNodeService(nodeService); 3066 indexer.setLuceneIndexLock(luceneIndexLock); 3067 indexer.setDictionaryService(dictionaryService); 3068 indexer.setLuceneFullTextSearchIndexer(luceneFTS); 3069 indexer.setContentService(contentService); 3070 if (clear) 3071 { 3072 } 3074 indexer.createNode(new ChildAssociationRef(null, null, null, rootNodeRef)); 3075 3076 long startTime = System.currentTimeMillis(); 3077 int count = 0; 3078 for (int i = 0; i < 10000000; i++) 3079 { 3080 if (i % 10 == 0) 3081 { 3082 if (System.currentTimeMillis() - startTime > time) 3083 { 3084 count = i; 3085 break; 3086 } 3087 } 3088 3089 QName qname = QName.createQName("{namespace}a_" + i); 3090 NodeRef ref = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME, qname, ContentModel.TYPE_CONTAINER) 3091 .getChildRef(); 3092 indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, rootNodeRef, qname, ref)); 3093 3094 } 3095 indexer.commit(); 3096 float delta = ((System.currentTimeMillis() - startTime) / 1000.0f); 3097 } 3100 3101 private NamespacePrefixResolver getNamespacePrefixReolsver(String defaultURI) 3102 { 3103 DynamicNamespacePrefixResolver nspr = new DynamicNamespacePrefixResolver(null); 3104 nspr.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI); 3105 nspr.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI); 3106 nspr.registerNamespace("namespace", "namespace"); 3107 nspr.registerNamespace("test", TEST_NAMESPACE); 3108 nspr.registerNamespace(NamespaceService.DEFAULT_PREFIX, defaultURI); 3109 return nspr; 3110 } 3111 3112 public static void main(String [] args) throws Exception 3113 { 3114 LuceneTest test = new LuceneTest(); 3115 test.setUp(); 3116 3119 3121 NodeRef targetNode = test.rootNodeRef; 3122 Path path = test.serviceRegistry.getNodeService().getPath(targetNode); 3123 3124 SearchParameters sp = new SearchParameters(); 3125 sp.addStore(test.rootNodeRef.getStoreRef()); 3126 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 3127 sp.setQuery("PATH:\"" + path + "//." + "\""); 3128 ResultSet results = test.serviceRegistry.getSearchService().query(sp); 3129 3130 results.close(); 3131 3132 } 3134} 3135 | Popular Tags |