solr

solr的使用

打开

进入solr-7.7.2\bin文件夹,进入cmd控制台,输入solr start

默认端口号是8983,注意窗口不要关闭[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lbDyc5Ya-1576120772037)(F:\课上截图\cmd.png)]

浏览器输入 http://localhost:8983/solr可以访问solr后台管理

点击选项中的new_core创建一个实例,

(注意:)如果创建失败把solr-7.7.2\server\solr\configsets_default下的面conf文件夹复制到new_core实例中

** 导入驱动**
在实例中创建lib文件夹存入jar包
在这里插入图片描述
放好后刷新core,在core admin选择reload刷新

在实例下conf文件下添加 solrconfig.xml 文件


<requestHandler name="/dataimport" 
   class="org.apache.solr.handler.dataimport.DataImportHandler">
	<lst name="defaults">
		<str name="config">data-config.xml</str>
	</lst>
  </requestHandler>

创建data-config.xml文件

在conf文件夹下创建data-config.xml,配置对应的数据库以及对应的索引数据

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource"
			driver="com.mysql.jdbc.Driver"
			url="jdbc:mysql://localhost:3306/itripdb"
			user="root"
			password="root"/>
	<document>
		<entity name="product" query="SELECT * FROM itrip_user"
		deltaQuery="select id from itrip_user where updateTime >'${dih.last_index_time}'"
deltaImportQuery="select id,userCode,userPassword,userType,flatID,userName,weChat,QQ,weibo,baidu,creationDate,createdBy,modifyDate,modifiedBy,activated from itrip_user where id ='${dih.delta.id}'">
			<field column="id" name="id" />
			<field column="userCode" name="userCode" />
			<field column="userPassword" name="userPassword" />
			<field column="userType" name="userType" />
			<field column="flatID" name="flatID" />
			<field column="userName" name="userName" />
			<field column="weChat" name="weChat" />
			<field column="QQ" name="QQ" />
			<field column="weibo" name="weibo" />
			<field column="baidu" name="baidu" />
			<field column="creationDate" name="creationDate" />
			<field column="createdBy" name="createdBy" />
			<field column="modifyDate" name="modifyDate" />
			<field column="modifiedBy" name="modifiedBy" />
			<field column="activated" name="activated" />
		</entity>
	</document>
</dataConfig>

在managed-schema文件添加

<field name="userCode" type="text_ik" indexed="true" stored="true"/>
<field name="userPassword" type="string" indexed="false" stored="false"/>
<field name="userType" type="pint" indexed="false" stored="false"/>
<field name="flatID" type="pint" indexed="false" stored="false"/>
<field name="userName" type="text_ik" indexed="true" stored="true"/>
<field name="weChat" type="string" indexed="false" stored="false"/>
<field name="QQ" type="string" indexed="false" stored="false"/>
<field name="weibo" type="string" indexed="false" stored="false"/>
<field name="baidu" type="string" indexed="false" stored="false"/>
<field name="creationDate" type="pdate" indexed="false" stored="false"/>
<field name="createdBy" type="pint" indexed="false" stored="false"/>
<field name="modifyDate" type="pdate" indexed="false" stored="false"/>
<field name="modifiedBy" type="pint" indexed="false" stored="false"/>
<field name="activated" type="pint" indexed="false" stored="false"/>

导入
导入刷新

** 增量更新**

1、修改数据库

数据库增加时间字段updateTime,数据类型改为timestamp

数据库更改记录更新时间

alter table `itrip_user` modify updateTime timestamp default current_timestamp on update current_timestamp;

2、添加jar包

在solr-7.7.2\server\solr-webapp\webapp\WEB-INF\lib目录下添加solr-dataimport-scheduler.jar

3、添加配置文件,在solr-7.7.2\server\solr文件下创建conf文件夹,在文件夹中创建dataimport.properties文件输入

#  to sync or not to sync  
#  1 - active; anything else - inactive  
syncEnabled=1
#  which cores to schedule  
#  in a multi-core environment you can decide which cores you want syncronized  
#  leave empty or comment it out if using single-core deployment  
syncCores=实例名称
#  solr server name or IP address  
#  [defaults to localhost if empty]  
server=IP地址
#  solr server port  
#  [defaults to 80 if empty]  
port=端口号
#  application name/context  
#  [defaults to current ServletContextListener's context (app) name]  
webapp=solr
#  增量索引的参数   
#  URL params [mandatory]  
#  remainder of URL  
params=/dataimport?command=delta-import&clean=true&commit=true
#  重做增量索引的时间间隔  
#  schedule interval  
#  number of minutes between two runs  
#  [defaults to 30 if empty]  
interval=1
#  重做全量索引的时间间隔,单位分钟,默认7200,即5天;  
#  为空,为0,或者注释掉:表示永不重做索引  
#reBuildIndexInterval=7200
#  重做索引的参数  
reBuildIndexParams=/dataimport?command=full-import&clean=true&commit=true
#  重做索引时间间隔的计时开始时间,第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;  
#  两种格式:2012-04-11 03:10:00 或者  03:10:00,后一种会自动补全日期部分为服务启动时的日期  
reBuildIndexBeginTime=03:10:00

4、配置web.xml

在solr-7.7.2\server\solr-webapp\webapp\WEB-INF目录下的web.xml中添加

<listener>  
		<listener-class>org.apache.solr.handler.dataimport.scheduler.ApplicationListener</listener-class>  
   </listener>  

5、修改实例中的data-config.xml

在文件夹solr-7.7.2\server\solr\new_core\conf中的data-config.xml中的entity标签中添加操作

deltaQuery="select id from itrip_user where updateTime >'${dih.last_index_time}'"
deltaImportQuery="select	id,userCode,userPassword,userType,flatID,userName,weChat,QQ,weibo,baidu,creationDate,createdBy,modifyDate,modifiedBy,activated from itrip_user where id ='${dih.delta.id}'"

查询
在这里插入图片描述

中文分词

1、存放jar包

把ik-analyzer-solr7-7.x.jar存入solr-7.7.2\server\solr-webapp\webapp\WEB-INF\lib文件夹

2、存放配置文件

在solr-7.7.2\server\solr-webapp\webapp\WEB-INF\文件夹下创建classes文件夹

在原本的文件夹中复制三个配置文件到该文件夹下

ext_stopword.dic 分词文件

IKAnalyzer.cfg.xml IK配置文件

mydict.dic 字典文件

3、配置Solr实例

在solr实例中配置

<field name="name" type="text_ik" indexed="true" stored="true"/>

<fieldType name="text_ik" class="solr.TextField">
		<analyzer type="index" isMaxWordLength="false" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
		<analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
	</fieldType>

Java中solrj用法

1、引入jar包

<dependency>
	<groupId>org.apache.solr</groupId>
	<artifactId>solr-solrj</artifactId>
	<version>7.4.0</version>
</dependency>

2、编写代码

@Test
public void search() throws IOException, SolrServerException {
    String solrUrl = "http://localhost:8983/solr/new_core";
    HttpSolrClient solrClient = new HttpSolrClient.Builder(solrUrl).build();
    SolrQuery query = new SolrQuery();

    query.set("q","*:*");
    query.setSort("id", SolrQuery.ORDER.desc);
    query.setFields("name");

    QueryResponse response = solrClient.query(query);

    SolrDocumentList docs = response.getResults();
    long cnt = docs.getNumFound();
    System.out.println("总条数为"+cnt+"条");
    for (SolrDocument doc : docs) {
        System.out.println("id:"+ doc.get("u_id") + ",name:"+ doc.get("name"));
    }
    solrClient.close();
}


;
    long cnt = docs.getNumFound();
    System.out.println("总条数为"+cnt+"条");
    for (SolrDocument doc : docs) {
        System.out.println("id:"+ doc.get("u_id") + ",name:"+ doc.get("name"));
    }
    solrClient.close();
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像中目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分类问题:判断图像中的目标属于哪个类别。 定位问题:确定目标在图像中的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值