Examples of OIndex


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

    if (searchInIndexTriples.isEmpty())
      return false;

    for (OSearchInIndexTriple indexTriple : searchInIndexTriples) {
      final OIndex idx = indexTriple.index.getInternal();
      final OQueryOperator operator = indexTriple.indexOperator;
      final Object key = indexTriple.key;

      final boolean indexCanBeUsedInEqualityOperators = (idx instanceof OIndexUnique || idx instanceof OIndexNotUnique);

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorBetween) {
        final Object[] betweenKeys = (Object[]) key;
        fillSearchIndexResultSet(iResultSet,
            indexTriple.index.getValuesBetween(OSQLHelper.getValue(betweenKeys[0]), OSQLHelper.getValue(betweenKeys[2])));
        return true;
      }

      if ((indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorEquals) || idx instanceof OIndexFullText
          && operator instanceof OQueryOperatorContainsText) {
        fillSearchIndexResultSet(iResultSet, indexTriple.index.get(key));
        return true;
      }

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorMajor) {
        fillSearchIndexResultSet(iResultSet, idx.getValuesMajor(key, false));
        return true;
      }

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorMajorEquals) {
        fillSearchIndexResultSet(iResultSet, idx.getValuesMajor(key, true));
        return true;
      }

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorMinor) {
        fillSearchIndexResultSet(iResultSet, idx.getValuesMinor(key, false));
        return true;
      }

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorMinorEquals) {
        fillSearchIndexResultSet(iResultSet, idx.getValuesMinor(key, true));
        return true;
      }
    }
    return false;
  }
View Full Code Here

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

      prop = iSchemaClass.getProperty(item.getName());
    }

    if (prop != null && prop.isIndexed()) {
      final Object origValue = iCondition.getLeft() == iItem ? iCondition.getRight() : iCondition.getLeft();
      final OIndex underlyingIndex = prop.getIndex().getUnderlying();

      if (iCondition.getOperator() instanceof OQueryOperatorBetween) {
        iSearchInIndexTriples.add(new OSearchInIndexTriple(iCondition.getOperator(), origValue, underlyingIndex));
        return true;
      }

      Object value = OSQLHelper.getValue(origValue);

      if (value == null)
        return false;

      value = OType.convert(value, underlyingIndex.getKeyType().getDefaultJavaType());

      if (value == null)
        return false;

      iSearchInIndexTriples.add(new OSearchInIndexTriple(iCondition.getOperator(), value, underlyingIndex));
View Full Code Here

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

    // COMMIT INDEX CHANGES
    final ODocument indexEntries = currentTx.getIndexChanges();

    if (indexEntries != null) {
      for (Entry<String, Object> indexEntry : indexEntries) {
        final OIndex index = getMetadata().getIndexManager().getIndexInternal(indexEntry.getKey());
        index.commit((ODocument) indexEntry.getValue());
      }
    }
  }
View Full Code Here

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

    ODatabaseDocumentTx db = null;

    try {
      db = getProfiledDatabaseInstance(iRequest);

      final OIndex index = db.getMetadata().getIndexManager().getIndex(urlParts[2]);
      if (index == null)
        throw new IllegalArgumentException("Index name '" + urlParts[2] + "' not found");

      final OIdentifiable record;

      if (urlParts.length > 4)
        // GET THE RECORD ID AS VALUE
        record = new ORecordId(urlParts[4]);
      else {
        // GET THE REQUEST CONTENT AS DOCUMENT
        if (iRequest.content == null || iRequest.content.length() == 0)
          throw new IllegalArgumentException("Index's entry value is null");

        record = new ODocument(db).fromJSON(iRequest.content);
      }

      index.put(urlParts[3], record);

      sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN, "Key '" + urlParts[3]
          + "' correctly inserted into the index " + urlParts[2] + ".");
    } finally {
      if (db != null)
View Full Code Here

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

    ODatabaseDocumentTx db = null;

    try {
      db = getProfiledDatabaseInstance(iRequest);

      final OIndex index = db.getMetadata().getIndexManager().getIndex(urlParts[2]);
      if (index == null)
        throw new IllegalArgumentException("Index name '" + urlParts[2] + "' not found");

      final boolean found;
      if (urlParts.length > 4)
        found = index.remove(urlParts[3], new ORecordId(urlParts[3]));
      else
        found = index.remove(urlParts[3]);

      if (found)
        sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN, null);
      else
        sendTextContent(iRequest, OHttpUtils.STATUS_NOTFOUND_CODE, OHttpUtils.STATUS_NOTFOUND_DESCRIPTION, null,
View Full Code Here

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

    ODatabaseDocumentTx db = null;

    try {
      db = getProfiledDatabaseInstance(iRequest);

      final OIndex index = db.getMetadata().getIndexManager().getIndex(urlParts[2]);
      if (index == null)
        throw new IllegalArgumentException("Index name '" + urlParts[2] + "' not found");

      final Collection<OIdentifiable> content = index.get(urlParts[3]);

      if (content == null || content.size() == 0)
        sendTextContent(iRequest, OHttpUtils.STATUS_NOTFOUND_CODE, OHttpUtils.STATUS_NOTFOUND_DESCRIPTION, null,
            OHttpUtils.CONTENT_TEXT_PLAIN, null);
      else {
View Full Code Here

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

    listener.onMessage("\nRebuilding " + propertyIndexes.size() + " automatic indexes...");

    database.getMetadata().getIndexManager().reload();

    for (Entry<OProperty, String> e : propertyIndexes.entrySet()) {
      final OIndex idx = database.getMetadata().getIndexManager().getIndex(e.getValue());
      if (idx != null) {
        idx.setCallback(e.getKey().getIndex());

        listener.onMessage("\n- Index '" + idx.getName() + "'...");

        // idx.rebuild(new OProgressListener() {
        // public boolean onProgress(Object iTask, long iCounter, float iPercent) {
        // if (iPercent % 10 == 0)
        // listener.onMessage(".");
        // return false;
        // }
        //
        // public void onCompletition(Object iTask, boolean iSucceed) {
        // }
        //
        // public void onBegin(Object iTask, long iTotal) {
        // }
        // });

        listener.onMessage("OK (" + idx.getSize() + " records)");
      }
    }
  }
View Full Code Here

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

      if (indexName == null || indexName.length() == 0)
        return;

      listener.onMessage("\n- Index '" + indexName + "'...");

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

      long tot = 0;

      jsonReader.readNext(OJSONReader.BEGIN_OBJECT);

      String n;
      do {
        jsonReader.readNext(new char[] { ':', '}' });

        if (jsonReader.lastChar() != '}') {
          key = jsonReader.checkContent("\"key\"").readString(OJSONReader.COMMA_SEPARATOR);
          value = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"value\"")
              .readString(OJSONReader.NEXT_IN_OBJECT);

          if (index != null)
            if (value.length() >= 4) {
              if (value.charAt(0) == '[')
                // REMOVE []
                value = value.substring(1, value.length() - 1);

              List<String> rids = OStringSerializerHelper.split(value, ',', new char[] { '#', '"' });

              for (String rid : rids) {
                doc.setIdentity(new ORecordId(rid));
                index.put(key, doc);
              }
            }

          tot++;
        }
View Full Code Here

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

    // COMMIT INDEX CHANGES
    final ODocument indexEntries = currentTx.getIndexChanges();

    if (indexEntries != null) {
      for (Entry<String, Object> indexEntry : indexEntries) {
        final OIndex index = getMetadata().getIndexManager().getIndexInternal(indexEntry.getKey());
        index.commit((ODocument) indexEntry.getValue());
      }
    }
  }
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.