Package com.mindstore.backend.controller
Class SearchController
java.lang.Object
com.mindstore.backend.controller.SearchController
REST controller for searches within text-index
-
Constructor Summary
ConstructorsConstructorDescriptionSearchController(TextSearchService textSearchService, SearchHistoryService searchHistoryService) search controller constructor -
Method Summary
Modifier and TypeMethodDescriptionautocompleteString(String prefix) function: endpoint for autocompletion within searchgetSearchHistory(Principal principal) function: get the recent searches that were made by the userCategory[]function: used to get all the available values the CATEGORY enum can haveSearches through all availableTextDocuments based on the query parameter.searchCommandList(String command, int page, int size, String searchAfter, Principal principal) Searches through all availableTextDocuments based on the query parameter.searchHighlighted(String query, int page, int size, String searchAfter, Principal principal) Searches through all availableTextDocuments based on the query parameter.searchThroughTags(String query, int page, int size, String searchAfter, List<String> tags, Principal principal) function: search controller endpoint for search inside tagged textssearchThroughTime(String query, int page, int size, String searchAfter, String dateFrom, String dateTo, Principal principal) Searches through all availableTextDocuments based on the query parameter.org.springframework.http.ResponseEntity<String> test()function: used to test the SearchController and debugging
-
Constructor Details
-
SearchController
public SearchController(TextSearchService textSearchService, SearchHistoryService searchHistoryService) search controller constructor- Parameters:
textSearchService- service class for search functionssearchHistoryService- service class or search history functions
-
-
Method Details
-
search
@GetMapping public SearchResultDto<TextDocument> search(@RequestParam String query, @RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size, @RequestParam(defaultValue="") String searchAfter, Principal principal) Searches through all availableTextDocuments based on the query parameter. Results are paginated and returned in aSearchResultDto. Additionally, the query is saved to the search history.- Parameters:
query- the search term entered by the userpage- the zero-based page index for pagination (default is 0)size- the number of items per page (default is 10)searchAfter- the string for the next search pageprincipal- the currently authenticated user (used for audit or filtering if needed)- Returns:
- a
SearchResultDtocontaining the paginated list of matchingTextDocuments
-
searchThroughTags
@GetMapping("/tag-search") public SearchResultDto<TextDocument> searchThroughTags(@RequestParam String query, @RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size, @RequestParam(defaultValue="") String searchAfter, @RequestParam List<String> tags, Principal principal) function: search controller endpoint for search inside tagged texts- Parameters:
query- the search term entered by the userpage- the zero-based page index for pagination (default is 0)size- the number of items per page (default is 10)searchAfter- the string for the next search pagetags- the tags that we filter the texts withprincipal- the currently authenticated user (used for audit or filtering if needed)- Returns:
- a
SearchResultDtocontaining the paginated list of matchingTextDocuments
-
autocompleteString
@GetMapping("/autocomplete") public List<String> autocompleteString(@RequestParam String prefix) throws IOException function: endpoint for autocompletion within search- Parameters:
prefix- - string we are searching for, for example "do" will suggest "docker"- Returns:
- List of strings that match query
- Throws:
IOException- when search fails
-
test
function: used to test the SearchController and debugging- Returns:
- ok ---> if successfull
-
getSearchHistory
@GetMapping("/history") public org.springframework.http.ResponseEntity<List<String>> getSearchHistory(Principal principal) function: get the recent searches that were made by the user- Parameters:
principal- the currently authenticated user- Returns:
- a List of strings with the searches
-
getTagList
function: used to get all the available values the CATEGORY enum can have- Returns:
- Array of Category enum
-
searchThroughTime
@GetMapping("/time") public SearchResultDto<TextDocument> searchThroughTime(@RequestParam String query, @RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size, @RequestParam(defaultValue="") String searchAfter, @RequestParam(required=false) String dateFrom, @RequestParam(required=false) String dateTo, Principal principal) Searches through all availableTextDocuments based on the query parameter. Results are paginated and returned in aSearchResultDto. Additionally, the query is saved to the search history.- Parameters:
query- the search term entered by the userpage- the zero-based page index for pagination (default is 0)size- the number of items per page (default is 10)searchAfter- the string for the next search pagedateFrom- the date we are querying fromdateTo- the date we are querying toprincipal- the currently authenticated user (used for audit or filtering if needed)- Returns:
- a
SearchResultDtocontaining the paginated list of matchingTextDocuments
-
searchCommandList
@GetMapping("/command-search") public SearchResultDto<TextDocument> searchCommandList(@RequestParam String command, @RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size, @RequestParam(defaultValue="") String searchAfter, Principal principal) Searches through all availableTextDocuments based on the query parameter. Results are paginated and returned in aSearchResultDto. Additionally, the query is saved to the search history.- Parameters:
command- the command entered by the userpage- the zero-based page index for pagination (default is 0)size- the number of items per page (default is 10)searchAfter- the string for the next search pageprincipal- the currently authenticated user (used for audit or filtering if needed)- Returns:
- a
SearchResultDtocontaining the paginated list of matchingTextDocuments
-
searchHighlighted
@GetMapping("/highlight") public SearchResultDto<SearchHitDto<TextDocument>> searchHighlighted(@RequestParam String query, @RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size, @RequestParam(defaultValue="") String searchAfter, Principal principal) Searches through all availableTextDocuments based on the query parameter. Results are paginated and returned in aSearchResultDto. Additionally, the query is saved to the search history.- Parameters:
query- the search term entered by the userpage- the zero-based page index for pagination (default is 0)size- the number of items per page (default is 10)searchAfter- the string for the next search pageprincipal- the currently authenticated user (used for audit or filtering if needed)- Returns:
- a
SearchResultDtocontaining the paginated list of matchingTextDocuments and a section of highlighted results
-