public ClusteredCacheQueryImpl(Query luceneQuery, SearchIntegrator searchFactory, ExecutorService asyncExecutor, AdvancedCache<?, ?> cache, KeyTransformationHandler keyTransformationHandler, Class<?>... classes) { super(luceneQuery, searchFactory, cache, keyTransformationHandler, null, classes); this.asyncExecutor = asyncExecutor; this.hSearchQuery = searchFactory.createHSQuery(luceneQuery, classes); }
@Override public HSQuery createHSQuery(SearchIntegrator integrator, IndexedTypeSet types) { ExtendedSearchIntegrator extendedIntegrator = integrator.unwrap( ExtendedSearchIntegrator.class ); return new LuceneHSQuery( luceneQuery, extendedIntegrator, types ); }
LuceneQueryMaker(SearchIntegrator searchFactory, FieldBridgeAndAnalyzerProvider<TypeMetadata> fieldBridgeAndAnalyzerProvider) { if (searchFactory == null) { throw new IllegalArgumentException("searchFactory argument cannot be null"); } this.fieldBridgeAndAnalyzerProvider = fieldBridgeAndAnalyzerProvider; this.queryContextBuilder = searchFactory.buildQueryBuilder(); this.searchFactory = searchFactory; }
@Benchmark @Threads(20) public void queryBooksByBestRating(QueryEngineHolder eh, Blackhole bh) { SearchIntegrator searchIntegrator = eh.si; Query luceneQuery = searchIntegrator.buildQueryBuilder() .forEntity( BookEntity.class ) .get() .all() .createQuery(); long expectedIndexSize = eh.getExpectedIndexSize(); int maxResults = eh.getMaxResults(); HSQuery hsQuery = searchIntegrator.createHSQuery( luceneQuery, BookEntity.class ); hsQuery.sort( new Sort( new SortField( "rating", SortField.Type.FLOAT, true ) ) ); hsQuery.maxResults( maxResults ); int queryResultSize = hsQuery.queryResultSize(); List<EntityInfo> queryEntityInfos = hsQuery.queryEntityInfos(); if ( eh.isQuerySync() && queryResultSize != expectedIndexSize ) { throw new RuntimeException( "Unexpected index size" ); } if ( maxResults != queryEntityInfos.size() ) { throw new RuntimeException( "Unexpected resultset size" ); } bh.consume( queryEntityInfos ); }
assertNotNull(searchFactory.getIndexManager(ProgrammaticSearchMappingProviderImpl.getIndexName(cache.getName()))); Query luceneQuery2 = searchFactory.buildQueryBuilder().forEntity(ProtobufValueWrapper.class).get() .keyword() .onField("name") .createQuery(); List<EntityInfo> queryEntityInfos = searchFactory.createHSQuery(luceneQuery2, ProtobufValueWrapper.class) .projection("surname") .queryEntityInfos();
public Indexer(SearchIntegrator si, Dataset<? extends AbstractBookEntity> data) { this.worker = si.getWorker(); this.dataset = data; }
private void verifyClassIsIndexed(SearchIntegrator searchIntegrator, Class<?> type) { assertTrue(searchIntegrator.getIndexBindings().containsKey(PojoIndexedTypeIdentifier.convertFromLegacy(type))); assertNotNull(searchIntegrator.getIndexManager(type.getName())); } }
private void performShardAwareOperation(IndexedTypeSet entityTypes, BiConsumer<IndexManager, IndexedTypeIdentifier> operation) { for (IndexedTypeIdentifier type : entityTypes) { EntityIndexBinding indexBindingForEntity = integrator.getIndexBinding(type); if (indexBindingForEntity != null) { Set<IndexManager> indexManagers = indexBindingForEntity.getIndexManagerSelector().forExisting(type, null, null); indexManagers.forEach(im -> operation.accept(im, type)); } } } }
private NRTIndexManager verifyShardingOptions(SearchIntegrator searchIntegrator, int expectedShards) { for (int i = 0; i < expectedShards; i++) Assert.assertNotNull(searchIntegrator.getIndexManager("person."+i), "person."+i+" IndexManager missing!"); Assert.assertNull(searchIntegrator.getIndexManager("person."+expectedShards), "An IndexManager too much was created!"); IndexManager indexManager = searchIntegrator.getIndexManager("person.0"); Assert.assertTrue(indexManager instanceof NRTIndexManager); NRTIndexManager nrtIM = (NRTIndexManager)indexManager; return nrtIM; }
static MockErrorHandler getErrorHandler(SearchIntegrator integrator) { ErrorHandler errorHandler = integrator.getErrorHandler(); Assert.assertTrue( errorHandler instanceof MockErrorHandler ); MockErrorHandler mockErrorHandler = (MockErrorHandler) errorHandler; return mockErrorHandler; }
/** * Checks if an index exists for the given class. This is not intended to test whether the entity class is indexable * (via annotations or programmatically). * * @param c the class to check * @return true if an index exists, false otherwise */ boolean hasIndex(final Class<?> c) { return searchFactory.getIndexBindings().get(c) != null; }
private void expectOnConfiguration(boolean async, boolean exclusiveIndexing, String... expectedStack) { SearchConfigurationForTest cfg = new SearchConfigurationForTest(); cfg.addProperty( "hibernate.search.default.worker.execution", async ? "async" : "sync" ); cfg.addProperty( "hibernate.search.default.exclusive_index_use", exclusiveIndexing ? "true" : "false" ); cfg.addProperty( "hibernate.search.error_handler", CountingErrorHandler.class.getName() ); cfg.addClass( Quote.class ); searchIntegrator = integratorResource.create( cfg ); final CountingErrorHandler errorHandler = (CountingErrorHandler) searchIntegrator.getErrorHandler(); writeData( NUMBER_ENTITIES ); //Check no errors happened in the asynchronous threads assertEquals( 0, errorHandler.getTotalCount() ); searchIntegrator.close(); //Now the SearchIntegrator was closed, let's unwind the recorder events and compare them with expectations: for ( int i = 0; i < expectedStack.length; i++ ) { //Check the events have been fired in the expected order assertEquals( expectedStack[i], byteman.consumeNextRecordedEvent() ); } //And no more events than those expected exist assertTrue( byteman.isEventStackEmpty() ); }
@TearDown public void shutdownIndexingEngine() throws IOException { if ( si != null ) { si.close(); } }
@Benchmark @GroupThreads(5) @Group("concurrentReadWriteTest") public void readWriteTestReader(QueryEngineHolder eh, Blackhole bh) { SearchIntegrator searchIntegrator = eh.si; Query luceneQuery = searchIntegrator.buildQueryBuilder() .forEntity( BookEntity.class ) .get() .all() .createQuery(); int maxResults = eh.getMaxResults(); HSQuery hsQuery = searchIntegrator.createHSQuery( luceneQuery, BookEntity.class ); hsQuery.maxResults( maxResults ); int queryResultSize = hsQuery.queryResultSize(); List<EntityInfo> queryEntityInfos = hsQuery.queryEntityInfos(); bh.consume( queryEntityInfos ); bh.consume( queryResultSize ); }
private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) { Worker worker = searchFactory.getWorker(); for (Work work : works) { worker.performWork(work, transactionContext); } }
private void verifyClassIsNotIndexed(SearchIntegrator searchIntegrator, Class<?> type) { assertFalse(searchIntegrator.getIndexBindings().containsKey(PojoIndexedTypeIdentifier.convertFromLegacy(type))); assertNull(searchIntegrator.getIndexManager(type.getName())); }
private void performShardAwareOperation(IndexedTypeSet entityTypes, BiConsumer<IndexManager, IndexedTypeIdentifier> operation) { for (IndexedTypeIdentifier type : entityTypes) { EntityIndexBinding indexBindingForEntity = integrator.getIndexBinding(type); if (indexBindingForEntity != null) { Set<IndexManager> indexManagers = indexBindingForEntity.getIndexManagerSelector().forExisting(type, null, null); indexManagers.forEach(im -> operation.accept(im, type)); } } } }
@Override public CompletableFuture<Object> invokeAsync() throws Throwable { if (queryInterceptor.isStopping()) { throw log.cacheIsStoppingNoCommandAllowed(cacheName.toString()); } IndexManager indexManager = searchFactory.getIndexManager(indexName); if (indexManager == null) { throw new SearchException("Unknown index referenced : " + indexName); } List<LuceneWork> luceneWorks = indexManager.getSerializer().toLuceneWorks(this.serializedModel); KeyTransformationHandler handler = queryInterceptor.getKeyTransformationHandler(); LuceneWork workToApply = LuceneWorkConverter.transformKeysToString(luceneWorks.iterator().next(), handler); indexManager.performStreamOperation(workToApply, null, true); return CompletableFutures.completedNull(); }
private MockErrorHandler getErrorHandlerAndAssertCorrectTypeIsUsed() { SearchIntegrator integrator = getExtendedSearchIntegrator(); ErrorHandler errorHandler = integrator.getErrorHandler(); Assert.assertEquals( MockErrorHandler.class, errorHandler.getClass() ); return (MockErrorHandler) errorHandler; }
/** * Checks if an index exists for the given class. This is not intended to test whether the entity class is indexable * (via annotations or programmatically). * * @param c the class to check * @return true if an index exists, false otherwise */ boolean hasIndex(final Class<?> c) { return searchFactory.getIndexBindings().get(c) != null; }