AEM 6.5使用Solr作为其内置搜索引擎,从而提高搜索性能。可以通过以下步骤来使用AEM 6.5 Solr搜索:
Query query = queryManager.createQuery("SELECT * FROM [nt:base] AS s WHERE CONTAINS(s.*, 'searchTerm')", Query.JCR_SQL2);
SolrServer solr = new HttpSolrServer("http://localhost:8983/solr/collection1");
org.apache.sling.api.SlingHttpServletRequest request = slingHttpServletRequest;
List hits = new ArrayList();
Query query = queryManager.createQuery(
"SELECT * FROM [nt:base] AS s WHERE CONTAINS(s.*, 'searchTerm')",
Query.JCR_SQL2);
query.setStart(startIndex);
query.setLimit(pageSize);
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
Resource hitResource = hit.getResource();
ValueMap properties = hitResource.getValueMap();
// add relevant properties to your hit list
hits.add(hit);
}
// create pagination
Pagination pagination = new Pagination(request.getRequestURI(),
page, sqlService.getHitsPerPage(), result.getTotalMatches());
request.setAttribute("pagination", pagination);
request.setAttribute("hits", hits);