SolrController { @RequestMapping("/queryAll") public Object queryAll() throws IOException, SolrServerException { SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("*:*"); solrQuery.set("q", "知然"); solrQuery.add("q", "name:然"); solrQuery.setSort("id", SolrQuery.ORDER.asc); solrQuery.setRows(50); solrQuery.setStart(0); solrQuery.setStart(0); solrQuery.setRows(20); solrQuery.setHighlight(true); solrQuery.addHighlightField("name"); solrQuery.setHighlightSimplePre("<font color='red'>"); solrQuery.setHighlightSimplePost("</font>"); System.out.println(solrQuery); QueryResponse response = solrClient.query(solrQuery); Map<String, Map<String, List<String>>> highlighting = response.getHighlighting(); SolrDocumentList documentList = response.getResults(); long numFound = documentList.getNumFound(); System.out.println("总共查询到的文档数量： " + numFound); for (SolrDocument solrDocument : documentList) { System.out.println("solrDocument==============" + solrDocument); System.out.println("solrDocument==============" + solrDocument.get("name")); } return highlighting; }  @RequestMapping("/addUsers") void addUsers(); @RequestMapping("/addUser") void addUser(); @RequestMapping("/getById/{id}") String getByIdFromSolr(@PathVariable("id") String id); @RequestMapping("/updateUser") void updateUser(); @RequestMapping("/delById/{id}") String delById(@PathVariable("id") String id); @RequestMapping("/delAll") void delAll(); @RequestMapping("/queryAllOne") String queryAllOne(); @RequestMapping("/queryAll") Object queryAll();  }
@Test public void queryAll() throws IOException, SolrServerException { SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("*:*"); solrQuery.set("q", "知然"); solrQuery.add("q", "name:然"); solrQuery.setSort("id", SolrQuery.ORDER.asc); solrQuery.setRows(50); solrQuery.setStart(0); solrQuery.setStart(0); solrQuery.setRows(20); solrQuery.setHighlight(true); solrQuery.addHighlightField("name"); solrQuery.setHighlightSimplePre("<font color='red'>"); solrQuery.setHighlightSimplePost("</font>"); System.out.println(solrQuery); QueryResponse response = solrClient.query(solrQuery); Map<String, Map<String, List<String>>> highlighting = response.getHighlighting(); SolrDocumentList documentList = response.getResults(); long numFound = documentList.getNumFound(); System.out.println("总共查询到的文档数量： " + numFound); for (SolrDocument solrDocument : documentList) { System.out.println(solrDocument); System.out.println(solrDocument.get("name")); } System.out.println(highlighting); }