solr SolrServer
来源:互联网 发布:网络直播公司简介 编辑:程序博客网 时间:2024/06/06 03:46
package com.su.search.client;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Date;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
/**
* Description:
* @author LiChunming
* @version V1.0
* @createDateTime:2012-2-27 下午03:49:04
* @Company: MSD.
* @Copyright: Copyright (c) 2011
**/
public class SolrServer {
private static SolrServer solrServer = null;
private static HttpSolrServer server=null;
private static String url="http://localhost:8080/solr/core0";
public static synchronized SolrServer getInstance() {
if (solrServer==null){
solrServer=new SolrServer();
}
return solrServer;
}
public static HttpSolrServer getServer(){
if(server==null){
server = new HttpSolrServer(url);
server.setSoTimeout(1000); // socket read timeout
server.setConnectionTimeout(1000);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false); // defaults to false
//allowCompression defaults to false.
//Server side must support gzip or deflate for this to have any effect.
server.setAllowCompression(true);
server.setMaxRetries(1); // defaults to 0. > 1 not recommended.
}
return server;
}
public static void main(String[] args) {
HttpSolrServer solrServer= SolrServer.getInstance().getServer();
SolrInputDocument doc1 = insert("b", "http:vvvvvyyvvs", "b", "b", "b", "b", "b", "b", "b", new Date(), "site");
try {
solrServer.add(doc1);
} catch (SolrServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
solrServer.commit();
} catch (SolrServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static SolrInputDocument insert(String user, String link, String title,
String desc, String content, String tags, String keywords,
String site, String type, Date date, String name) {
// SitesIndexDTO sitesIndex = new SitesIndexDTO();
SolrInputDocument doc = new SolrInputDocument();
if (link != null && !"".equals(link)) {
doc.addField("link", link);
}
if (title != null && !"".equals(title)) {
doc.addField("title", title);
}
if (keywords != null && !"".equals(keywords)) {
doc.addField("keywords", keywords);
}
if (desc != null && !"".equals(desc)) {
doc.addField("desc", desc);
}
if (content != null && !"".equals(content)) {
doc.addField("content", content);
}
if (tags != null && !"".equals(tags)) {
doc.addField("tags", tags);
}
doc.addField("source", "admin");
if (site != null && !"".equals(site)) {
doc.addField("site", site);
}
if (type != null && !"".equals(type)) {
doc.addField("type", type);
}
if (date != null && !"".equals(date)) {
doc.addField("last_modified",
DateFormatUtils.format(date, "yyyy-MM-dd'T'HH:mm:ss'Z'"));
}
return doc;
}
}
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Date;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
/**
* Description:
* @author LiChunming
* @version V1.0
* @createDateTime:2012-2-27 下午03:49:04
* @Company: MSD.
* @Copyright: Copyright (c) 2011
**/
public class SolrServer {
private static SolrServer solrServer = null;
private static HttpSolrServer server=null;
private static String url="http://localhost:8080/solr/core0";
public static synchronized SolrServer getInstance() {
if (solrServer==null){
solrServer=new SolrServer();
}
return solrServer;
}
public static HttpSolrServer getServer(){
if(server==null){
server = new HttpSolrServer(url);
server.setSoTimeout(1000); // socket read timeout
server.setConnectionTimeout(1000);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false); // defaults to false
//allowCompression defaults to false.
//Server side must support gzip or deflate for this to have any effect.
server.setAllowCompression(true);
server.setMaxRetries(1); // defaults to 0. > 1 not recommended.
}
return server;
}
public static void main(String[] args) {
HttpSolrServer solrServer= SolrServer.getInstance().getServer();
SolrInputDocument doc1 = insert("b", "http:vvvvvyyvvs", "b", "b", "b", "b", "b", "b", "b", new Date(), "site");
try {
solrServer.add(doc1);
} catch (SolrServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
solrServer.commit();
} catch (SolrServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static SolrInputDocument insert(String user, String link, String title,
String desc, String content, String tags, String keywords,
String site, String type, Date date, String name) {
// SitesIndexDTO sitesIndex = new SitesIndexDTO();
SolrInputDocument doc = new SolrInputDocument();
if (link != null && !"".equals(link)) {
doc.addField("link", link);
}
if (title != null && !"".equals(title)) {
doc.addField("title", title);
}
if (keywords != null && !"".equals(keywords)) {
doc.addField("keywords", keywords);
}
if (desc != null && !"".equals(desc)) {
doc.addField("desc", desc);
}
if (content != null && !"".equals(content)) {
doc.addField("content", content);
}
if (tags != null && !"".equals(tags)) {
doc.addField("tags", tags);
}
doc.addField("source", "admin");
if (site != null && !"".equals(site)) {
doc.addField("site", site);
}
if (type != null && !"".equals(type)) {
doc.addField("type", type);
}
if (date != null && !"".equals(date)) {
doc.addField("last_modified",
DateFormatUtils.format(date, "yyyy-MM-dd'T'HH:mm:ss'Z'"));
}
return doc;
}
}
0 0
- solr SolrServer
- Solr笔记五之SolrServer
- solr入门之SolrServer实例化方式
- Solr入门之SolrServer实例化方式
- Solr入门之SolrServer实例化方式
- Solr入门之SolrServer实例化方式
- Solr入门之SolrServer实例化方式
- SolrServer源码
- solrserver实例化
- 10018---solrserver Extension
- solrj 查询SolrServer的一般流程
- Solr
- solr
- solr
- solr
- solr
- solr
- Solr
- 用算法求N(N>=3)之内素数的个数
- Unity AssetBundle爬坑手记
- MySQL Migration Toolkit的使用
- AsyncTasLoader不进行加载操作的原因及解决方法
- 下列函数的结果
- solr SolrServer
- 在Mac OS平台使用VNC连接树莓派
- 杂碎的编程体会
- 博文汇总
- Ubuntu14.04下ise14.4出错:error while running "gmake –f ***** "
- Linux进程调度
- WebStorm中配置浏览器方法
- 删除无序数组中跳跃重复值并排序(时间复杂度为O(n))
- JAVA static{}静态代码块 和 {}