@Override
  public void afterRegistration(
      final OObjectDatabaseTx db,
      final SchemeDescriptor descriptor,
      final Field field,
      final LuceneIndex annotation) {
    db.getMetadata().getIndexManager().reload();
    final String property = field.getName();
    final String model = descriptor.schemeClass;
    final String name =
        Objects.firstNonNull(Strings.emptyToNull(annotation.name().trim()), model + '.' + property);
    final OClass clazz = db.getMetadata().getSchema().getClass(model);
    final OIndex<?> classIndex = clazz.getClassIndex(name);
    final OClass.INDEX_TYPE type = OClass.INDEX_TYPE.FULLTEXT;
    if (!descriptor.initialRegistration && classIndex != null) {
      final IndexValidationSupport support = new IndexValidationSupport(classIndex, logger);
      support.checkTypeCompatible(type);
      support.checkFieldsCompatible(property);

      final boolean correct =
          support
              .isIndexSigns(
                  classIndex.getConfiguration().field("algorithm"), getAnalyzer(classIndex))
              .matchRequiredSigns(
                  type, OLuceneIndexFactory.LUCENE_ALGORITHM, annotation.value().getName());
      if (!correct) {
        support.dropIndex(db);
      } else {
        // index ok
        return;
      }
    }
    final ODocument metadata = createMetadata(annotation);
    SchemeUtils.command(
        db,
        "create index %s on %s (%s) %s engine %s metadata %s",
        name,
        model,
        property,
        type.name(),
        OLuceneIndexFactory.LUCENE_ALGORITHM,
        metadata.toJSON());
    logger.info("Lucene fulltext index '{}' ({} [{}]) created", name, model, property);
  }
  private static int priorityOfUsage(OIndex<?> index) {
    if (index == null) return -1;

    final OClass.INDEX_TYPE indexType = OClass.INDEX_TYPE.valueOf(index.getType());
    final boolean isComposite = isComposite(index);
    final boolean supportNullValues = supportNullValues(index);

    int priority = 1;

    if (isComposite) {
      if (!supportNullValues) return -1;
    } else {
      priority += 10;
    }

    switch (indexType) {
      case UNIQUE_HASH_INDEX:
      case NOTUNIQUE_HASH_INDEX:
        if (isComposite) return -1;
        else priority += 10;
        break;
      case UNIQUE:
      case NOTUNIQUE:
        priority += 5;
        break;
      case PROXY:
      case FULLTEXT:
      case DICTIONARY:
      case FULLTEXT_HASH_INDEX:
      case DICTIONARY_HASH_INDEX:
      case SPATIAL:
        return -1;
    }

    return priority;
  }