Class QueryParserHelper

java.lang.Object
org.elasticsearch.index.search.QueryParserHelper

public final class QueryParserHelper
extends java.lang.Object
Helpers to extract and expand field names and boosts
  • Method Summary

    Modifier and Type Method Description
    static boolean hasAllFieldsWildcard​(java.util.Collection<java.lang.String> fields)
    Returns true if any of the fields is the wildcard *, false otherwise.
    static java.util.Map<java.lang.String,​java.lang.Float> parseFieldsAndWeights​(java.util.List<java.lang.String> fields)
    Convert a list of field names encoded with optional boosts to a map that associates the field name and its boost.
    static java.util.Map<java.lang.String,​java.lang.Float> resolveMappingField​(QueryShardContext context, java.lang.String fieldOrPattern, float weight, boolean acceptAllTypes, boolean acceptMetadataField)
    Resolves the provided pattern or field name from the QueryShardContext and return a map of the expanded fields with their original boost.
    static java.util.Map<java.lang.String,​java.lang.Float> resolveMappingField​(QueryShardContext context, java.lang.String fieldOrPattern, float weight, boolean acceptAllTypes, boolean acceptMetadataField, java.lang.String fieldSuffix)
    Resolves the provided pattern or field name from the QueryShardContext and return a map of the expanded fields with their original boost.
    static java.util.Map<java.lang.String,​java.lang.Float> resolveMappingFields​(QueryShardContext context, java.util.Map<java.lang.String,​java.lang.Float> fieldsAndWeights)  
    static java.util.Map<java.lang.String,​java.lang.Float> resolveMappingFields​(QueryShardContext context, java.util.Map<java.lang.String,​java.lang.Float> fieldsAndWeights, java.lang.String fieldSuffix)
    Resolve all the field names and patterns present in the provided map with the QueryShardContext and returns a new map containing all the expanded fields with their original boost.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parseFieldsAndWeights

      public static java.util.Map<java.lang.String,​java.lang.Float> parseFieldsAndWeights​(java.util.List<java.lang.String> fields)
      Convert a list of field names encoded with optional boosts to a map that associates the field name and its boost.
      Parameters:
      fields - The list of fields encoded with optional boosts (e.g. ^0.35).
      Returns:
      The converted map with field names and associated boosts.
    • resolveMappingFields

      public static java.util.Map<java.lang.String,​java.lang.Float> resolveMappingFields​(QueryShardContext context, java.util.Map<java.lang.String,​java.lang.Float> fieldsAndWeights)
    • resolveMappingFields

      public static java.util.Map<java.lang.String,​java.lang.Float> resolveMappingFields​(QueryShardContext context, java.util.Map<java.lang.String,​java.lang.Float> fieldsAndWeights, java.lang.String fieldSuffix)
      Resolve all the field names and patterns present in the provided map with the QueryShardContext and returns a new map containing all the expanded fields with their original boost.
      Parameters:
      context - The context of the query.
      fieldsAndWeights - The map of fields and weights to expand.
      fieldSuffix - The suffix name to add to the expanded field names if a mapping exists for that name. The original name of the field is kept if adding the suffix to the field name does not point to a valid field in the mapping.
    • resolveMappingField

      public static java.util.Map<java.lang.String,​java.lang.Float> resolveMappingField​(QueryShardContext context, java.lang.String fieldOrPattern, float weight, boolean acceptAllTypes, boolean acceptMetadataField)
      Resolves the provided pattern or field name from the QueryShardContext and return a map of the expanded fields with their original boost.
      Parameters:
      context - The context of the query
      fieldOrPattern - The field name or the pattern to resolve
      weight - The weight for the field
      acceptAllTypes - Whether all field type should be added when a pattern is expanded. If false, only searchable field types are added.
      acceptMetadataField - Whether metadata fields should be added when a pattern is expanded.
    • resolveMappingField

      public static java.util.Map<java.lang.String,​java.lang.Float> resolveMappingField​(QueryShardContext context, java.lang.String fieldOrPattern, float weight, boolean acceptAllTypes, boolean acceptMetadataField, java.lang.String fieldSuffix)
      Resolves the provided pattern or field name from the QueryShardContext and return a map of the expanded fields with their original boost.
      Parameters:
      context - The context of the query
      fieldOrPattern - The field name or the pattern to resolve
      weight - The weight for the field
      acceptAllTypes - Whether all field type should be added when a pattern is expanded. If false, only searchable field types are added.
      acceptMetadataField - Whether metadata fields should be added when a pattern is expanded.
      fieldSuffix - The suffix name to add to the expanded field names if a mapping exists for that name. The original name of the field is kept if adding the suffix to the field name does not point to a valid field in the mapping.
    • hasAllFieldsWildcard

      public static boolean hasAllFieldsWildcard​(java.util.Collection<java.lang.String> fields)
      Returns true if any of the fields is the wildcard *, false otherwise.
      Parameters:
      fields - A collection of field names