public Indexer(SearchIntegrator si, Dataset<? extends AbstractBookEntity> data) { this.worker = si.getWorker(); this.dataset = data; }
private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) { Worker worker = searchFactory.getWorker(); for (Work work : works) { worker.performWork(work, transactionContext); } }
private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) { Worker worker = searchFactory.getWorker(); for (Work work : works) { worker.performWork(work, transactionContext); } }
@Override public void run() { final Worker worker = integrator.getWorker(); final String title = "Volume N' " + Integer.toString( threadId ); final Integer bookId = Integer.valueOf( threadId ); final Query query = new TermQuery( new Term( "title", title ) ); try { while ( running.get() ) { cyclesCompleted.incrementAndGet(); verifyMatches( integrator, 0, query ); writeABook( bookId, title, worker ); verifyMatches( integrator, 1, query ); deleteABook( bookId, worker ); verifyMatches( integrator, 0, query ); } } catch (RuntimeException re) { if ( running.get() ) { re.printStackTrace(); failures.set( true ); } } }
public void execute() { TransactionContextForTest tc = new TransactionContextForTest(); works.forEach( w -> integratorProvider.get().getWorker().performWork( w, tc ) ); tc.end(); works.clear(); } }
@Test public void testCustomWorker() { manualConfiguration.addProperty( "hibernate.search.worker.scope", CustomWorker.class.getName() ); SearchIntegrator searchIntegrator = integratorResource.create( manualConfiguration ); assertNotNull( "Worker should have been created", searchIntegrator.getWorker() ); assertTrue( "Wrong worker class", searchIntegrator.getWorker() instanceof CustomWorker ); }
@Test public void testDefaultWorker() { SearchIntegrator searchIntegrator = integratorResource.create( manualConfiguration ); assertNotNull( "Worker should have been created", searchIntegrator.getWorker() ); assertTrue( "Wrong worker class", searchIntegrator.getWorker() instanceof PerTransactionWorker ); }
@Test public void testExplicitTransactionalWorker() { manualConfiguration.addProperty( "hibernate.search.worker.scope", "transaction" ); SearchIntegrator searchIntegrator = integratorResource.create( manualConfiguration ); assertNotNull( "Worker should have been created", searchIntegrator.getWorker() ); assertTrue( "Wrong worker class", searchIntegrator.getWorker() instanceof PerTransactionWorker ); }
@Test public void testCustomWorkerWithProperties() { manualConfiguration.addProperty( "hibernate.search.worker.scope", CustomWorkerExpectingFooAndBar.class.getName() ); manualConfiguration.addProperty( "hibernate.search.worker.foo", "foo" ); manualConfiguration.addProperty( "hibernate.search.worker.bar", "bar" ); SearchIntegrator searchIntegrator = integratorResource.create( manualConfiguration ); assertNotNull( "Worker should have been created", searchIntegrator.getWorker() ); assertTrue( "Wrong worker class", searchIntegrator.getWorker() instanceof CustomWorkerExpectingFooAndBar ); }
@Override public void run() { for ( int i = 1; i <= docsPerThread; i++ ) { final Worker worker = integrator.getWorker(); Work work = workLog.generateNewWork(); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); workLog.workApplied( work ); tc.end(); if ( i % printEach == 0 ) { System.out.println( Thread.currentThread().getName() + " sent " + i ); } } } }
@Benchmark @Threads(3 * AbstractBookEntity.TYPE_COUNT) public void write(NonStreamWriteEngineHolder eh, ChangesetGenerator changesetGenerator, NonStreamWriteCounters counters) { SearchIntegrator si = eh.getSearchIntegrator(); Worker worker = si.getWorker(); IndexedTypeIdentifier typeId = changesetGenerator.getTypeId(); changesetGenerator.stream().forEach( changeset -> { TransactionContextForTest tc = new TransactionContextForTest(); changeset.toAdd().forEach( book -> { Work work = new Work( book, book.getId(), WorkType.ADD ); worker.performWork( work, tc ); } ); changeset.toUpdate().forEach( book -> { Work work = new Work( book, book.getId(), WorkType.UPDATE ); worker.performWork( work, tc ); } ); changeset.toDelete().forEach( id -> { Work work = new Work( typeId, id, WorkType.DELETE ); worker.performWork( work, tc ); } ); tc.end(); ++counters.changeset; } ); // Ensure that we'll block until all works have been performed SearchIntegratorHelper.flush( si, typeId ); }
@Benchmark @Threads(20) public void simpleIndexing(QueryEngineHolder eh) { Worker worker = eh.si.getWorker(); BookEntity book = new BookEntity(); book.setId( 1L ); book.setText( "Some very long text should be stored here. No, I mean long as in a book." ); book.setTitle( "Naaa" ); Work work = new Work( book, book.getId(), WorkType.ADD, false ); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); tc.end(); }
public static void preindexEntities(SearchIntegrator si, int numEntities) { println( "Starting index creation..." ); Worker worker = si.getWorker(); TransactionContextForTest tc = new TransactionContextForTest(); boolean needsFlush = false; int i = 1; for ( ; i <= numEntities; i++ ) { BookEntity book = new BookEntity(); book.setId( Long.valueOf( i ) ); book.setText( "Some very long text should be stored here. No, I mean long as in a book." ); book.setTitle( "Naaa" ); book.setRating( Float.intBitsToFloat( i ) ); Work work = new Work( book, book.getId(), WorkType.ADD, false ); worker.performWork( work, tc ); needsFlush = true; if ( i % 1000 == 0 ) { //commit in batches of 1000: tc.end(); needsFlush = false; tc = new TransactionContextForTest(); } } if ( needsFlush ) { //commit remaining work tc.end(); } println( " ... created an index of " + numEntities + " entities." ); }