@Override public List<SearchResult> search( final SessionIdentifier sessionIdentifier, final String query, final int maxResults) { // search in one component { final int pos = query.indexOf(':'); if (pos != -1) { final String name = query.substring(0, pos); final SearchServiceComponent search = searchServiceComponentRegistry.get(name); if (search != null) { final List<SearchServiceComponent> searchServiceComponents = Arrays.asList(search); return search( searchServiceComponents, query.substring(pos + 1).trim(), sessionIdentifier, maxResults); } } } final List<SearchServiceComponent> searchServiceComponents = new ArrayList<SearchServiceComponent>(searchServiceComponentRegistry.getAll()); logger.trace("searchServiceComponents " + searchServiceComponents.size()); return search(searchServiceComponents, query, sessionIdentifier, maxResults); }
@Override public List<String> getSearchComponentNames() { final List<String> result = new ArrayList<String>(); for (final SearchServiceComponent cs : searchServiceComponentRegistry.getAll()) { result.add(cs.getClass().getName()); } return result; }
@Test public void testSearchSpecial() throws Exception { final Logger logger = EasyMock.createNiceMock(Logger.class); EasyMock.replay(logger); final SessionIdentifier sessionIdentifier = new SessionIdentifier("sessionId"); final int maxResults = 1337; final SearchQueryHistoryDao searchQueryHistoryDao = null; final IdGeneratorUUID idGeneratorUUID = null; final List<SearchResult> list = Arrays.asList(); final SearchServiceComponent searchServiceComponent = EasyMock.createMock(SearchServiceComponent.class); EasyMock.expect(searchServiceComponent.search(sessionIdentifier, "bar", maxResults)) .andReturn(list); EasyMock.replay(searchServiceComponent); final SearchServiceComponentRegistry searchServiceComponentRegistry = EasyMock.createNiceMock(SearchServiceComponentRegistry.class); EasyMock.expect(searchServiceComponentRegistry.get("foo")).andReturn(searchServiceComponent); EasyMock.replay(searchServiceComponentRegistry); final ThreadRunner threadRunner = new ThreadRunnerMock(); final SearchServiceSearchResultComparator searchServiceComponentComparator = null; final AuthenticationService authenticationService = EasyMock.createNiceMock(AuthenticationService.class); EasyMock.expect(authenticationService.getCurrentUser(sessionIdentifier)).andReturn(null); EasyMock.replay(authenticationService); final SearchService searchService = new SearchServiceImpl( logger, authenticationService, searchQueryHistoryDao, idGeneratorUUID, searchServiceComponentRegistry, threadRunner, searchServiceComponentComparator); searchService.search(sessionIdentifier, "foo: bar", maxResults); EasyMock.verify(searchServiceComponentRegistry, searchServiceComponent); }