@Test public void subpropertyQuerying() throws Exception { Map<String, Object> root = new HashMap<String, Object>(); Map<String, Object> subEntity = new HashMap<String, Object>(); root.put("rootprop1", "simpleprop"); subEntity.put("intprop", 10); subEntity.put("substring", "I'm a tokenized string that should be indexed"); root.put("subentity", subEntity); UUID applicationId = createApplication("testOrganization", "subpropertyQuerying"); assertNotNull(applicationId); EntityManager em = emf.getEntityManager(applicationId); assertNotNull(em); Entity saved = em.create("test", root); Query query = new Query(); query.addEqualityFilter("rootprop1", "simpleprop"); Results results = em.searchCollection(em.getApplicationRef(), "tests", query); Entity entity = results.getEntitiesMap().get(saved.getUuid()); assertNotNull(entity); // query on the nested int value query = new Query(); query.addEqualityFilter("subentity.intprop", 10); results = em.searchCollection(em.getApplicationRef(), "tests", query); entity = results.getEntitiesMap().get(saved.getUuid()); assertNotNull(entity); // query on the nexted tokenized value query = new Query(); query.addContainsFilter("subentity.substring", "tokenized"); query.addContainsFilter("subentity.substring", "indexed"); results = em.searchCollection(em.getApplicationRef(), "tests", query); entity = results.getEntitiesMap().get(saved.getUuid()); assertNotNull(entity); }
/** * Perform an intersection of the 2 results * * @param results */ public void and(Results results) { getEntitiesMap(); results.getEntitiesMap(); if ((entitiesMap != null) && (results.entitiesMap != null)) { Map<UUID, Entity> newMap = new LinkedHashMap<UUID, Entity>(); for (Map.Entry<UUID, Entity> e : entitiesMap.entrySet()) { if (results.entitiesMap.containsKey(e.getKey())) { newMap.put(e.getKey(), e.getValue()); } } entitiesMap = newMap; entities = new ArrayList<Entity>(entitiesMap.values()); level = Level.ALL_PROPERTIES; return; } getRefsMap(); results.getRefsMap(); if ((refsMap != null) && (results.refsMap != null)) { Map<UUID, EntityRef> newMap = new LinkedHashMap<UUID, EntityRef>(); for (Map.Entry<UUID, EntityRef> e : refsMap.entrySet()) { if (results.refsMap.containsKey(e.getKey())) { newMap.put(e.getKey(), e.getValue()); } } refsMap = newMap; refs = new ArrayList<EntityRef>(refsMap.values()); level = Level.REFS; ids = null; return; } getIdSet(); results.getIdSet(); if ((idSet != null) && (results.idSet != null)) { Set<UUID> newSet = new LinkedHashSet<UUID>(); for (UUID uuid : idSet) { if (results.idSet.contains(uuid)) { newSet.add(uuid); } } idSet = newSet; ids = new ArrayList<UUID>(idSet); level = Level.IDS; return; } // should be empty init(); }
@JsonSerialize(include = Inclusion.NON_NULL) public Map<UUID, EntityRef> getRefsMap() { if (refsMap != null) { return refsMap; } getEntitiesMap(); if (entitiesMap != null) { refsMap = cast(entitiesMap); return refsMap; } getRefs(); if (refs != null) { refsMap = new LinkedHashMap<UUID, EntityRef>(); for (EntityRef ref : refs) { refsMap.put(ref.getUuid(), ref); } } return refsMap; }
@Test public void stringWithSpaces() throws Exception { Map<String, Object> props = new HashMap<String, Object>(); props.put("myString", "My simple string"); UUID applicationId = createApplication("testOrganization", "stringWithSpaces"); assertNotNull(applicationId); EntityManager em = emf.getEntityManager(applicationId); assertNotNull(em); Entity saved = em.create("test", props); Query query = new Query(); query.addEqualityFilter("myString", "My simple string"); Results results = em.searchCollection(em.getApplicationRef(), "tests", query); Entity entity = results.getEntitiesMap().get(saved.getUuid()); assertNotNull(entity); }
@Test public void arrayQuerying() throws Exception { Map<String, Object> root = new HashMap<String, Object>(); root.put("intprop", 10); root.put("array", new String[] {"val1", "val2", "val3 with spaces"}); Map<String, Object> jsonData = (Map<String, Object>) JsonUtils.parse(JsonUtils.mapToJsonString(root)); UUID applicationId = createApplication("testOrganization", "arrayQuerying"); assertNotNull(applicationId); EntityManager em = emf.getEntityManager(applicationId); assertNotNull(em); Entity saved = em.create("test", jsonData); Query query = new Query(); query.addEqualityFilter("intprop", 10); Results results = em.searchCollection(em.getApplicationRef(), "tests", query); Entity entity = results.getEntitiesMap().get(saved.getUuid()); assertNotNull(entity); // query on the nested int value query = new Query(); query.addEqualityFilter("array", "val1"); results = em.searchCollection(em.getApplicationRef(), "tests", query); entity = results.getEntitiesMap().get(saved.getUuid()); assertNotNull(entity); // query on the nexted tokenized value query = new Query(); query.addEqualityFilter("array", "val2"); results = em.searchCollection(em.getApplicationRef(), "tests", query); entity = results.getEntitiesMap().get(saved.getUuid()); assertNotNull(entity); query = new Query(); query.addEqualityFilter("array", "val3"); results = em.searchCollection(em.getApplicationRef(), "tests", query); entity = results.getEntitiesMap().get(saved.getUuid()); assertNull(entity); query = new Query(); query.addContainsFilter("array", "spaces"); results = em.searchCollection(em.getApplicationRef(), "tests", query); entity = results.getEntitiesMap().get(saved.getUuid()); assertNotNull(entity); }
public void merge(Results results) { getEntitiesMap(); results.getEntitiesMap(); if (entitiesMap != null || results.entitiesMap != null) { level = Level.ALL_PROPERTIES; // do nothing, nothing to union if (entitiesMap != null && results.entitiesMap == null) { return; // other side has the results, assign and return } else if (entitiesMap == null && results.entitiesMap != null) { entities = results.entities; return; } entitiesMap.putAll(results.entitiesMap); entities = new ArrayList<Entity>(entitiesMap.values()); return; } getRefsMap(); results.getRefsMap(); if ((refsMap != null) || (results.refsMap != null)) { level = Level.REFS; // do nothing, nothing to union if (refsMap != null && results.refsMap == null) { return; // other side has the results, assign and return } else if (refsMap == null && results.refsMap != null) { refs = results.refs; return; } refsMap.putAll(results.refsMap); refs = new ArrayList<EntityRef>(refsMap.values()); return; } getIdSet(); results.getIdSet(); if ((idSet != null) && (results.idSet != null)) { level = Level.IDS; // do nothing, nothing to union if (idSet != null && results.idSet == null) { return; // other side has the results, assign and return } else if (idSet == null && results.idSet != null) { ids = results.ids; return; } idSet.addAll(results.idSet); ids = new ArrayList<UUID>(idSet); return; } }