Class SearchServiceInternalImpl
java.lang.Object
org.craftercms.studio.impl.v2.service.search.internal.SearchServiceInternalImpl
- All Implemented Interfaces:
SearchService
Internal implementation of
SearchService- Author:
- joseross
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected StringDefault label used for unknown file typesstatic final Patternstatic final Stringstatic final StringConfigurations for facetsprotected String[]List of fields to include during highlightingprotected StringName of the field for internal nameprotected StringName of the field for last edit dateprotected StringName of the field for last edit userstatic final intCorresponds to 'index.max_result_window' default valueprotected StringName of the field for mimeTypeprotected intNumber of snippets to generate for each filestatic final Patternprotected StringName of the field for pathsList of fields to include during searchingprotected final PermissionAwareSearchServiceThe Search serviceprotected final ServicesConfigThe site configurationprotected StringName of the field for sizeprotected intNumber of characters to include for snippetsprotected final StudioConfigurationThe Studio configurationprotected Map<String, org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>> Configurations for typesFields inherited from interface org.craftercms.studio.api.v2.service.search.SearchService
DEFAULT_MAX_EXPANSIONS -
Constructor Summary
ConstructorsConstructorDescriptionSearchServiceInternalImpl(PermissionAwareSearchService searchService, StudioConfiguration studioConfiguration, ServicesConfig servicesConfig) -
Method Summary
Modifier and TypeMethodDescriptionprotected StringaddBoosting(String field, float boosting) protected voidbuildAggregations(org.opensearch.client.opensearch.core.SearchRequest.Builder builder, Map<String, FacetTO> siteFacets) Adds the aggregations needed to the given buildergetItemSnippets(Map<String, List<String>> highlights) Maps the OpenSearch highlighting to simple text snippetsprotected StringgetItemType(Map<String, Object> source) Maps the item type for the given source based on the configurationprotected StringgetMimeType(Map<String, Object> source) Finds the mime type for the given itemprotected StringgetSortFieldName(String name) Maps the field name from the configured facets, if it's not found returns the same value.voidinit()Loads facets and type mapping from the global configurationprotected voidLoads the facets from the global configurationprotected voidprotected voidLoads the type mapping from the global configurationprotected SearchResultprocessResults(org.opensearch.client.opensearch.core.SearchResponse<Map> response, Map<String, FacetTO> siteFacets, List<String> additionalFields) Maps the OpenSearchSearchResponseto aSearchResultobjectprotected SearchResultItemprocessSearchHit(Map<String, Object> source, Map<String, List<String>> highlights, List<String> additionalFields) Maps the information from OpenSearch for a singleSearchResultItemsearch(String siteId, SearchParams params, int maxExpansions) Performs a search operation for a given siteprotected voidupdateFilters(org.opensearch.client.opensearch._types.query_dsl.BoolQuery.Builder query, SearchParams params, Map<String, FacetTO> siteFacets) Adds the required filters based on the given parametersprotected voidupdateHighlighting(org.opensearch.client.opensearch.core.SearchRequest.Builder builder) Adds the configured highlighting to the given builderMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.craftercms.studio.api.v2.service.search.SearchService
search
-
Field Details
-
CONFIG_KEY_FIELDS
- See Also:
-
CONFIG_KEY_FACETS
- See Also:
-
CONFIG_KEY_TYPES
- See Also:
-
CONFIG_KEY_NAME
- See Also:
-
CONFIG_KEY_FIELD
- See Also:
-
CONFIG_KEY_FACET_DATE
- See Also:
-
CONFIG_KEY_FACET_MULTIPLE
- See Also:
-
CONFIG_KEY_FACET_RANGES
- See Also:
-
CONFIG_KEY_FACET_RANGE_LABEL
- See Also:
-
CONFIG_KEY_FACET_RANGE_FROM
- See Also:
-
CONFIG_KEY_FACET_RANGE_TO
- See Also:
-
CONFIG_KEY_TYPE_MATCHES
- See Also:
-
CONFIG_KEY_FIELD_BOOST
- See Also:
-
FACET_RANGE_MIN
- See Also:
-
FACET_RANGE_MAX
- See Also:
-
DEFAULT_MIME_TYPE
- See Also:
-
EXACT_MATCH_PATTERN
-
PATH_MATCH_PATTERN
-
MAX_RESULT_WINDOW
public static final int MAX_RESULT_WINDOWCorresponds to 'index.max_result_window' default value- See Also:
-
pathFieldName
Name of the field for paths -
internalNameFieldName
Name of the field for internal name -
lastEditFieldName
Name of the field for last edit date -
lastEditorFieldName
Name of the field for last edit user -
sizeFieldName
Name of the field for size -
mimeTypeName
Name of the field for mimeType -
searchFields
List of fields to include during searching -
highlightFields
List of fields to include during highlighting -
snippetSize
protected int snippetSizeNumber of characters to include for snippets -
numberOfSnippets
protected int numberOfSnippetsNumber of snippets to generate for each file -
defaultType
Default label used for unknown file types -
searchService
The Search service -
studioConfiguration
The Studio configuration -
servicesConfig
The site configuration -
facets
Configurations for facets -
types
protected Map<String,org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>> typesConfigurations for types
-
-
Constructor Details
-
SearchServiceInternalImpl
@ConstructorProperties({"searchService","studioConfiguration","servicesConfig"}) public SearchServiceInternalImpl(PermissionAwareSearchService searchService, StudioConfiguration studioConfiguration, ServicesConfig servicesConfig)
-
-
Method Details
-
init
public void init()Loads facets and type mapping from the global configuration -
addBoosting
-
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 singleSearchResultItem- Parameters:
source- the fields returned by OpenSearchhighlights- 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 updateparams- the parameters to addsiteFacets- 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 OpenSearchSearchResponseto aSearchResultobject- 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:
searchin interfaceSearchService- Parameters:
siteId- the id of the siteparams- the parameters for the searchmaxExpansions- 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 buildersiteFacets- the facets from the site configuration
-
getSortFieldName
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
Maps the item type for the given source based on the configuration- Parameters:
source- the source to map- Returns:
- the item type
-
getItemSnippets
Maps the OpenSearch highlighting to simple text snippets- Parameters:
highlights- the highlighting to map- Returns:
- the list of snippets
-
getMimeType
Finds the mime type for the given item- Parameters:
source- the item to map- Returns:
- the mime type
-