• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > solr实战-(一),solr实战

solr实战-(一),solr实战

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含solr实战,solr实战视频教程,solr实战 pdf,怎么建立solr服务,solr等服务器相关知识,网友希望可以进行参考

solr实战-(一),solr实战


实现用户数据索引及查询
1. 启动solr       solr start
2. 创建collection       solr create -c user
3. schema中添加field      3.1 solr-5.2.1/server/solr/user/conf/managed-schema中添加
                <!--定义IK分词类型-->
               <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>

               <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
               <field name="username" type="text_ik" indexed="true" stored="true" multiValued="true"/>
               <field name="age" type="text_ik" indexed="true" stored="true"/>
               <field name="keywords" type="text_ik" indexed="true" stored="true"/>


    3.2 添加IK分词库             filed定义中使用了IKAnalyzer,需要进入相关配置引用分词器              a. solr-5.2.1/contrib/analysis-extras/lib中添加IKAnalyzer3.2.8.jar  下载地址: http://download.csdn.net/detail/buyaore_wo/8946777              b. solrconfig.xml (/solr-5.2.1/server/solr/user/conf)中添加库引用配置,如下                     
<lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lib" regex=".*\.jar" />

      4.使用SolrJ添加索引数据       
	/**
	 * 添加文档
	 */
	@Test
	public void addDoc() {
		SolrInputDocument doc = new SolrInputDocument();
		doc.addField("id", "12");
		doc.addField("username", "哈哈");
		doc.addField("keywords", "哈哈 你好");
		doc.addField("age", "18");

		UpdateResponse response;
		try {
			response = httpSolrClient.add(/*"user",*/ doc);
			// 提交
			httpSolrClient.commit();

			// logger.info("########## Query Time :" + response.getQTime());

			System.out.println("########## Query Time :" + response.getQTime());
			// logger.info("########## Elapsed Time :" +
			// response.getElapsedTime());
			System.out.println("########## Elapsed Time :"
					+ response.getElapsedTime());
			// logger.info("########## Status :" + response.getStatus());
			System.out.println("########## Status :" + response.getStatus());
		} catch (SolrServerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

 5.查询数据    
	@Test
	public void testQuery() {
		SolrQuery solrQuery = new SolrQuery("keywords:*好");
		// solrQuery.setFilterQueries("resourcename:*analytics*");
		// SolrQuery solrQuery = new SolrQuery("*:*");
		// solrQuery.setFields("id", "title");
		solrQuery.setStart(0).setRows(5);
		try {
			QueryResponse queryResponse = httpSolrClient.query(/*"user",*/
					solrQuery);
			// logger.info("results:" +
			// queryResponse.getResults().getNumFound());
			System.out.println("results:"
					+ queryResponse.getResults().getNumFound());
			SolrDocumentList solrDocumentList = queryResponse.getResults();
			for (SolrDocument solrDocument : solrDocumentList) {

				Collection<String> fieldNames = solrDocument.getFieldNames();
				// logger.info("==========================================");
				System.out
						.println("==========================================");
				for (String field : fieldNames) {
					// logger.info(field + ":" +
					// solrDocument.getFieldValue(field));
					System.out.println(field + ":"
							+ solrDocument.getFieldValue(field));
				}
			}
		} catch (SolrServerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


中途可能遇到以下这样的异常 org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://192.168.0.12:8983/solr: Expected mime type application/xml but got text/html. <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/update. Reason:
<pre>    Not Found</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>
</body>
</html>

原因是没有指定 collection_name

版权声明:本文为博主原创文章,未经博主允许不得转载。

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • solr实战-(一),solr实战

相关文章

  • flume 组件概述与列表
  • hadoop学习---2.cygwin及sshd安装配置,---2.cygwinsshd
  • Openstack Nova(九)----Instance 创建(Computer API &amp; Conductor ),openstacknovaapi
  • 浅谈大数据,浅谈数据
  • hdfs一致性模型,hdfs一致性
  • 《4》CentOS7.0+OpenStack+kvm云平台部署—配置Nova,《4》kvm
  • 几本京东上的CISCO云计算相关书籍,cisco相关书籍
  • JOIN操作,数据库join操作
  • 通过iscsi协议使用ceph rbd,iscsi协议cephrbd
  • 实战第一个云程序,实战第一个云

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • HIVE动态分区实战,hive动态实战
    • mysql数据导入hbase
    • 《转》Ubuntu14.04 openstack juno配置之 ceilometer遥测模块安装配置,《转》ubuntu14.04
    • Hadoop学习---第三篇Hadoop的第一个Mapreduce程序,hadoopmapreduce
    • 你真的了解OpenStack吗?学过的人,都知道!,了解openstack
    • Linux配置时间服务器,linux配置服务器
    • 安装openstack 时 遇见的一些问题及解决方法!,openstack一些问题
    • Spark MLlib Deep Learning Convolution Neural Network (深度学习-卷积神经网络)3.3,mllibconvolution
    • 详说大数据计算的可类化Classable,类化classable
    • Ambari管理Hadoop集群时遇到的问题,ambarihadoop

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有