Examples of OIndex


Examples of com.orientechnologies.orient.core.index.OIndex

      foreach(record);
    }
  }

  private void searchInIndex() {
    final OIndex index = database.getMetadata().getIndexManager().getIndex(compiledFilter.getTargetIndex());
    if (index == null)
      throw new OCommandExecutionException("Target index '" + compiledFilter.getTargetIndex() + "' not found");

    if (compiledFilter.getRootCondition() != null) {
      if (!"KEY".equalsIgnoreCase(compiledFilter.getRootCondition().getLeft().toString()))
        throw new OCommandExecutionException("'Key' field is required for queries against indexes");

      final Object right = compiledFilter.getRootCondition().getRight();
      final Object keyValue = OSQLHelper.getValue(right);

      Collection<OIdentifiable> result = null;
      final OQueryOperator indexOperator = compiledFilter.getRootCondition().getOperator();
      if (indexOperator instanceof OQueryOperatorBetween) {
        final Object[] values = (Object[]) compiledFilter.getRootCondition().getRight();

        if (projections != null && projections.size() == 1 && projections.keySet().iterator().next().equalsIgnoreCase("@rid")) {
          // SPECIAL CASE
          result = index.getValuesBetween(OSQLHelper.getValue(values[0]), OSQLHelper.getValue(values[2]));

          for (OIdentifiable e : result)
            addResult(e.getIdentity());

        } else {
          final Collection<ODocument> entries = index.getEntriesBetween(OSQLHelper.getValue(values[0]),
              OSQLHelper.getValue(values[2]));

          for (OIdentifiable r : entries)
            addResult(r);
        }

      } else if (indexOperator instanceof OQueryOperatorMajor) {
        final Object value = compiledFilter.getRootCondition().getRight();
        if (projections != null && projections.size() == 1 && projections.keySet().iterator().next().equalsIgnoreCase("@rid")) {
          // SPECIAL CASE
          result = index.getValuesMajor(OSQLHelper.getValue(value), false);

          for (OIdentifiable e : result)
            addResult(e.getIdentity());

        } else {
          final Collection<ODocument> entries = index.getEntriesMajor(OSQLHelper.getValue(value), false);

          for (ODocument document : entries)
            addResult(document);
        }
      } else if (indexOperator instanceof OQueryOperatorMajorEquals) {
        final Object value = compiledFilter.getRootCondition().getRight();
        if (projections != null && projections.size() == 1 && projections.keySet().iterator().next().equalsIgnoreCase("@rid")) {
          // SPECIAL CASE
          result = index.getValuesMajor(OSQLHelper.getValue(value), true);

          for (OIdentifiable e : result)
            addResult(e.getIdentity());

        } else {
          final Collection<ODocument> entries = index.getEntriesMajor(OSQLHelper.getValue(value), true);

          for (ODocument document : entries)
            addResult(document);
        }
      } else if (indexOperator instanceof OQueryOperatorMinor) {
        final Object value = compiledFilter.getRootCondition().getRight();
        if (projections != null && projections.size() == 1 && projections.keySet().iterator().next().equalsIgnoreCase("@rid")) {
          // SPECIAL CASE
          result = index.getValuesMinor(OSQLHelper.getValue(value), false);

          for (OIdentifiable e : result)
            addResult(e.getIdentity());

        } else {
          final Collection<ODocument> entries = index.getEntriesMinor(OSQLHelper.getValue(value), false);

          for (ODocument document : entries)
            addResult(document);
        }
      } else if (indexOperator instanceof OQueryOperatorMinorEquals) {
        final Object value = compiledFilter.getRootCondition().getRight();
        if (projections != null && projections.size() == 1 && projections.keySet().iterator().next().equalsIgnoreCase("@rid")) {
          // SPECIAL CASE
          result = index.getValuesMinor(OSQLHelper.getValue(value), true);

          for (OIdentifiable e : result)
            addResult(e.getIdentity());

        } else {
          final Collection<ODocument> entries = index.getEntriesMinor(OSQLHelper.getValue(value), true);

          for (ODocument document : entries)
            addResult(document);
        }
      } else {
        result = index.get(keyValue);

        for (OIdentifiable r : result)
          addResult(createIndexEntryAsDocument(keyValue, r.getIdentity()));
      }

    } else {

      // ADD ALL THE ITEMS AS RESULT
      for (Iterator<Entry<Object, Set<OIdentifiable>>> it = index.iterator(); it.hasNext();) {
        final Entry<Object, Set<OIdentifiable>> current = it.next();

        for (Iterator<OIdentifiable> collIt = ((ORecordLazySet) current.getValue()).rawIterator(); collIt.hasNext();)
          addResult(createIndexEntryAsDocument(current.getKey(), collIt.next().getIdentity()));
      }

    }

    if (anyFunctionAggregates) {
      for (Entry<String, Object> projection : projections.entrySet()) {
        if (projection.getValue() instanceof OSQLFunctionRuntime) {
          final OSQLFunctionRuntime f = (OSQLFunctionRuntime) projection.getValue();
          f.setResult(index.getSize());
        }
      }
    }
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

  @Test(dependsOnMethods = "testDuplicatedIndexOnUnique")
  public void testIndexEntries() {
    List<Profile> result = database.command(new OSQLSynchQuery<Profile>("select * from Profile where nick is not null")).execute();

    OIndex idx = database.getMetadata().getIndexManager().getIndex("Profile.nick");

    Assert.assertEquals(idx.getSize(), result.size());
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Long> valuesMajorResults = new ArrayList<Long>(Arrays.asList(4L, 5L));
    Collection<OIdentifiable> indexCollection = index.getValuesMajor(3, false);
    Assert.assertEquals(indexCollection.size(), 2);
    for (OIdentifiable identifiable : indexCollection) {
      valuesMajorResults.remove(identifiable.getIdentity().getClusterPosition());
    }
    Assert.assertEquals(valuesMajorResults.size(), 0);

    final Collection<Long> valuesMajorInclusiveResults = new ArrayList<Long>(Arrays.asList(3L, 4L, 5L));
    indexCollection = index.getValuesMajor(3, true);
    Assert.assertEquals(indexCollection.size(), 3);
    for (OIdentifiable identifiable : indexCollection) {
      valuesMajorInclusiveResults.remove(identifiable.getIdentity().getClusterPosition());
    }
    Assert.assertEquals(valuesMajorInclusiveResults.size(), 0);

    indexCollection = index.getValuesMajor(5, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().getIdentity().getClusterPosition(), 5L);

    indexCollection = index.getValuesMajor(5, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Integer> valuesMajorResults = new ArrayList<Integer>(Arrays.asList(4, 5));
    Collection<ODocument> indexCollection = index.getEntriesMajor(3, false);
    Assert.assertEquals(indexCollection.size(), 2);
    for (ODocument doc : indexCollection) {
      valuesMajorResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMajorResults.size(), 0);

    final Collection<Integer> valuesMajorInclusiveResults = new ArrayList<Integer>(Arrays.asList(3, 4, 5));
    indexCollection = index.getEntriesMajor(3, true);
    Assert.assertEquals(indexCollection.size(), 3);
    for (ODocument doc : indexCollection) {
      valuesMajorInclusiveResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMajorInclusiveResults.size(), 0);

    indexCollection = index.getEntriesMajor(5, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().<Integer> field("key"), Integer.valueOf(5));
    Assert.assertEquals(indexCollection.iterator().next().<ORecordId> rawField("rid"), new ORecordId(10, 5));

    indexCollection = index.getEntriesMajor(5, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Long> valuesMinorResults = new ArrayList<Long>(Arrays.asList(0L, 1L, 2L));
    Collection<OIdentifiable> indexCollection = index.getValuesMinor(3, false);
    Assert.assertEquals(indexCollection.size(), 3);
    for (OIdentifiable identifiable : indexCollection) {
      valuesMinorResults.remove(identifiable.getIdentity().getClusterPosition());
    }
    Assert.assertEquals(valuesMinorResults.size(), 0);

    final Collection<Long> valuesMinorInclusiveResults = new ArrayList<Long>(Arrays.asList(0L, 1L, 2L, 3L));
    indexCollection = index.getValuesMinor(3, true);
    Assert.assertEquals(indexCollection.size(), 4);
    for (OIdentifiable identifiable : indexCollection) {
      valuesMinorInclusiveResults.remove(identifiable.getIdentity().getClusterPosition());
    }
    Assert.assertEquals(valuesMinorInclusiveResults.size(), 0);

    indexCollection = index.getValuesMinor(0, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().getIdentity().getClusterPosition(), 0L);

    indexCollection = index.getValuesMinor(0, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Integer> valuesMinorResults = new ArrayList<Integer>(Arrays.asList(0, 1, 2));
    Collection<ODocument> indexCollection = index.getEntriesMinor(3, false);
    Assert.assertEquals(indexCollection.size(), 3);
    for (ODocument doc : indexCollection) {
      valuesMinorResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMinorResults.size(), 0);

    final Collection<Integer> valuesMinorInclusiveResults = new ArrayList<Integer>(Arrays.asList(0, 1, 2, 3));
    indexCollection = index.getEntriesMinor(3, true);
    Assert.assertEquals(indexCollection.size(), 4);
    for (ODocument doc : indexCollection) {
      valuesMinorInclusiveResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
    Assert.assertEquals(valuesMinorInclusiveResults.size(), 0);

    indexCollection = index.getEntriesMinor(0, true);
    Assert.assertEquals(indexCollection.size(), 1);
    Assert.assertEquals(indexCollection.iterator().next().<Integer> field("key"), Integer.valueOf(0));
    Assert.assertEquals(indexCollection.iterator().next().<ORecordId> rawField("rid"), new ORecordId(10, 0));

    indexCollection = index.getEntriesMinor(0, false);
    Assert.assertEquals(indexCollection.size(), 0);

    database.command(new OCommandSQL("drop index equalityIdx")).execute();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    for (int key = 0; key <= 5; key++) {
      database.command(new OCommandSQL("insert into index:equalityIdx (key,rid) values (" + key + ",#10:" + key + ")")).execute();
    }

    final OIndex index = database.getMetadata().getIndexManager().getIndex("equalityIdx");

    final Collection<Integer> betweenResults = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
    Collection<ODocument> indexCollection = index.getEntriesBetween(1, 3);
    Assert.assertEquals(indexCollection.size(), 3);
    for (ODocument doc : indexCollection) {
      betweenResults.remove(doc.<Integer> field("key"));
      Assert.assertEquals(doc.<ORecordId> rawField("rid"), new ORecordId(10, doc.<Integer> field("key").longValue()));
    }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

  }

  public void LongTypes() {
    database.getMetadata().getSchema().getClass("Profile").createProperty("hash", OType.LONG).createIndex(INDEX_TYPE.UNIQUE);

    OIndex idx = database.getMetadata().getIndexManager().getIndex("Profile.hash");

    for (int i = 0; i < 5; i++) {
      Profile profile = new Profile("HashTest1").setHash(100l + i);
      database.save(profile);
    }

    Iterator<Entry<Object, Set<OIdentifiable>>> it = idx.iterator();
    while (it.hasNext()) {
      it.next();
    }

    Assert.assertEquals(idx.getSize(), 5);
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    final List<Account> result = database.command(new OSQLSynchQuery<Profile>("select * from Account limit 1")).execute();

    // Assert.assertEquals(result.size(), 1);

    OIndex idx = database.getMetadata().getIndexManager().getIndex("Whiz.account");

    for (int i = 0; i < 5; i++) {
      ODocument whiz = new ODocument(database.getUnderlying(), "Whiz");

      whiz.field("id", i);
      whiz.field("text", "This is a test");
      whiz.field("account", result.get(0).getRid());

      whiz.save();
    }

    Assert.assertEquals(idx.getSize(), 1);

    List<ODocument> indexedResult = database.getUnderlying()
        .command(new OSQLSynchQuery<Profile>("select * from Whiz where account = ?")).execute(result.get(0).getRid());

    Assert.assertEquals(indexedResult.size(), 5);
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    linkedClassName = (String) document.field("linkedClass");
    if (document.field("linkedType") != null)
      linkedType = OType.getById(((Integer) document.field("linkedType")).byteValue());

    final OIndex underlyingIndex = getDatabase().getMetadata().getIndexManager().getIndex(getFullName());

    if (underlyingIndex != null)
      index = new OPropertyIndex(getDatabase(), owner, new String[] { name });
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.