Complete the code to define the main component responsible for handling search queries.
class [1] { public void handleSearch(String query) { // Implementation } }
The class SearchHandler is the main component that handles search queries in this design.
Complete the code to add a method that indexes documents for search.
public class Indexer { public void [1](Document doc) { // Indexing logic } }
The method indexDocument is responsible for adding documents to the search index.
Fix the error in the code that processes search queries asynchronously.
public class AsyncSearchProcessor { public Future<List<Result>> processQuery(String query) { return executorService.[1](() -> { // Search logic return search(query); }); } }
execute which returns void, causing a type mismatch.run or invoke which are not methods of executorService.The submit method returns a Future object, which is needed for asynchronous processing with a result.
Fill both blanks to complete the code for filtering search results by relevance and date.
List<Result> filteredResults = results.stream()
.filter(r -> r.getRelevance() [1] 0.8)
.filter(r -> r.getDate() [2] LocalDate.now().minusDays(30))
.collect(Collectors.toList());The code filters results with relevance greater than or equal to 0.8 and dates within the last 30 days (less than or equal to 30 days ago).
Fill all three blanks to complete the code that builds a search query with filters and sorting.
SearchQuery query = new SearchQuery.Builder()
.setKeyword([1])
.addFilter([2], [3])
.setSortOrder(SortOrder.RELEVANCE)
.build();The keyword is set to "machine learning", the filter is on the "date" field, and the filter value is "last_30_days" to restrict results.
