002--Solr分析查询

2017-12-14  本文已影响11人  糖纸疯了

1.工具选取

2.使用版本

3.核心思路

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!

上一篇 下一篇

猜你喜欢

热点阅读