2. solr 6.6.0 内容上传及查询

本文详细介绍了solr 6.6.0中内容上传、图片特征提取、XML数据导入、MySQL数据导入、增添字段、删除数据及查询操作的步骤。包括在managed-schema中配置字段、利用lire进行图像特征提取、通过data-config.xml配置数据库导入、Java代码实现查询等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  接上文:https://blog.youkuaiyun.com/danjuanzi2684/article/details/83385831

 

1. solr文字内容上传:

        以core名为try为例,上传过程需要将上传的字段添加在配置文件try\\conf\\ managed-schema中,以上传old、WebpageURL、imgWebURL三个字段为例,基本配置如下:

<field name="old" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="WebpageURL" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="imgWebURL" type="string" indexed="true" stored="true" multiValued="false"/>

        如果该字段查询时可能用到分词,需要将type进行修改,solr中的text_ikk可以实现,首先找到配置文件中text_ikk类型的定义位置,将需要添加的字段进行添加,具体如下:

<fieldType name="text_ikk" class="solr.TextField">    
              <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>    
</fieldType>    
    
    <field name="summary"  type="text_ikk" indexed="true"  stored="true"  multiValued="false" />
    <field name="name" type="text_ikk" indexed="true" stored="true" multiValued="false"/>
    <field name="description" type="text_ikk" indexed="true" stored="true" multiValued="false"/>
    <field name="label" type="text_ikk" indexed="true" stored="true" multiValued="false"/>
    
    <field name="test"  type="text_ikk" indexed="true"  stored="true"  multiValued="false" />  

  基本上传代码如下:


public class upload {
	public static void main(String[] args) throws SolrServerException, IOException {
		HttpSolrClient server = new HttpSolrClient("http://localhost:8983/solr/try");
		// 创建Document对象
		SolrInputDocument doc = new SolrInputDocument();
		doc.addField("id", "c001");
		doc.addField("name", "xiao ming");
		doc.addField("age", "22");
		// 将Document对象添加到索引库
		server.add(doc);
		// 提交
		server.commit();
	}
}

    

2.solr 图片特征上传:

      solr中可以集成lire,实现图像特征的提取及检索,liresolr具体参考:https://bitbucket.org/dermotte/liresolr

      图片特征的上传,可直接利用solr自带的*_hi和*_ha,managed-schema中对应字段为以下三行,如果没有,自行添加:

<dynamicField name="*_ha" type="text_ws" indexed="true" stored="true"/> <!-- if you are using BitSampling --> 
<dynamicField name="*_hi" type="binaryDV" indexed="true" stored="true"/>
<fieldtype name="binaryDV" class="net.semanticmetadata.lire.solr.BinaryDocValuesField"/>

       如果中文分词或者添加_hi时出现错误:Error loading class 's 'net.semanticmetadata.lire.solr.BinaryDocValuValuesField',将lire.jar、liresolr.jar、IKAnalyzer2012FF_u1.jar、ik-analyzer-solr5-5.x.jar,四个jar包拷贝到solr-6.6.0\server\solr-webapp\webapp\WEB-INF\lib文件夹

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值