private CandidateResults getResults( final EntityIndex entityIndex, final SearchEdge searchEdge, final SearchTypes searchTypes, final int expectedSize, final int attempts ) { for ( int i = 0; i < attempts; i++ ) { final CandidateResults candidateResults = entityIndex.search( searchEdge, searchTypes, "select *", 100, 0, false ); if ( candidateResults.size() == expectedSize ) { return candidateResults; } try { Thread.sleep( 10000 ); } catch ( InterruptedException e ) { //swallow } } fail( "Could not find candidates of size " + expectedSize + " after " + attempts + " attempts" ); //we'll never reach this, required for compile return null; } }
/** * Takes in candidate results and uses the iterator to create batch commands */ public EntityIndexBatch deindexBatchIteratorResolver(IndexEdge edge,CandidateResults edgesToBeDeindexed, EntityIndexBatch batch){ Iterator itr = edgesToBeDeindexed.iterator(); while( itr.hasNext() ) { batch.deindex( edge, ( CandidateResult ) itr.next()); } return batch; }
/** * Parse the results and return the candidate results */ private CandidateResults parseResults( final SearchResponse searchResponse, final ParsedQuery query, final int limit, final int from, boolean hasGeoSortPredicates ) { final SearchHits searchHits = searchResponse.getHits(); final SearchHit[] hits = searchHits.getHits(); if (logger.isTraceEnabled()) { logger.trace(" Hit count: {} Total hits: {}", hits.length, searchHits.getTotalHits()); } List<CandidateResult> candidates = new ArrayList<>( hits.length ); for ( SearchHit hit : hits ) { CandidateResult candidateResult; candidateResult = parseIndexDocId( hit, hasGeoSortPredicates ); candidates.add( candidateResult ); } final CandidateResults candidateResults = new CandidateResults( candidates, query.getSelectFieldMappings()); // >= seems odd. However if we get an overflow, we need to account for it. if ( hits.length >= limit ) { candidateResults.initializeOffset( from + limit ); } return candidateResults; }
Collection<SelectFieldMapping> fieldMappingCollection = candidateResults.getGetFieldMappings(); if (candidateResults.size() < limit) { subscriber.onCompleted(); return;
: entityIndex.search(indexEdge, SearchTypes.allTypes(), query, limit, i * limit, false); assertEquals(limit, results.size()); assertNotEquals("Scroll matches last item from previous page",lastId, results.get(ordinal).getId().getUuid()); lastId = results.get(limit -1).getId().getUuid(); offset = results.getOffset(); assertEquals("Failed on page "+i, results.get( ordinal ).getId(), entityIds.get( i*limit ) ); assertEquals( 0, results.size() ); assertFalse(results.hasOffset());
@Test public void testDeleteWithAlias() throws IOException { final String entityType = "thing"; IndexEdge searchEdge = new IndexEdgeImpl( appId, "things", SearchEdge.NodeType.SOURCE, 1 ); final SearchTypes searchTypes = SearchTypes.fromTypes( entityType ); insertJsonBlob( entityType, searchEdge, "/sample-large.json", 1, 0 ); entityIndex.addIndex(UUID.randomUUID() + "v2", 1, 0, "one"); entityIndex.refreshAsync().toBlocking().first(); insertJsonBlob( entityType, searchEdge, "/sample-large.json", 1, 1 ); CandidateResults crs = testQuery( searchEdge, searchTypes, "name = 'Bowers Oneil'", 1 ); EntityIndexBatch entityIndexBatch = entityIndex.createBatch(); entityIndexBatch.deindex(searchEdge, crs.get(0)); indexProducer.put(entityIndexBatch.build()).subscribe(); entityIndex.refreshAsync().toBlocking().first(); //Hilda Youn testQuery(searchEdge, searchTypes, "name = 'Bowers Oneil'", 0); }
@Test public void deleteVerification() throws Throwable { Id ownerId = new SimpleId( "owner" ); IndexEdge indexSCope = new IndexEdgeImpl( ownerId, "user", SearchEdge.NodeType.SOURCE, 10 ); final String middleName = "middleName" + UUIDUtils.newTimeUUID(); Map entityMap = new HashMap() {{ put( "username", "edanuff" ); put( "email", "ed@anuff.com" ); put( "middlename", middleName ); }}; Entity user = EntityIndexMapUtils.fromMap( entityMap ); EntityUtils.setId( user, new SimpleId( "edanuff" ) ); EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() ); EntityIndexBatch batch = entityIndex.createBatch(); batch.index( indexSCope, user ); indexProducer.put(batch.build()).subscribe();; entityIndex.refreshAsync().toBlocking().first(); final String query = "where username = 'edanuff'"; CandidateResults r = entityIndex.search( indexSCope, SearchTypes.fromTypes( "edanuff" ), query, 10, 0, false); assertEquals( user.getId(), r.get( 0 ).getId()); batch.deindex( indexSCope, user.getId(), user.getVersion() ); indexProducer.put(batch.build()).subscribe();; entityIndex.refreshAsync().toBlocking().first(); // EntityRef r = entityIndex.search( indexSCope, SearchTypes.fromTypes( "edanuff" ), query, 10, 0, false ); assertFalse( r.iterator().hasNext() ); }
/** * Build CandidateResults from direct query */ private CandidateResults buildCandidateResultsForDirectQuery(final List<Identifier> directIdentifiers, final ParsedQuery query, final SearchTypes searchTypes) { Preconditions.checkArgument(searchTypes.getTypes().length > 0, "Search type required"); String entityType = searchTypes.getTypes()[0]; List<CandidateResult> candidates = new ArrayList<>(directIdentifiers.size()); for (Identifier id : directIdentifiers) { CandidateResult candidateResult = null; if (id.isUUID()) { candidateResult = new CandidateResult(entityType, id.getUUID()); } else if (id.isName()) { candidateResult = new CandidateResult(entityType, id.getName()); } candidates.add(candidateResult); } return new CandidateResults(candidates, query.getSelectFieldMappings(), true); }
return new CandidateResults( candidates, Collections.EMPTY_SET);
assertEquals( 1, notFirstResults.size() ); assertEquals(second.getId(), notFirstResults.get( 0 ).getId() ); assertEquals( 1, notSecondUnion.size() ); assertEquals( first.getId(), notSecondUnion.get( 0 ).getId() ); assertEquals( 2, notBothReturnResults.size() ); assertEquals( second.getId(), notBothReturnResults.get( 0).getId() ); assertEquals( first.getId(), notBothReturnResults.get( 1 ).getId() ); assertEquals( 0, filterBoth.size() ); assertEquals( 2, noMatchesAndResults.size() ); assertEquals( second.getId(), noMatchesAndResults.get( 0).getId() ); assertEquals( first.getId(), noMatchesAndResults.get( 1 ).getId() ); assertEquals( 2, noMatchesOrResults.size() ); assertEquals( second.getId(), noMatchesOrResults.get( 0).getId() ); assertEquals( first.getId(), noMatchesOrResults.get( 1 ).getId() );
private CandidateResults getResults( final EntityIndex EntityIndex, final SearchEdge searchEdge, final SearchTypes searchTypes, final int expectedSize ) { final int attempts = 100; String ql = "select *"; for ( int i = 0; i < attempts; i++ ) { final CandidateResults candidateResults = EntityIndex.search( searchEdge, searchTypes, ql , 100, 0, false ); if ( candidateResults.size() == expectedSize ) { return candidateResults; } try { Thread.sleep( 100 ); } catch ( InterruptedException e ) { //swallow } } fail( "Could not find candidates of size " + expectedSize + "after " + attempts + " attempts" ); //we'll never reach this, required for compile return null; } }
assertEquals(1, singleResults.size()); assertEquals(first.getId(), singleResults.get(0).getId()); assertEquals( 2, singleKeywordUnion.size() ); assertEquals( second.getId(), singleKeywordUnion.get( 0).getId() ); assertEquals( first.getId(), singleKeywordUnion.get( 1 ).getId() ); assertEquals( 2, towMatchResults.size() ); assertEquals(second.getId(), towMatchResults.get( 0).getId() ); assertEquals(first.getId(), towMatchResults.get( 1 ).getId() );
private CandidateResults testQuery( final SearchEdge scope, final SearchTypes searchTypes, final String queryString, final int num ) { StopWatch timer = new StopWatch(); timer.start(); CandidateResults candidateResults = entityIndex.search( scope, searchTypes, queryString, 1000, 0, false ); timer.stop(); assertEquals(num, candidateResults.size()); logger.debug("Query time {}ms", timer.getTime()); return candidateResults; }
@Test public void queryByUUID() throws Throwable { Id appId = new SimpleId( "application" ); Id ownerId = new SimpleId( "owner" ); IndexEdge indexSCope = new IndexEdgeImpl( ownerId, "user", SearchEdge.NodeType.SOURCE, 10 ); final UUID searchUUID = UUIDGenerator.newTimeUUID(); Map entityMap = new HashMap() {{ put( "searchUUID", searchUUID ); }}; Entity user = EntityIndexMapUtils.fromMap( entityMap ); final Id entityId = new SimpleId( "entitytype" ); EntityUtils.setId( user, entityId ); EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() ); EntityIndexBatch batch = entityIndex.createBatch(); batch.index( indexSCope, user ); indexProducer.put(batch.build()).subscribe();; entityIndex.refreshAsync().toBlocking().first(); final String query = "where searchUUID = " + searchUUID; final CandidateResults r = entityIndex.search( indexSCope, SearchTypes.fromTypes(entityId.getType()), query, 10, 0, false); assertEquals(user.getId(), r.get(0).getId()); }
SearchTypes.fromTypes( testEntity.getId().getType() ), 1 ); assertEquals( 1, collectionResults.size() ); assertEquals( testEntity.getId(), collectionResults.get( 0 ).getId() ); SearchTypes.fromTypes( testEntity.getId().getType() ), 1 ); assertEquals( 1, connectionResults.size() ); assertEquals( testEntity.getId(), connectionResults.get( 0 ).getId() ); SearchTypes.fromTypes( testEntity.getId().getType() ), 1 ); assertEquals( 1, lastConnectionResults.size() ); assertEquals( testEntity.getId(), lastConnectionResults.get( 0 ).getId() );