/** * 添加索引 */ public static void AddIndexes() { HttpSolrServer server = new HttpSolrServer("http://localhost:8081/solr"); SolrInputDocument doc1 = new SolrInputDocument(); doc1.addField("id", "1"); doc1.addField("title", "云南xxx科技"); doc1.addField("cat", "企业信息门户,元数据,数字沙盘,知识管理"); SolrInputDocument doc2 = new SolrInputDocument(); doc2.addField("id", "2"); doc2.addField("title", "胡启稳"); doc2.addField("cat", "知识管理,企业信息门户,云南,昆明"); SolrInputDocument doc3 = new SolrInputDocument(); doc3.addField("id", "3"); doc3.addField("title", "liferay"); doc3.addField("cat", "知识管理2,企业信息门户2,云南2,昆明2"); // doc3.addField("test_s", "这个内容能添加进去么?这是动态字段呀"); Listdocs = new ArrayList (); docs.add(doc1); docs.add(doc2); docs.add(doc3); try { server.setParser(new XMLResponseParser()); server.add(docs); for (SolrInputDocument doc : docs) { System.out.println(doc); } server.commit(); System.out.println("添加索引成功......"); } catch (Exception e) { e.printStackTrace(); } }
结果图: