public static ConditionTemplate autocompleteFieldMatching(String text) {
    if (StringUtils.isBlank(text)) {
      return ConditionTemplate.field(Schemas.IDENTIFIER, new IsEqualCriterion("a38"));
    }
    String cleanedText = AccentApostropheCleaner.removeAccents(text).toLowerCase();

    String[] cleanedTextWords = cleanedText.split(" ");

    LogicalSearchValueCondition condition;
    if (cleanedTextWords.length == 1) {
      if (cleanedText.endsWith(" ")) {
        condition = new IsEqualCriterion(cleanedText.trim());
      } else {
        condition = new IsStartingWithTextCriterion(cleanedText.trim());
      }
    } else {
      List<LogicalSearchValueCondition> conditions = new ArrayList<>();
      for (int i = 0; i < cleanedTextWords.length; i++) {
        if (i + 1 == cleanedTextWords.length) {
          if (cleanedText.endsWith(" ")) {
            conditions.add(new IsEqualCriterion(cleanedTextWords[i]));
          } else {
            conditions.add(new IsStartingWithTextCriterion(cleanedTextWords[i]));
          }
        } else {
          conditions.add(new IsEqualCriterion(cleanedTextWords[i]));
        }
      }
      condition = all(conditions);
    }

    return ConditionTemplate.field(Schemas.SCHEMA_AUTOCOMPLETE_FIELD, condition);
  }
 public static ConditionTemplate schemaTypeIsNotIn(List<String> types) {
   List<LogicalSearchValueCondition> schemaTypesCriteria = new ArrayList<>();
   for (String type : types) {
     schemaTypesCriteria.add(LogicalSearchQueryOperators.startingWithText(type));
   }
   return ConditionTemplate.field(Schemas.SCHEMA, not(any(schemaTypesCriteria)));
 }
  public ConditionTemplate metadatasHasAnalyzedValue(String value, List<Metadata> metadatas) {

    List<String> availableLanguages =
        modelLayerFactory.getCollectionsListManager().getCollectionLanguages(collection);
    LanguageDetectionManager languageDetectionManager =
        modelLayerFactory.getLanguageDetectionManager();

    String language =
        availableLanguages.size() == 1
            ? availableLanguages.get(0)
            : languageDetectionManager.tryDetectLanguage(value);
    List<Metadata> searchedMetadatas = new ArrayList<>();
    for (Metadata metadata : metadatas) {
      if (!availableLanguages.contains(language) || language == null) {
        for (String availableLanguage : availableLanguages) {
          searchedMetadatas.add(metadata.getSearchableMetadataWithLanguage(availableLanguage));
        }
      } else {
        searchedMetadatas.add(metadata.getSearchableMetadataWithLanguage(language));
      }
    }

    return ConditionTemplate.anyField(searchedMetadatas, query(value));
  }