使用Maven工程创建Sorl项目

来源:互联网 发布:武侠巨人网络 编辑:程序博客网 时间:2024/04/27 19:16

Maven 配置  :

   

<dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.10</version><scope>test</scope></dependency><dependency><groupId>org.apache.solr</groupId><artifactId>solr-solrj</artifactId><version>4.8.1</version><scope>compile</scope></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.7</version></dependency><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.9</version><scope>compile</scope></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.8</version></dependency><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.1.3</version></dependency></dependencies>


    连接Solr 并且插入数据

   

public class App {public static void main(String[] args) throws SolrServerException,IOException {String baseURL = "http://127.0.0.1:8080/collection1";SolrServer server = new HttpSolrServer(baseURL);SolrInputDocument doc = new SolrInputDocument();doc.addField("name", "我爱中国");doc.addField("addr", "中关村大街");doc.addField("manu", "汉语");doc.addField("cat", "cat is cat dog horse");doc.addField("lei", "cat is cat dog horse");doc.addField("id", "2001");server.add(doc);server.commit();}}


0 0