use of com.day.cq.search.SimpleSearch in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImpl method populateSearchListItems.
private void populateSearchListItems() {
listItems = new ArrayList<>();
if (!StringUtils.isBlank(query)) {
SimpleSearch search = resource.adaptTo(SimpleSearch.class);
if (search != null) {
search.setQuery(query);
search.setSearchIn(startIn);
search.addPredicate(new Predicate("type", "type").set("type", NameConstants.NT_PAGE));
search.setHitsPerPage(limit);
try {
collectSearchResults(search.getResult());
} catch (RepositoryException e) {
LOGGER.error("Unable to retrieve search results for query.", e);
}
}
}
}
use of com.day.cq.search.SimpleSearch in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImplTest method testSearchListType.
@Test
protected void testSearchListType() throws Exception {
Session mockSession = mock(Session.class);
SimpleSearch mockSimpleSearch = mock(SimpleSearch.class);
context.registerAdapter(ResourceResolver.class, Session.class, mockSession);
context.registerAdapter(Resource.class, SimpleSearch.class, mockSimpleSearch);
SearchResult searchResult = mock(SearchResult.class);
when(mockSimpleSearch.getResult()).thenReturn(searchResult);
when(searchResult.getResources()).thenReturn(Collections.singletonList(Objects.requireNonNull(context.resourceResolver().getResource("/content/list/pages/page_1/jcr:content"))).iterator());
List list = getListUnderTest(LIST_6);
checkListConsistencyByPaths(list, new String[] { "/content/list/pages/page_1" });
Utils.testJSONExport(list, Utils.getTestExporterJSONPath(testBase, LIST_6));
}
use of com.day.cq.search.SimpleSearch in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImpl method getSearchListItems.
/**
* Get the list items if using the search source type.
*
* @return The search list items.
*/
private Stream<Page> getSearchListItems() {
Optional<Page> searchRoot = getRootPage(PN_SEARCH_IN);
String query = properties.get(PN_SEARCH_QUERY, String.class);
if (!StringUtils.isBlank(query) && searchRoot.isPresent()) {
SimpleSearch search = resource.adaptTo(SimpleSearch.class);
if (search != null) {
search.setQuery(query);
search.setSearchIn(searchRoot.get().getPath());
search.addPredicate(new Predicate("type", "type").set("type", NameConstants.NT_PAGE));
int limit = properties.get(PN_SEARCH_LIMIT, SEARCH_LIMIT_DEFAULT);
search.setHitsPerPage(limit);
return safeGetSearchResult(search).map(SearchResult::getResources).map(it -> (Iterable<Resource>) () -> it).map(it -> StreamSupport.stream(it.spliterator(), false)).orElseGet(Stream::empty).filter(Objects::nonNull).map(currentPage.getPageManager()::getContainingPage).filter(Objects::nonNull);
}
}
return Stream.empty();
}
Aggregations