class NpmSearchParameterExtractor extends ComponentSupport {

  public String extractText(final Parameters parameters) {
    String textParameter = Strings.nullToEmpty(parameters.get("text")).trim();
    if (!textParameter.isEmpty()) {
      // HACK: replace the various special search fields with their ES field names, and assume "maintainer" is author
      // A better way would be to parse the actual query into an AST and then rewrite, but we're not doing that for now
      textParameter = textParameter
          .replaceAll("keywords:", "assets.attributes.npm.keywords:")
          .replaceAll("author:", "assets.attributes.npm.author:")
          .replaceAll("maintainer:", "assets.attributes.npm.author:")
          .replaceAll("is:", "assets.attributes.npm.tagged_is:")
          .replaceAll("not:", "assets.attributes.npm.tagged_not:")
          .replaceAll("scope:", "assets.attributes.npm.scope:");

      // HACK: if we don't have a keyword that we're specifically searching on, prefix and suffix the search string with
      // wildcard characters to mimic the partial matching behavior that the upstream npm search endpoint already does
      if (!textParameter.contains(":")) {
        textParameter = WILDCARD + textParameter + WILDCARD;
      }
    }
    return textParameter;
  }

}