1. Maven pom.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2. log4j.xml
filepattern="${logPath}/%d{YYYYMMddHHmmss}-fargo.log">
3. 测试类(SolrJ的添加索引为例)
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrInputDocument;
import java.io.IOException;
import java.util.UUID;
public class Main {
public static void main(String[] args)throws IOException, SolrServerException {
System.out.println("Hello Solr...");
String urlString ="http://localhost:8983/solr/core1";
SolrClient solrClient =new HttpSolrClient.Builder(urlString).build();
System.out.println("INFO: Insert a document into Solr...");
SolrInputDocument doc =new SolrInputDocument();
doc.addField("id","8");
doc.addField("COMPANY","ebay");
doc.addField("LOCATION","Silicon Vally(硅谷)");
doc.addField("DESC-CO","ebay是一个与Amazon相似的电商网站,类似中国的阿里巴巴。开发Java,Web应用是很有必要的。");
doc.addField("uuid",UUID.randomUUID().toString());
solrClient.add(doc);
solrClient.commit();// periodically flush
System.out.println("INFO: Insert the document into Solr Successfully");
}
}
4. 备注
Solr里面设置了uuid为唯一键。