com.orientechnologies.orient.core.index.OCompositeKey Java Examples
The following examples show how to use
com.orientechnologies.orient.core.index.OCompositeKey.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractTagRule.java From light with Apache License 2.0 | 6 votes |
protected List<String> getTagEntityListDb(String host, String tagId) { List<String> entityList = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OIndex<?> tagHostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("tagHostIdIdx"); OCompositeKey key = new OCompositeKey(host, tagId); OIdentifiable oid = (OIdentifiable) tagHostIdIdx.get(key); if (oid != null) { ODocument doc = (ODocument)oid.getRecord(); entityList = new ArrayList<String>(); ORidBag entities = doc.field("in_HasTag"); Iterator<OIdentifiable> iterator = entities.iterator(); while (iterator.hasNext()) { OIdentifiable identifiable = iterator.next(); entityList.add(identifiable.getIdentity().toString()); } } } catch (Exception e) { logger.error("Exception:", e); } finally { graph.shutdown(); } return entityList; }
Example #2
Source File: AssetStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Test public void getNextPageReturnsEntriesByPages() { int limit = 2; Asset asset1 = createAsset(bucket, "asset1", component); Asset asset2 = createAsset(bucket, "asset2", component); Asset asset3 = createAsset(bucket, "asset3", component); try (ODatabaseDocumentTx db = database.getInstance().connect()) { assetEntityAdapter.addEntity(db, asset1); assetEntityAdapter.addEntity(db, asset2); assetEntityAdapter.addEntity(db, asset3); } OIndexCursor cursor = underTest.getIndex(AssetEntityAdapter.I_BUCKET_COMPONENT_NAME).cursor(); List<Entry<OCompositeKey, EntityId>> assetPage1 = underTest.getNextPage(cursor, limit); List<Entry<OCompositeKey, EntityId>> assetPage2 = underTest.getNextPage(cursor, limit); assertThat(assetPage1.size(), is(2)); assertThat(assetPage1.get(0).getValue(), is(EntityHelper.id(asset1))); assertThat(assetPage1.get(1).getValue(), is(EntityHelper.id(asset2))); assertThat(assetPage2.size(), is(1)); assertThat(assetPage2.get(0).getValue(), is(EntityHelper.id(asset3))); }
Example #3
Source File: AssetStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Test public void getNextPageStopsAtNullEntry() { int limit = 2; Asset asset1 = createAsset(bucket, "asset1", component); try (ODatabaseDocumentTx db = database.getInstance().connect()) { assetEntityAdapter.addEntity(db, asset1); } OIndexCursor cursor = underTest.getIndex(AssetEntityAdapter.I_BUCKET_COMPONENT_NAME).cursor(); List<Entry<OCompositeKey, EntityId>> assetPage1 = underTest.getNextPage(cursor, limit); assertThat(assetPage1.size(), is(1)); assertThat(assetPage1.get(0).getValue(), is(EntityHelper.id(asset1))); }
Example #4
Source File: ComponentStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Test public void getNextPageReturnsEntriesByPages() { int limit = 2; Component entity1 = createComponent(bucket, "group1", "name1", "version1"); Component entity2 = createComponent(bucket, "group2", "name2", "version2"); Component entity3 = createComponent(bucket, "group3", "name3", "version3"); try (ODatabaseDocumentTx db = database.getInstance().connect()) { entityAdapter.addEntity(db, entity1); entityAdapter.addEntity(db, entity2); entityAdapter.addEntity(db, entity3); } OIndexCursor cursor = underTest.getIndex(ComponentEntityAdapter.I_GROUP_NAME_VERSION_INSENSITIVE).cursor(); List<Entry<OCompositeKey, EntityId>> page1 = underTest.getNextPage(cursor, limit); List<Entry<OCompositeKey, EntityId>> page2 = underTest.getNextPage(cursor, limit); assertThat(page1.size(), is(2)); assertThat(page1.get(0).getValue(), is(EntityHelper.id(entity1))); assertThat(page1.get(1).getValue(), is(EntityHelper.id(entity2))); assertThat(page2.size(), is(1)); assertThat(page2.get(0).getValue(), is(EntityHelper.id(entity3))); }
Example #5
Source File: ComponentStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Test public void getNextPageStopsAtNullEntry() { int limit = 2; Component entity1 = createComponent(bucket, "group1", "name1", "version1"); try (ODatabaseDocumentTx db = database.getInstance().connect()) { entityAdapter.addEntity(db, entity1); } OIndexCursor cursor = underTest.getIndex(ComponentEntityAdapter.I_GROUP_NAME_VERSION_INSENSITIVE).cursor(); List<Entry<OCompositeKey, EntityId>> page1 = underTest.getNextPage(cursor, limit); assertThat(page1.size(), is(1)); assertThat(page1.get(0).getValue(), is(EntityHelper.id(entity1))); }
Example #6
Source File: OLuceneFacetManager.java From orientdb-lucene with Apache License 2.0 | 6 votes |
public void addFacetContext(QueryContext queryContext, Object key) throws IOException { queryContext.setFacet(true); queryContext.setFacetField(facetField); queryContext.setFacetConfig(config); // queryContext.setfacetDim(facetDim); queryContext.setReader(new DirectoryTaxonomyReader(getTaxDirectory(owner.getDatabase()))); if (key instanceof OCompositeKey) { List<Object> keys = ((OCompositeKey) key).getKeys(); for (Object o : keys) { if (o instanceof Map) { String drillDown = (String) ((Map) o).get("drillDown"); queryContext.setDrillDownQuery(drillDown); } } } }
Example #7
Source File: OLuceneSpatialIndexManager.java From orientdb-lucene with Apache License 2.0 | 6 votes |
@Override public Object get(Object key) { try { if (key instanceof OSpatialCompositeKey) { final OSpatialCompositeKey newKey = (OSpatialCompositeKey) key; final SpatialOperation strategy = newKey.getOperation() != null ? newKey.getOperation() : SpatialOperation.Intersects; if (SpatialOperation.Intersects.equals(strategy)) return searchIntersect(newKey, newKey.getMaxDistance(), newKey.getContext()); else if (SpatialOperation.IsWithin.equals(strategy)) return searchWithin(newKey, newKey.getContext()); } else if (key instanceof OCompositeKey) return searchIntersect((OCompositeKey) key, 0, null); } catch (IOException e) { OLogManager.instance().error(this, "Error on getting entry against Lucene index", e); } return null; }
Example #8
Source File: OLuceneSpatialIndexManager.java From orientdb-lucene with Apache License 2.0 | 6 votes |
public Object searchIntersect(OCompositeKey key, double distance, OCommandContext context) throws IOException { double lat = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(0), Double.class)).doubleValue(); double lng = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(1), Double.class)).doubleValue(); SpatialOperation operation = SpatialOperation.Intersects; Point p = ctx.makePoint(lng, lat); SpatialArgs args = new SpatialArgs(operation, ctx.makeCircle(lng, lat, DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM))); Filter filter = strategy.makeFilter(args); IndexSearcher searcher = getSearcher(); ValueSource valueSource = strategy.makeDistanceValueSource(p); Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(searcher); return new LuceneResultSet(this, new SpatialQueryContext(context, searcher, new MatchAllDocsQuery(), filter, distSort).setSpatialArgs(args)); }
Example #9
Source File: OLuceneIndexType.java From orientdb-lucene with Apache License 2.0 | 6 votes |
public static Query createDeleteQuery(OIdentifiable value, List<String> fields, Object key) { BooleanQuery booleanQuery = new BooleanQuery(); booleanQuery.add(new TermQuery(new Term(OLuceneIndexManagerAbstract.RID, value.toString())), BooleanClause.Occur.MUST); Map<String, String> values = new HashMap<String, String>(); // TODO Implementation of Composite keys with Collection if (key instanceof OCompositeKey) { } else { values.put(fields.iterator().next(), key.toString()); } for (String s : values.keySet()) { booleanQuery.add(new TermQuery(new Term(s + OLuceneIndexManagerAbstract.STORED, values.get(s))), BooleanClause.Occur.MUST); } return booleanQuery; }
Example #10
Source File: OLuceneIndexType.java From orientdb-lucene with Apache License 2.0 | 6 votes |
public static Query createFullQuery(OIndexDefinition index, Object key, Analyzer analyzer, Version version) throws ParseException { String query = ""; if (key instanceof OCompositeKey) { Object params = ((OCompositeKey) key).getKeys().get(0); if (params instanceof Map) { Object q = ((Map) params).get("q"); if (q != null) { query = q.toString(); } } else { query = params.toString(); } } else { query = key.toString(); } return getQueryParser(index, query, analyzer, version); }
Example #11
Source File: OPointShapeFactory.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Override public Shape makeShape(OCompositeKey key, SpatialContext ctx) { double lat = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(0), Double.class)).doubleValue(); double lng = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(1), Double.class)).doubleValue(); return ctx.makePoint(lng, lat); }
Example #12
Source File: AbstractConfigRule.java From light with Apache License 2.0 | 5 votes |
public OrientVertex getConfigByHostId(OrientGraph graph, String host, String configId) { OrientVertex config = null; OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("configHostIdIdx"); OCompositeKey key = new OCompositeKey(host, configId); OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key); if (oid != null) { config = graph.getVertex(oid.getRecord()); } return config; }
Example #13
Source File: BranchRule.java From light with Apache License 2.0 | 5 votes |
public OrientVertex getBranchByHostId(OrientGraph graph, String branchType, String host, String categoryId) { OrientVertex branch = null; OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex(branchType + "HostIdIdx"); OCompositeKey key = new OCompositeKey(host, categoryId); OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key); if (oid != null) { branch = graph.getVertex(oid.getRecord()); } return branch; }
Example #14
Source File: OPolygonShapeFactory.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Override public Shape makeShape(OCompositeKey key, SpatialContext ctx) { SpatialContext ctx1 = JtsSpatialContext.GEO; String value = key.getKeys().get(0).toString(); try { return ctx1.getWktShapeParser().parse(value); } catch (ParseException e) { OLogManager.instance().error(this, "Error on making shape", e); } return null; }
Example #15
Source File: ORectangleShapeFactory.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Override public Shape makeShape(OCompositeKey key, SpatialContext ctx) { Point[] points = new Point[2]; int i = 0; for (Object o : key.getKeys()) { List<Number> numbers = (List<Number>) o; double lat = ((Double) OType.convert(numbers.get(0), Double.class)).doubleValue(); double lng = ((Double) OType.convert(numbers.get(1), Double.class)).doubleValue(); points[i] = ctx.makePoint(lng, lat); i++; } return ctx.makeRectangle(points[0], points[1]); }
Example #16
Source File: OShapeFactoryImpl.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Override public Shape makeShape(OCompositeKey key, SpatialContext ctx) { for (OShapeFactory f : factories.values()) { if (f.canHandle(key)) { return f.makeShape(key, ctx); } } return null; }
Example #17
Source File: OLuceneSpatialIndexManager.java From orientdb-lucene with Apache License 2.0 | 5 votes |
@Override public void put(Object key, Object value) { OCompositeKey compositeKey = (OCompositeKey) key; if (key instanceof OCompositeKey) { } Set<OIdentifiable> container = (Set<OIdentifiable>) value; for (OIdentifiable oIdentifiable : container) { addDocument(newGeoDocument(oIdentifiable, factory.makeShape(compositeKey, ctx))); } }
Example #18
Source File: OShapeFactoryImpl.java From orientdb-lucene with Apache License 2.0 | 4 votes |
@Override public boolean canHandle(OCompositeKey key) { return false; }
Example #19
Source File: SearchFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Transactional protected void rebuildComponentIndex() { try { Repository repository = getRepository(); StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(repository); ORID bucketId = bucketEntityAdapter.recordIdentity(bucket); if (bucket == null) { log.warn("Unable to rebuild search index for repository {}", repository.getName()); return; } long processed = 0; long total = componentStore.countComponents(ImmutableList.of(bucket)); if (total > 0) { ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60); Stopwatch sw = Stopwatch.createStarted(); OIndexCursor cursor = componentStore.getIndex(ComponentEntityAdapter.I_BUCKET_GROUP_NAME_VERSION).cursor(); List<Entry<OCompositeKey, EntityId>> nextPage = componentStore.getNextPage(cursor, PAGE_SIZE); while (!Iterables.isEmpty(nextPage)) { List<EntityId> componentIds = nextPage.stream() .filter(entry -> bucketId.equals(entry.getKey().getKeys().get(BUCKET))) .map(Entry::getValue) .collect(toList()); processed += componentIds.size(); bulkPut(componentIds); long elapsed = sw.elapsed(TimeUnit.MILLISECONDS); progressLogger .info("Indexed {} / {} {} components in {} ms", processed, total, repository.getName(), elapsed); nextPage = componentStore.getNextPage(cursor, PAGE_SIZE); } progressLogger.flush(); // ensure the final progress message is flushed } } catch (Exception e) { log.error("Unable to rebuild search index for repository {}", getRepository().getName(), e); } }
Example #20
Source File: OPolygonShapeFactory.java From orientdb-lucene with Apache License 2.0 | 4 votes |
@Override public boolean canHandle(OCompositeKey key) { return false; }
Example #21
Source File: AbstractCatalogRule.java From light with Apache License 2.0 | 4 votes |
protected void addProductDb(Map<String, Object> data) throws Exception { String host = (String)data.get("host"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); OrientVertex createUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("createUserId")); String parentId = (String)data.remove("parentId"); List<String> tags = (List<String>)data.remove("tags"); OrientVertex product = graph.addVertex("class:Product", data); createUser.addEdge("Create", product); // parent OrientVertex parent = getBranchByHostId(graph, categoryType, host, parentId); if(parent != null) { parent.addEdge("HasProduct", product); } // tag if(tags != null && tags.size() > 0) { for(String tagId: tags) { Vertex tag = null; // get the tag is it exists OIndex<?> tagHostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("tagHostIdIdx"); OCompositeKey tagKey = new OCompositeKey(host, tagId); OIdentifiable tagOid = (OIdentifiable) tagHostIdIdx.get(tagKey); if (tagOid != null) { tag = graph.getVertex(tagOid.getRecord()); product.addEdge("HasTag", tag); } else { tag = graph.addVertex("class:Tag", "host", host, "tagId", tagId, "createDate", data.get("createDate")); createUser.addEdge("Create", tag); product.addEdge("HasTag", tag); } } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example #22
Source File: AbstractBfnRule.java From light with Apache License 2.0 | 4 votes |
protected void addPostDb(String bfnType, Map<String, Object> data) throws Exception { String className = bfnType.substring(0, 1).toUpperCase() + bfnType.substring(1); String host = (String)data.get("host"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId")); List<String> tags = (List<String>)data.remove("tags"); OrientVertex post = graph.addVertex("class:Post", data); createUser.addEdge("Create", post); // parent OrientVertex parent = getBranchByHostId(graph, bfnType, host, (String) data.get("parentId")); if(parent != null) { parent.addEdge("HasPost", post); } // tag if(tags != null && tags.size() > 0) { for(String tagId: tags) { Vertex tag = null; // get the tag is it exists OIndex<?> tagHostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("tagHostIdIdx"); OCompositeKey tagKey = new OCompositeKey(host, tagId); OIdentifiable tagOid = (OIdentifiable) tagHostIdIdx.get(tagKey); if (tagOid != null) { tag = graph.getVertex(tagOid.getRecord()); post.addEdge("HasTag", tag); } else { tag = graph.addVertex("class:Tag", "host", host, "tagId", tagId, "createDate", data.get("createDate")); createUser.addEdge("Create", tag); post.addEdge("HasTag", tag); } } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example #23
Source File: OrientRebuildBrowseNodeServiceTest.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private Entry<Object, EntityId> createIndexEntry(final ORID bucketId, final EntityId id) { return new SimpleEntry<>(new OCompositeKey(bucketId), id); }
Example #24
Source File: RebuildAssetUploadMetadataTask.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Override protected Object execute() { long totalAssets = assetStore.countAssets(null); long processedAssets = 0; OIndexCursor assetCursor = assetStore.getIndex(AssetEntityAdapter.I_BUCKET_COMPONENT_NAME).cursor(); ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60); List<Entry<OCompositeKey, EntityId>> assets = assetStore.getNextPage(assetCursor, limit); if (!Iterables.isEmpty(assets) && !Strings2.isBlank(assetStore.getById(assets.get(0).getValue()).createdBy())) { return null; } while (assets != null && !assets.isEmpty()) { checkContinuation(); Iterable<EntityId> assetIds = assets.stream().map(Entry::getValue).collect(toList()); Collection<Asset> assetsToUpdate = stream(assetStore.getByIds(assetIds)) .filter(asset -> Strings2.isEmpty(asset.createdBy())) .filter(asset -> asset.blobRef() != null).map(asset -> { BlobStore blobStore = blobStoreManager.get(asset.blobRef().getStore()); Blob blob = blobStore.get(asset.blobRef().getBlobId()); if (blob != null) { asset.createdBy(blob.getHeaders().get(BlobStore.CREATED_BY_HEADER)); asset.createdByIp(blob.getHeaders().get(BlobStore.CREATED_BY_IP_HEADER)); asset.blobCreated(blob.getMetrics().getCreationTime()); } return asset; }).collect(toList()); assetStore.save(assetsToUpdate); processedAssets += size(assetsToUpdate); progressLogger.info("{} / {} asset upload metadata processed in {} ms", processedAssets, totalAssets, progressLogger.getElapsed()); assets = assetStore.getNextPage(assetCursor, limit); } progressLogger.flush(); return null; }
Example #25
Source File: OrientRebuildBrowseNodeService.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Override public void rebuild(final Repository repo, final BooleanSupplier isCancelled) throws RebuildBrowseNodeFailedException { log.info("Deleting browse nodes for repository {}", repo.getName()); browseNodeManager.deleteByRepository(repo.getName()); log.info("Rebuilding browse nodes for repository {}", repo.getName()); Bucket bucket = bucketStore.read(repo.getName()); ORID bucketId = AttachedEntityHelper.id(bucket); try { long processed = 0; long total = assetStore.countAssets(ImmutableList.of(bucket)); if (total > 0) { ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60); Stopwatch sw = Stopwatch.createStarted(); OIndexCursor cursor = assetStore.getIndex(AssetEntityAdapter.I_BUCKET_COMPONENT_NAME).cursor(); List<Entry<OCompositeKey, EntityId>> nextPage = assetStore.getNextPage(cursor, rebuildPageSize); while (!Iterables.isEmpty(nextPage)) { checkContinuation(isCancelled, repo.getName()); List<Asset> assets = new ArrayList<>(rebuildPageSize); for (Entry<OCompositeKey, EntityId> indexEntry : nextPage) { if (bucketId.equals(indexEntry.getKey().getKeys().get(BUCKET_KEY_ID))) { assets.add(assetStore.getById(indexEntry.getValue())); } } int assetsSize = Iterables.size(assets); browseNodeManager.createFromAssets(repo, assets); processed += assetsSize; long elapsed = sw.elapsed(TimeUnit.MILLISECONDS); progressLogger.info("Rebuilt browse nodes for {} / {} assets in {} ms", processed, total, elapsed); nextPage = assetStore.getNextPage(cursor, rebuildPageSize); } progressLogger.flush(); // ensure final rebuild message is flushed } } catch (Exception e) { throw new RebuildBrowseNodeFailedException("Could not re-create browse nodes", e); } }
Example #26
Source File: TestCreateNested1.java From orientdb-lucene with Apache License 2.0 | 3 votes |
@Test public void testIndex() { ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:tmp"); db.create(); OClass test = db.getMetadata().getSchema().createClass("Test"); test.createProperty("name", OType.STRING); test.createProperty("age", OType.INTEGER); test.createIndex("Test.name_age", OClass.INDEX_TYPE.NOTUNIQUE, "name", "age"); ODocument doc = new ODocument("Test"); doc.field("name", "Enrico"); doc.field("age", 32); db.save(doc); OIndex<?> index = db.getMetadata().getIndexManager().getIndex("Test.name_age"); Collection<OIdentifiable> results = (Collection<OIdentifiable>) index.get(new OCompositeKey(Arrays.asList("Enrico", 32))); Assert.assertEquals(results.size(), 1); results = (Collection<OIdentifiable>) index.get(new OCompositeKey(Arrays.asList("Enrico", 31))); Assert.assertEquals(results.size(), 0); }
Example #27
Source File: OShapeFactory.java From orientdb-lucene with Apache License 2.0 | votes |
public Shape makeShape(OCompositeKey key,SpatialContext ctx);
Example #28
Source File: OShapeFactory.java From orientdb-lucene with Apache License 2.0 | votes |
public boolean canHandle(OCompositeKey key);