1.httpsolrserver Դ?源码?
2.error from server at solr non ok status 431 message request header file
3.HTTP Status 500 – Internal Server Error 错误原因,怎么改
4.solr group分组排序的源码问题
5.求助:solr如何通过指定条件修改数据
httpsolrserver Դ??
Slor简介
Slor,作为Apache下的源码顶级开源项目,采用Java开发,源码是源码基于Lucene的全文搜索服务器。它提供了比Lucene更为丰富的源码tpl 源码查询语言,同时实现了可配置、源码可扩展,源码并对索引、源码搜索性能进行了优化。源码Slor可以独立运行,源码支持在Jetty、源码Tomcat等Servlet容器中运行。源码离职公司要源码添加、源码删除、源码更新索引可通过POST方法向Slor服务器发送描述Field及其内容的XML文档实现。Slor搜索通过HTTP GET请求完成,解析返回的Xml、json等格式的族谱管理系统 源码查询结果,然后组织页面布局。Slor不提供构建UI的功能,但提供了一个管理界面,通过该界面可以查询Slor的配置和运行状态。
Slor和Lucene的区别
Slor和Lucene的本质区别主要体现在以下三个方面:搜索服务器、企业级应用和管理。asp信息查询源码Lucene是一个专注于搜索底层建设的搜索库,而非独立应用。而Slor是一个独立的搜索服务器。Lucene专注于搜索底层建设,而Slor则专注于企业应用需求。Lucene不负责支撑搜索服务所必需的建材配送app源码管理功能,而Slor则负责这些管理任务。Slor是Lucene面向企业搜索应用的扩展。
Slor安装配置
下载Slor:从Slor官方网站下载,根据运行环境选择。可参考使用指南:wiki.apache.org/solr/Fr...
安装过程:解压下载包,将server\solr-webapp\webapp文件夹复制到Tomcat\webapps目录下,并修改为solr。将server\lib\ext中的jar文件复制到Tomcat\webapps\solr\WEB-INF\lib目录中。
启动服务:运行startup.bat启动服务。
访问管理界面:打开mit();
} catch (SolrServerException e) {
state = 1;
System.out.println("修改solr数据报错");
e.printStackTrace();
} catch (IOException e) {
state = 1;
System.out.println("修改solr数据报错");
e.printStackTrace();
}
return state;
}
删除主方法
public int deletContent(String enterpriseId) {
LBHttpSolrServer server = SolrUtil.getSolrServer(ap.getEnterprisenewSolrUrl());
int state = 0;
try {
server.deleteById(enterpriseId);
server.commit();
} catch (SolrServerException e) {
state = 1;
System.out.println("删除solr数据报错");
e.printStackTrace();
} catch (IOException e) {
state = 1;
System.out.println("删除solr数据报错");
e.printStackTrace();
}
return state;
}
solr工具类
package com.dinfo.boc.utils;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.LBHttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import com.dinfo.boc.enterprise.bean.EnterpriseContentBean;
import com.dinfo.boc.enterprisenew.bean.SolrQueryResult;
/
*** 与Solr服务器交互的工具类
* @author qiuyj
*
*/
public class SolrUtil {
/
*** 获取与指定Solr地址的连接
* @param solrUrl
* @return
*/
public static LBHttpSolrServer getSolrServer(String solrUrl){
final int ONE_HUNDRED_MS = ;
if(solrUrl == null || "".equals(solrUrl)){
throw new RuntimeException("Solr url can not be empty!");
}
LBHttpSolrServer solrServer = null;
try {
solrServer = new LBHttpSolrServer(solrUrl);
solrServer.setConnectionTimeout(ONE_HUNDRED_MS);
} catch (MalformedURLException e) {
e.printStackTrace();
} //SolrUtil.getSolrServer(solrUrl);
//solrServer.setDefaultMaxConnectionsPerHost();
//solrServer.setMaxTotalConnections();
return solrServer;
}
/
*** 向指定的Solr地址添加一条数据
* @param solrUrl
* @param doc
* @throws Exception
*/
public static void add(String solrUrl, SolrInputDocument doc) throws Exception {
if(doc == null){
throw new RuntimeException("SolrInputDocument object can not be null!");
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
solr.add(doc);
solr.commit();
}
/
*** 向指定的Solr地址用JavaBean添加一条数据
* @param solrUrl
* @param obj
* @throws Exception
*/
public static void add(String solrUrl, Object obj) throws Exception {
if(obj == null){
throw new RuntimeException("Object to be inserted can not be null!");
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
solr.addBean(obj);
solr.commit();
}
/
*** 向指定Solr地址批量添加数据
* @param solrUrl
* @param docs
* @throws Exception
*/
@SuppressWarnings("unchecked")
public static void addAll(String solrUrl, Collection<? extends Object> objs) throws Exception {
if(objs == null){
throw new RuntimeException("Object collection can not be null!");
}
if(objs.size() == 0){
return;
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
if(objs.iterator().next() instanceof SolrInputDocument){
solr.add((Collection<SolrInputDocument>)objs);
} else {
solr.addBeans(objs);
}
solr.commit();
}
/
*** 根据给定的id,从solr中删除对应信息
* @param solrUrl
* @param ids
*/
public static void deleteByIds(String solrUrl, String ... ids) throws Exception {
if(ids == null || ids.length == 0){
throw new RuntimeException("Ids can not be empty!");
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
solr.deleteById(Arrays.asList(ids));
solr.commit();
}
public static void deleteByIds(String solrUrl, Integer ... ids) throws Exception {
if(ids == null || ids.length == 0){
throw new RuntimeException("Ids can not be empty!");
}
List<String> stringIdList = new ArrayList<>(ids.length);
for(Integer id : ids){
stringIdList.add("" + id);
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
solr.deleteById(stringIdList);
solr.commit();
}
/
*** 删除指定Solr路径下符合指定查询条件的数据
* @param solrUrl
* @param condition
* @throws Exception
*/
public static void deleteByCondition(String solrUrl, String condition) throws Exception {
if(condition == null || "".equals(condition)){
throw new RuntimeException("Condition can not be empty!");
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
solr.deleteByQuery(condition);
solr.commit();
}
/
*** 删除指定Solr路径下的所有数据
* @param solrUrl
* @throws Exception
*/
public static void deleteAll(String solrUrl) throws Exception {
deleteByCondition(solrUrl, "*:*");
}
/
*** 根据 指定查询条件从Solr中查询数据,并以SolrDocument的List形式返回
* @param solrUrl
* @param query
* @return
* @throws Exception
*/
public static SolrDocumentList queryAndGetSolrDocumentList(String solrUrl, SolrQuery query) throws Exception {
if(query == null){
throw new RuntimeException("SolrQuery object can not be null!");
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
QueryResponse resp = solr.query(query);
return resp.getResults();
}
/
*** 根据 指定查询条件从Solr中查询数据,并以QueryResponse形式返回
* @param solrUrl
* @param query
* @return
* @throws Exception
*/
public static QueryResponse queryAndGetSolrQueryResponse(String solrUrl, SolrQuery query) throws Exception {
if(query == null){
throw new RuntimeException("SolrQuery object can not be null!");
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
QueryResponse resp = solr.query(query);
return resp;
}
/
*** 根据 指定查询条件从Solr中查询数据,并以Java Bean的List形式返回
* @param solrUrl
* @param query
* @param returnClass 返回的List集合的泛型
* @return
* @throws Exception
*/
public static <T> List<T> queryAndGetBeanList(String solrUrl, SolrQuery query, Class<T> returnClass) throws Exception {
if(query == null){
throw new RuntimeException("SolrQuery object can not be null!");
}
if(returnClass == null){
throw new RuntimeException("Return class can not be null!");
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
QueryResponse resp = solr.query(query);
return resp.getBeans(returnClass);
}
/
*** 根据 指定查询条件从Solr中查询数据,并以SolrQueryResult对象的形式返回,其中包含List对象和totalCount
* @param solrUrl
* @param query
* @param returnClass 返回的List集合的泛型
* @return
* @throws Exception
*/
public static <T> SolrQueryResult<T> queryAndGetSolrQueryResult(String solrUrl, SolrQuery query, Class<T> returnClass) throws Exception {
SolrQueryResult<T> result = new SolrQueryResult<T>();
if(query == null){
throw new RuntimeException("SolrQuery object can not be null!");
}
if(returnClass == null){
throw new RuntimeException("Return class can not be null!");
}
LBHttpSolrServer solr = getSolrServer(solrUrl);
solr.setConnectionTimeout();
QueryResponse resp = solr.query(query);
List<T> resultList = resp.getBeans(returnClass);
long totalCount = resp.getResults().getNumFound();
result.setResultList(resultList);
result.setTotalCount(totalCount);
return result;
}
/
*** 根据 指定查询条件从Solr中查询数据,并以SolrQueryResult对象的形式返回,其中包含List对象和totalCount
* @param solrUrl
* @param query
* @param returnClass 返回的List集合的泛型
* @return
* @throws Exception
*/
public static <T> SolrQueryResult<T> queryAndGetSolrQueryResult(LBHttpSolrServer solr, SolrQuery query, Class<T> returnClass) throws Exception {
SolrQueryResult<T> result = new SolrQueryResult<T>();
if(query == null){
throw new RuntimeException("SolrQuery object can not be null!");
}
if(returnClass == null){
throw new RuntimeException("Return class can not be null!");
}
QueryResponse resp = solr.query(query);
List<T> resultList = resp.getBeans(returnClass);
long totalCount = resp.getResults().getNumFound();
result.setResultList(resultList);
result.setTotalCount(totalCount);
return result;
}
/
*** 用以过滤一些影响Solr查询的特殊字符,如左右括号、星号等
* @param str
* @return
*/
public static String filterSpecialCharacters(String str){
if(str == null){
return str;
}
str = str.replace("(", "\\(");
str = str.replace(")", "\\)");
str = str.replace("*", "\\*");
return str;
}
public static void updateSolrById(LBHttpSolrServer server){
SolrQuery query = new SolrQuery();
String id="5daa5ccef0becdd8d";
int state=0;
String name="新疆金风科技股份有限公司";
query.set("q", "enterpriseId:"+id);
try {
QueryResponse qr = server.query(query);
List<EnterpriseContentBean> contentList = qr.getBeans(EnterpriseContentBean.class);
//设置需要保存的文章信息
for(EnterpriseContentBean bean:contentList){
// bean.setEnterpriseId(enterpriseId);
bean.setEnterpriseName(name);
bean.setResource("东方财富网港股频道");
}
server.addBeans(contentList);
server.commit();
} catch (SolrServerException e) {
state = 1;
e.printStackTrace();
} catch (IOException e) {
state = 1;
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
LBHttpSolrServerenterpriseServer=new LBHttpSolrServer("http://...:/solr/enterprisenew");
enterpriseServer.setConnectionTimeout();
updateSolrById(enterpriseServer);
System.out.println("over");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}