002--Solr分析查询

002--Solr分析查询

1.工具选取

2.使用版本

  • Tomcat 7 version
  • Solr 4.10.3 version

3.核心思路

  • 数据库是否连接,怎么建立连接?
  • 数据怎么存放,对应key值是什么?
  • 如果进行检索,分词依据是什么?
  • 取出数据是什么,如何确定数据格式?

3.核心代码

//1.连接数据库
String baseUrl="http://localhost:8055/solr/article";
HttpSolrServer httpSolrServer=new HttpSolrServer(baseUrl);

//2.建立SolrInputDocument对象
SolrInputDocument solrInputDocument=new SolrInputDocument();
solrInputDocument.addField("id", 1);
solrInputDocument.addField("name","苹果7");
solrInputDocument.addField("price","5000");
   
//3.建立索引
httpSolrServer.add(solrInputDocument);

//4.提交
httpSolrServer.commit();

4.排错顺序

    1. 字段名称和solr服务器中存储的字段名称不对应!
    1. 如例子中的http://localhost:8055/solr/article是否能正常在地址栏打开,注意:这个url中不能出现井号!
    1. 如还出现以上问题,建议仔细查看日志说明或者控制台错误提示,这个步骤推荐最先执行。

5.windows和Linux

为了验证,我将window下的solr直接上传到Linux上,更改相应路径,然后运行,Bingo!