@Override protected SearchTypes getSearchTypes() { final SearchTypes types = SearchTypes.fromTypes( entityType ); return types; }
/** * Create a search type from a potentially nullable set of string. If they are null, or empty, then allTypes is * returned otherwise the type will be returned */ public static SearchTypes fromNullableTypes( final String... types ) { if ( isEmpty( types ) ) { return allTypes(); } return fromTypes( types ); }
/** * 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); }
for ( i=0; i < expectedPages; i++ ) { final CandidateResults results = !offset.isPresent() ? entityIndex.search( indexEdge, SearchTypes.allTypes(), query, limit, 0, false ) : entityIndex.search(indexEdge, SearchTypes.allTypes(), query, limit, i * limit, false); final CandidateResults results = entityIndex.search(indexEdge, SearchTypes.allTypes(), query, limit, i * limit, false);
final String[] sourceTypes = searchTypes.getTypeNames( applicationScope );
/** * Create a search that will search on the specified types */ public static SearchTypes fromTypes( final String... types ) { return new SearchTypes( types ); }
@Override protected SearchTypes getSearchTypes() { return SearchTypes.fromNullableTypes( connectedEntityType.orNull() ); }
logger.debug( "Searching index (read alias): {}\n nodeId: {}, edgeType: {}, \n type: {}\n query: {} ", this.alias.getReadAlias(), searchEdge.getNodeId(), searchEdge.getEdgeName(), searchTypes.getTypeNames( applicationScope ), srb );
@Test public void testIndex() throws IOException, InterruptedException { 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", 101, 0 ); testQueries( searchEdge, searchTypes ); }
for (String type : searchTypes.getTypes()) { try { if ( Schema.getDefaultSchema().getEntityInfo(type) != null ){
@Test public void testAddMultipleIndexes() throws IOException { final String entityType = "thing"; IndexEdge searchEdge = new IndexEdgeImpl( appId, "things", SearchEdge.NodeType.SOURCE, 10 ); final SearchTypes searchTypes = SearchTypes.fromTypes(entityType); insertJsonBlob( entityType, searchEdge, "/sample-large.json", 101, 0); testQueries(searchEdge, searchTypes); entityIndex.addIndex(UUID.randomUUID()+"_v2", 1, 0, "one"); insertJsonBlob( entityType, searchEdge, "/sample-large.json", 101, 100); //Hilda Youn testQuery( searchEdge, searchTypes, "name = 'Hilda Young'", 1 ); testQuery( searchEdge, searchTypes, "name = 'Lowe Kelley'", 1 ); logger.info("hi"); }
@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); }
final String entityType = "thing"; IndexEdge indexEdge = new IndexEdgeImpl( appId, "things", SearchEdge.NodeType.SOURCE, 1 ); final SearchTypes searchTypes = SearchTypes.fromTypes( entityType ); EntityIndexBatch batch = entityIndex.createBatch();
/** * Go around EntityManager and execute query directly against Core Persistence. * Results may include stale index entries. */ private CandidateResults queryCollectionCp( final String collName, final String type, final String query ) { EntityManager em = app.getEntityManager(); EntityIndexFactory eif = SpringResource.getInstance().getBean( Injector.class ).getInstance( EntityIndexFactory.class ); ApplicationScope as = new ApplicationScopeImpl( new SimpleId( em.getApplicationId(), TYPE_APPLICATION ) ); IndexLocationStrategyFactory indexLocationStrategyFactory = SpringResource.getInstance().getBean( Injector.class ).getInstance(IndexLocationStrategyFactory.class); EntityIndex ei = eif.createEntityIndex(indexLocationStrategyFactory.getIndexLocationStrategy(as)); final Id rootId = createId(em.getApplicationId(), TYPE_APPLICATION); SearchEdge is = CpNamingUtils.createCollectionSearchEdge( rootId, collName ); return ei.search( is, SearchTypes.fromTypes( type ), query, 1000, 0, false ); }
@Test public void testDeindex() { IndexEdge searchEdge = new IndexEdgeImpl( appId, "fastcars", SearchEdge.NodeType.SOURCE, 1 ); Map entityMap = new HashMap() {{ put( "name", "Ferrari 212 Inter" ); put( "introduced", 1952 ); put( "topspeed", 215 ); }}; Entity entity = EntityIndexMapUtils.fromMap( entityMap ); EntityUtils.setId(entity, new SimpleId( "fastcar" ) ); EntityUtils.setVersion(entity, UUIDGenerator.newTimeUUID() ); entity.setField(new UUIDField(IndexingUtils.ENTITY_ID_FIELDNAME, UUID.randomUUID() ) ); indexProducer.put(entityIndex.createBatch().index( searchEdge, entity ).build()).subscribe(); entityIndex.refreshAsync().toBlocking().first(); CandidateResults candidateResults = entityIndex .search( searchEdge, SearchTypes.fromTypes( entity.getId().getType() ), "name contains 'Ferrari*'", 10, 0, false ); assertEquals( 1, candidateResults.size() ); EntityIndexBatch batch = entityIndex.createBatch(); batch.deindex( searchEdge, entity ); indexProducer.put(batch.build()).subscribe();; entityIndex.refreshAsync().toBlocking().first(); candidateResults = entityIndex .search(searchEdge, SearchTypes.fromTypes( entity.getId().getType() ), "name contains 'Ferrari*'", 10, 0, false ); assertEquals(0, candidateResults.size()); }
@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() ); }
.search( searchEdge, SearchTypes.fromTypes( searchEdge.getEdgeName() ), "select * where " + FIELD_WORKER_INDEX + " = " + workerIndex + " AND " + FIELD_ORDINAL + " = " + ordinal + " AND " + FIELD_UNIQUE_IDENTIFIER + " = '" + uniqueIdentifier