Class SearchServiceInternalImpl
- java.lang.Object
-
- org.craftercms.studio.impl.v2.service.search.internal.SearchServiceInternalImpl
-
- All Implemented Interfaces:
SearchServiceInternal
public class SearchServiceInternalImpl extends Object implements SearchServiceInternal
Default implementation ofSearchServiceInternal
- Author:
- joseross
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_KEY_FACET_DATE
static String
CONFIG_KEY_FACET_MULTIPLE
static String
CONFIG_KEY_FACET_RANGE_FROM
static String
CONFIG_KEY_FACET_RANGE_LABEL
static String
CONFIG_KEY_FACET_RANGE_TO
static String
CONFIG_KEY_FACET_RANGES
static String
CONFIG_KEY_FACETS
static String
CONFIG_KEY_FIELD
static String
CONFIG_KEY_FIELD_BOOST
static String
CONFIG_KEY_FIELDS
static String
CONFIG_KEY_NAME
static String
CONFIG_KEY_TYPE_MATCHES
static String
CONFIG_KEY_TYPES
static String
DEFAULT_MIME_TYPE
protected String
defaultType
Default label used for unknown file typesprotected PermissionAwareSearchService
elasticsearchService
The Elasticsearch servicestatic Pattern
EXACT_MATCH_PATTERN
static String
FACET_RANGE_MAX
static String
FACET_RANGE_MIN
protected Map<String,FacetTO>
facets
Configurations for facetsprotected String[]
highlightFields
List of fields to include during highlightingprotected String
internalNameFieldName
Name of the field for internal nameprotected String
lastEditFieldName
Name of the field for last edit dateprotected String
lastEditorFieldName
Name of the field for last edit userstatic int
MAX_RESULT_WINDOW
Corresponds to 'index.max_result_window' default valueprotected String
mimeTypeName
Name of the field for mimeTypeprotected int
numberOfSnippets
Number of snippets to generate for each filestatic Pattern
PATH_MATCH_PATTERN
protected String
pathFieldName
Name of the field for pathsprotected Map<String,String>
searchFields
List of fields to include during searchingprotected ServicesConfig
servicesConfig
The site configurationprotected String
sizeFieldName
Name of the field for sizeprotected int
snippetSize
Number of characters to include for snippetsprotected StudioConfiguration
studioConfiguration
The Studio configurationprotected Map<String,org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>>
types
Configurations for types
-
Constructor Summary
Constructors Constructor Description SearchServiceInternalImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
addBoosting(String field, float boosting)
protected void
buildAggregations(co.elastic.clients.elasticsearch.core.SearchRequest.Builder builder, Map<String,FacetTO> siteFacets)
Adds the aggregations needed to the given builderprotected List<String>
getItemSnippets(Map<String,List<String>> highlights)
Maps the Elasticsearch highlighting to simple text snippetsprotected String
getItemType(Map<String,Object> source)
Maps the item type for the given source based on the configurationprotected String
getMimeType(Map<String,Object> source)
Finds the mime type for the given itemprotected String
getSortFieldName(String name)
Maps the field name from the configured facets, if it's not found returns the same value.void
init()
Loads facets and type mapping from the global configurationprotected void
loadFacetsFromGlobalConfiguration()
Loads the facets from the global configurationprotected void
loadFieldsFromGlobalConfiguration()
protected void
loadTypesFromGlobalConfiguration()
Loads the type mapping from the global configurationprotected SearchResult
processResults(co.elastic.clients.elasticsearch.core.SearchResponse<Map> response, Map<String,FacetTO> siteFacets, List<String> additionalFields)
Maps the ElasticsearchSearchResponse
to aSearchResult
objectprotected SearchResultItem
processSearchHit(Map<String,Object> source, Map<String,List<String>> highlights, List<String> additionalFields)
Maps the information from Elasticsearch for a singleSearchResultItem
SearchResult
search(String siteId, List<String> allowedPaths, SearchParams params)
Performs a search operation for a given sitevoid
setDefaultType(String defaultType)
void
setElasticsearchService(PermissionAwareSearchService elasticsearchService)
void
setHighlightFields(String[] highlightFields)
void
setInternalNameFieldName(String internalNameFieldName)
void
setLastEditFieldName(String lastEditFieldName)
void
setLastEditorFieldName(String lastEditorFieldName)
void
setMimeTypeName(String mimeTypeName)
void
setNumberOfSnippets(int numberOfSnippets)
void
setPathFieldName(String pathFieldName)
void
setServicesConfig(ServicesConfig servicesConfig)
void
setSizeFieldName(String sizeFieldName)
void
setSnippetSize(int snippetSize)
void
setStudioConfiguration(StudioConfiguration studioConfiguration)
protected void
updateFilters(co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery.Builder query, SearchParams params, Map<String,FacetTO> siteFacets)
Adds the required filters based on the given parametersprotected void
updateHighlighting(co.elastic.clients.elasticsearch.core.SearchRequest.Builder builder)
Adds the configured highlighting to the given builder
-
-
-
Field Detail
-
CONFIG_KEY_FIELDS
public static final String CONFIG_KEY_FIELDS
- See Also:
- Constant Field Values
-
CONFIG_KEY_FACETS
public static final String CONFIG_KEY_FACETS
- See Also:
- Constant Field Values
-
CONFIG_KEY_TYPES
public static final String CONFIG_KEY_TYPES
- See Also:
- Constant Field Values
-
CONFIG_KEY_NAME
public static final String CONFIG_KEY_NAME
- See Also:
- Constant Field Values
-
CONFIG_KEY_FIELD
public static final String CONFIG_KEY_FIELD
- See Also:
- Constant Field Values
-
CONFIG_KEY_FACET_DATE
public static final String CONFIG_KEY_FACET_DATE
- See Also:
- Constant Field Values
-
CONFIG_KEY_FACET_MULTIPLE
public static final String CONFIG_KEY_FACET_MULTIPLE
- See Also:
- Constant Field Values
-
CONFIG_KEY_FACET_RANGES
public static final String CONFIG_KEY_FACET_RANGES
- See Also:
- Constant Field Values
-
CONFIG_KEY_FACET_RANGE_LABEL
public static final String CONFIG_KEY_FACET_RANGE_LABEL
- See Also:
- Constant Field Values
-
CONFIG_KEY_FACET_RANGE_FROM
public static final String CONFIG_KEY_FACET_RANGE_FROM
- See Also:
- Constant Field Values
-
CONFIG_KEY_FACET_RANGE_TO
public static final String CONFIG_KEY_FACET_RANGE_TO
- See Also:
- Constant Field Values
-
CONFIG_KEY_TYPE_MATCHES
public static final String CONFIG_KEY_TYPE_MATCHES
- See Also:
- Constant Field Values
-
CONFIG_KEY_FIELD_BOOST
public static final String CONFIG_KEY_FIELD_BOOST
- See Also:
- Constant Field Values
-
FACET_RANGE_MIN
public static final String FACET_RANGE_MIN
- See Also:
- Constant Field Values
-
FACET_RANGE_MAX
public static final String FACET_RANGE_MAX
- See Also:
- Constant Field Values
-
DEFAULT_MIME_TYPE
public static final String DEFAULT_MIME_TYPE
- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
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
-
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
-
elasticsearchService
protected PermissionAwareSearchService elasticsearchService
The Elasticsearch service
-
studioConfiguration
protected StudioConfiguration studioConfiguration
The Studio configuration
-
servicesConfig
protected ServicesConfig servicesConfig
The site configuration
-
-
Method Detail
-
setPathFieldName
public void setPathFieldName(String pathFieldName)
-
setInternalNameFieldName
public void setInternalNameFieldName(String internalNameFieldName)
-
setLastEditFieldName
public void setLastEditFieldName(String lastEditFieldName)
-
setLastEditorFieldName
public void setLastEditorFieldName(String lastEditorFieldName)
-
setSizeFieldName
public void setSizeFieldName(String sizeFieldName)
-
setMimeTypeName
public void setMimeTypeName(String mimeTypeName)
-
setDefaultType
public void setDefaultType(String defaultType)
-
setHighlightFields
public void setHighlightFields(String[] highlightFields)
-
setSnippetSize
public void setSnippetSize(int snippetSize)
-
setNumberOfSnippets
public void setNumberOfSnippets(int numberOfSnippets)
-
setElasticsearchService
public void setElasticsearchService(PermissionAwareSearchService elasticsearchService)
-
setStudioConfiguration
public void setStudioConfiguration(StudioConfiguration studioConfiguration)
-
setServicesConfig
public void setServicesConfig(ServicesConfig servicesConfig)
-
init
public void init()
Loads facets and type mapping from the global configuration
-
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 Elasticsearch for a singleSearchResultItem
- Parameters:
source
- the fields returned by Elasticsearchhighlights
- the highlights returned by Elasticsearch- Returns:
- the search item object
-
updateFilters
protected void updateFilters(co.elastic.clients.elasticsearch._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(co.elastic.clients.elasticsearch.core.SearchRequest.Builder builder)
Adds the configured highlighting to the given builder- Parameters:
builder
- the search builder to update
-
processResults
protected SearchResult processResults(co.elastic.clients.elasticsearch.core.SearchResponse<Map> response, Map<String,FacetTO> siteFacets, List<String> additionalFields)
Maps the ElasticsearchSearchResponse
to aSearchResult
object- Parameters:
response
- the response to map- Returns:
- the search result object
-
search
public SearchResult search(String siteId, List<String> allowedPaths, SearchParams params) throws ServiceLayerException
Performs a search operation for a given site- Specified by:
search
in interfaceSearchServiceInternal
- Parameters:
siteId
- the site idallowedPaths
- list of paths that should be included in the resultsparams
- the search parameters- Returns:
- the search results
- Throws:
ServiceLayerException
- if there is any error executing the search in Elasticsearch
-
buildAggregations
protected void buildAggregations(co.elastic.clients.elasticsearch.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
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 Elasticsearch highlighting to simple text snippets- Parameters:
highlights
- the highlighting to map- Returns:
- the list of snippets
-
-