zoukankan      html  css  js  c++  java
  • Solr简单使用

    1.添加索引

    		// 第一步:把solrJ的jar包添加到工程中。
    		// 第二步:创建一个SolrServer,使用HttpSolrServer创建对象。
    		SolrServer solrServer = new HttpSolrServer("http://192.168.25.154:8080/solr");
    		// 第三步:创建一个文档对象SolrInputDocument对象。
    		SolrInputDocument document = new SolrInputDocument();
    		// 第四步:向文档中添加域。必须有id域,域的名称必须在schema.xml中定义。
    		document.addField("id", "test001");
    		document.addField("item_title", "测试商品");
    		document.addField("item_price", "199");
    		// 第五步:把文档添加到索引库中。
    		solrServer.add(document);
    		// 第六步:提交。
    		solrServer.commit();
    

    2.删除

    		// 第一步:创建一个SolrServer对象。
    		SolrServer solrServer = new HttpSolrServer("http://192.168.25.154:8080/solr");
    		// 第二步:调用SolrServer对象的根据id删除的方法。
    		solrServer.deleteById("1");
    		// 第三步:提交。
    		solrServer.commit();

                      SolrServer solrServer = new HttpSolrServer("http://192.168.25.154:8080/solr");

                      solrServer.deleteByQuery("title:change.me");

                      solrServer.commit();


    3.查询

    		SolrServer solrServer = new HttpSolrServer("http://192.168.25.154:8080/solr");
    		// 第二步:创建一个SolrQuery对象。
    		SolrQuery query = new SolrQuery();
    		// 第三步:向SolrQuery中添加查询条件、过滤条件。。。
    		query.setQuery("*:*");
    		// 第四步:执行查询。得到一个Response对象。
    		QueryResponse response = solrServer.query(query);
    		// 第五步:取查询结果。
    		SolrDocumentList solrDocumentList = response.getResults();
    		System.out.println("查询结果的总记录数:" + solrDocumentList.getNumFound());
    		// 第六步:遍历结果并打印。
    		for (SolrDocument solrDocument : solrDocumentList) {
    			System.out.println(solrDocument.get("id"));
    			System.out.println(solrDocument.get("item_title"));
    			System.out.println(solrDocument.get("item_price"));
    		}
    

      

  • 相关阅读:
    在C++中使用GDI+绘制带箭头的线,箭头大小可调
    tomcat通过conf-Catalina-localhost目录发布项目详解
    VC++ 获取Windows系统标准字体方法
    简单实现全屏对话框
    采用ATL实现无模板对话框的显示
    C++实现全局鼠标、键盘消息hook,支持事件
    C++ FastDelegate 扩展,实现与.net类似的事件处理功能
    技术研发在国内的现状
    [STM32F103]DMA原理
    [STM32F103]RTC日历
  • 原文地址:https://www.cnblogs.com/zhoucx66/p/9299264.html
Copyright © 2011-2022 走看看