Package de.cxp.ocs
Class SearchController
java.lang.Object
de.cxp.ocs.SearchController
- All Implemented Interfaces:
SearchService
@RefreshScope
@CrossOrigin("*")
@RestController
@RequestMapping(path="/search-api/v1")
@EnableScheduling
public class SearchController
extends Object
implements SearchService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionarrangedSearch
(String tenant, ArrangedSearchQuery searchQuery) org.springframework.http.ResponseEntity
<org.springframework.http.HttpStatus> flushConfig
(String tenant) getDocument
(String tenant, String docId) String[]
org.springframework.http.ResponseEntity
<ExceptionResponse> handleInternalErrors
(jakarta.servlet.http.HttpServletRequest request, Exception e) org.springframework.http.ResponseEntity
<ExceptionResponse> org.springframework.http.ResponseEntity
<ExceptionResponse> void
Search the index using the given searchQuery.
-
Constructor Details
-
SearchController
public SearchController()
-
-
Method Details
-
refreshAllConfigs
@Scheduled(fixedDelayString="${ocs.scheduler.refresh-config-delay-ms:60000}") public void refreshAllConfigs() -
flushConfig
@GetMapping("/flushConfig/{tenant}") public org.springframework.http.ResponseEntity<org.springframework.http.HttpStatus> flushConfig(@PathVariable("tenant") String tenant) -
search
@GetMapping("/search/{tenant}") public SearchResult search(@PathVariable("tenant") String tenant, SearchQuery searchQuery, @RequestParam Map<String, String> filters) throws ExceptionDescription copied from interface:SearchService
Search the index using the given searchQuery. Each tenant can have its own configuration. Different tenants may still use the same indexes. This is defined by the underlying configuration.- Specified by:
search
in interfaceSearchService
- Parameters:
tenant
- the name that correlates to the index configurationsearchQuery
- the user's search termsfilters
- Any other parameters are used as filters. They are validated according to the actual data and configuration. Each filter can have multiple values, separated by comma. Commas inside the values have to be double-URL encoded. Depending on the configured backend type these values are used differently. Examples:- brand=adidas
- brand=adidas,nike (products from adidas OR nike are shown)
- category=men,shoes,sneaker (if category would be configured as path, these values are used for hierarchical filtering)
- price=10,99.99 (if price is configured as numeric field, these values are used as range filters)
- color=red,black (if that field is configured to be used for "exclusive filtering" only products would be shown that are available in red AND black)
- optional for the future also negations could be supported, e.g. color=red,!black
- Returns:
- the result of that search request
- Throws:
Exception
-- if tenant can't be accessed
- if according index does not exist
-
arrangedSearch
@PostMapping("/search/arranged/{tenant}") public SearchResult arrangedSearch(@PathVariable("tenant") String tenant, @RequestBody ArrangedSearchQuery searchQuery) throws Exception - Specified by:
arrangedSearch
in interfaceSearchService
- Throws:
Exception
-
getDocument
@GetMapping("/doc/{tenant}/{id}") public Document getDocument(@PathVariable("tenant") String tenant, @PathVariable("id") String docId) throws Exception - Specified by:
getDocument
in interfaceSearchService
- Throws:
Exception
-
getTenants
- Specified by:
getTenants
in interfaceSearchService
-
handleNotFoundException
@ExceptionHandler(NotFoundException.class) public org.springframework.http.ResponseEntity<ExceptionResponse> handleNotFoundException(NotFoundException e) -
handleParameterErrors
@ExceptionHandler(java.lang.IllegalArgumentException.class) public org.springframework.http.ResponseEntity<ExceptionResponse> handleParameterErrors(NotFoundException e) -
handleInternalErrors
@ExceptionHandler({org.elasticsearch.ElasticsearchStatusException.class,java.util.concurrent.ExecutionException.class,java.io.IOException.class,java.io.UncheckedIOException.class,java.lang.RuntimeException.class,java.lang.ClassNotFoundException.class}) public org.springframework.http.ResponseEntity<ExceptionResponse> handleInternalErrors(jakarta.servlet.http.HttpServletRequest request, Exception e)
-