Class SearchServiceInternalImpl

java.lang.Object
org.craftercms.studio.impl.v2.service.search.internal.SearchServiceInternalImpl
All Implemented Interfaces:
SearchService

public class SearchServiceInternalImpl extends Object implements SearchService
Internal implementation of SearchService
Author:
joseross
  • Field Details

    • CONFIG_KEY_FIELDS

      public static final String CONFIG_KEY_FIELDS
      See Also:
    • CONFIG_KEY_FACETS

      public static final String CONFIG_KEY_FACETS
      See Also:
    • CONFIG_KEY_TYPES

      public static final String CONFIG_KEY_TYPES
      See Also:
    • CONFIG_KEY_NAME

      public static final String CONFIG_KEY_NAME
      See Also:
    • CONFIG_KEY_FIELD

      public static final String CONFIG_KEY_FIELD
      See Also:
    • CONFIG_KEY_FACET_DATE

      public static final String CONFIG_KEY_FACET_DATE
      See Also:
    • CONFIG_KEY_FACET_MULTIPLE

      public static final String CONFIG_KEY_FACET_MULTIPLE
      See Also:
    • CONFIG_KEY_FACET_RANGES

      public static final String CONFIG_KEY_FACET_RANGES
      See Also:
    • CONFIG_KEY_FACET_RANGE_LABEL

      public static final String CONFIG_KEY_FACET_RANGE_LABEL
      See Also:
    • CONFIG_KEY_FACET_RANGE_FROM

      public static final String CONFIG_KEY_FACET_RANGE_FROM
      See Also:
    • CONFIG_KEY_FACET_RANGE_TO

      public static final String CONFIG_KEY_FACET_RANGE_TO
      See Also:
    • CONFIG_KEY_TYPE_MATCHES

      public static final String CONFIG_KEY_TYPE_MATCHES
      See Also:
    • CONFIG_KEY_FIELD_BOOST

      public static final String CONFIG_KEY_FIELD_BOOST
      See Also:
    • FACET_RANGE_MIN

      public static final String FACET_RANGE_MIN
      See Also:
    • FACET_RANGE_MAX

      public static final String FACET_RANGE_MAX
      See Also:
    • DEFAULT_MIME_TYPE

      public static final String DEFAULT_MIME_TYPE
      See Also:
    • EXACT_MATCH_PATTERN

      public static final Pattern EXACT_MATCH_PATTERN
    • PATH_MATCH_PATTERN

      public static final Pattern PATH_MATCH_PATTERN
    • MAX_RESULT_WINDOW

      public static final int MAX_RESULT_WINDOW
      Corresponds to 'index.max_result_window' default value
      See Also:
    • pathFieldName

      protected String pathFieldName
      Name of the field for paths
    • internalNameFieldName

      protected String internalNameFieldName
      Name of the field for internal name
    • lastEditFieldName

      protected String lastEditFieldName
      Name of the field for last edit date
    • lastEditorFieldName

      protected String lastEditorFieldName
      Name of the field for last edit user
    • sizeFieldName

      protected String sizeFieldName
      Name of the field for size
    • mimeTypeName

      protected String mimeTypeName
      Name of the field for mimeType
    • searchFields

      protected Map<String,String> searchFields
      List of fields to include during searching
    • highlightFields

      protected String[] highlightFields
      List of fields to include during highlighting
    • snippetSize

      protected int snippetSize
      Number of characters to include for snippets
    • numberOfSnippets

      protected int numberOfSnippets
      Number of snippets to generate for each file
    • defaultType

      protected String defaultType
      Default label used for unknown file types
    • searchService

      protected final PermissionAwareSearchService searchService
      The Search service
    • studioConfiguration

      protected final StudioConfiguration studioConfiguration
      The Studio configuration
    • servicesConfig

      protected final ServicesConfig servicesConfig
      The site configuration
    • facets

      protected Map<String,FacetTO> facets
      Configurations for facets
    • types

      protected Map<String,org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>> types
      Configurations for types
  • Constructor Details

  • Method Details

    • init

      public void init()
      Loads facets and type mapping from the global configuration
    • addBoosting

      protected String addBoosting(String field, float boosting)
    • loadFieldsFromGlobalConfiguration

      protected void loadFieldsFromGlobalConfiguration()
    • loadFacetsFromGlobalConfiguration

      protected void loadFacetsFromGlobalConfiguration()
      Loads the facets from the global configuration
    • loadTypesFromGlobalConfiguration

      protected void loadTypesFromGlobalConfiguration()
      Loads the type mapping from the global configuration
    • processSearchHit

      protected SearchResultItem processSearchHit(Map<String,Object> source, Map<String,List<String>> highlights, List<String> additionalFields)
      Maps the information from OpenSearch for a single SearchResultItem
      Parameters:
      source - the fields returned by OpenSearch
      highlights - the highlights returned by OpenSearch
      Returns:
      the search item object
    • updateFilters

      protected void updateFilters(org.opensearch.client.opensearch._types.query_dsl.BoolQuery.Builder query, SearchParams params, Map<String,FacetTO> siteFacets)
      Adds the required filters based on the given parameters
      Parameters:
      query - the query to update
      params - the parameters to add
      siteFacets - the facets configured for the site
    • updateHighlighting

      protected void updateHighlighting(org.opensearch.client.opensearch.core.SearchRequest.Builder builder)
      Adds the configured highlighting to the given builder
      Parameters:
      builder - the search builder to update
    • processResults

      protected SearchResult processResults(org.opensearch.client.opensearch.core.SearchResponse<Map> response, Map<String,FacetTO> siteFacets, List<String> additionalFields)
      Maps the OpenSearch SearchResponse to a SearchResult object
      Parameters:
      response - the response to map
      Returns:
      the search result object
    • search

      public SearchResult search(String siteId, SearchParams params, int maxExpansions) throws ServiceLayerException
      Performs a search operation for a given site
      Specified by:
      search in interface SearchService
      Parameters:
      siteId - the id of the site
      params - the parameters for the search
      maxExpansions - Specifies the maximum number of terms for fuzzy queries expands to.
      Returns:
      the search results
      Throws:
      ServiceLayerException - if there is any error executing the search in OpenSearch
    • buildAggregations

      protected void buildAggregations(org.opensearch.client.opensearch.core.SearchRequest.Builder builder, Map<String,FacetTO> siteFacets)
      Adds the aggregations needed to the given builder
      Parameters:
      builder - the search source builder
      siteFacets - the facets from the site configuration
    • getSortFieldName

      protected String getSortFieldName(String name)
      Maps the field name from the configured facets, if it's not found returns the same value.
      Parameters:
      name - the facet name
      Returns:
      name of the field to sort
    • getItemType

      protected String getItemType(Map<String,Object> source)
      Maps the item type for the given source based on the configuration
      Parameters:
      source - the source to map
      Returns:
      the item type
    • getItemSnippets

      protected List<String> getItemSnippets(Map<String,List<String>> highlights)
      Maps the OpenSearch highlighting to simple text snippets
      Parameters:
      highlights - the highlighting to map
      Returns:
      the list of snippets
    • getMimeType

      protected String getMimeType(Map<String,Object> source)
      Finds the mime type for the given item
      Parameters:
      source - the item to map
      Returns:
      the mime type